Hey Marc,
Thanks for the feedback.
As for an example:
example.proto:
syntax = "proto3";
package pb;
message Color {
int32 R = 1;
int32 G = 2;
int32 B = 3;
}
message Dog {
int32 dogProperty = 1;
}
message Cat {
int32 catProperty = 1;
}
message Animal {
// trivial data
bool canSwim = 1;
// complex data (composition)
Color skinColor = 2;
enum AnimalType {
animalTypeDog = 0;
animalTypeCat = 1;
}
AnimalType animalType = 3;
// complex data (inheritance)
Dog dog = 4;
Cat cat = 5;
}
This generates an implementation (or in my case also my half-working interface generation) like this:
In IExample.g.cs
public partial interface IAnimal
{
/// <summary>
/// trivial data
/// </summary>
bool CanSwim { get; set; }
/// <summary>
/// complex data (composition)
/// </summary>
IColor SkinColor { get; set; }
Animal.Types.AnimalType AnimalType { get; set; }
/// <summary>
/// complex data (inheritance)
/// </summary>
IDog Dog { get; set; }
ICat Cat { get; set; }
}
public partial interface IDog
{
int DogProperty { get; set; }
}
etc
In Example.g.cs
internal partial class Animal : pb::IMessage<Animal>, IAnimal
{
..stuff
}
Now obviously the generation of the interface is far from done, but as far as the generator is concerned, IDog and IColor are both composites because there is no way to distinguish between the two.
I will have to find a good way to specify this difference so the parser can catch it.
This would then (maybe) also allow for the generator to create:
public partial interface IDog : IAnimal
{
int DogProperty { get; set; }
}
This would require 2 properties. One above a message to say whether it derives off other message ( to add f/e let IDog inherit from IAnimal).
And another to mark a message member (f/e Dog dog = 4;) as being derived from.. as all messages are handled individually.
A secondary problem comes from the boiler plate code including the above in writing and reading mechanics.
In my case, I create external objects with an internal object reference as constructor parameter, ie I would have in Animal.cs (manual implementation stuff)
internal partial class Animal
{
internal Animal(InternalObjectType internalObject)
{
// do stuff with internalObject
}
bool CanSwim
{
get { return internalObject.TerribleInternalFuncionToGetSwimInfo(); }
set { internalObject.SomeArcaneWizardryToSetSwimming(value); }
}
IColor SkinColor
{
get { var color = new Color {R = internalObject.Redish, B = ... etc}; return color; }
set { internalObject.Redish = value.R; ...etc
}
}
Now the generation as-is does provide a partial method OnConstruction, which I could implement and use to do the usual work post-construction, but it makes nested properties a PITA :)