1

is it possible to access an exist serialization model from defined model and then append a Contracted but unknown subtype to it, subsequently use it for serialization ?

or do i need to explicitly create a new model ? i.e. in this case for ModuleTwoFoo


Update

var model = TypeModel.Create();
model[typeof(IFooChild)].AddSubType(2, typeof(ModuleTwoFooChild));
model.CompileInPlace();

RuntimeModel.Default[] // model[] is the access ... Doh !

my only complain if at all ... wish there was a way to access the original model then build on it rather than having regenerate the model again

As stated by marc "essentially what is required is cloned but unfrozen model"


public interface IFoo
{
    int FooNumber { get; set; }
    IList<IFooChild> Children { get; set; }
}

[ProtoContract, ProtoInclude(1, typeof(ModuleOneFooChild))]
public interface IFooChild
{
    IFoo Foo { get; set; }
    string Detail { get; set; }
}

[ProtoContract]
public class ModuleOneFoo : IFoo
{
    [ProtoMember(1)]
    public int FooNumber { get; set; }

    [ProtoMember(2)]
    public IList<IFooChild> Children { get; set; }    
}

[ProtoContract]
public class ModuleOneFooChild : IFooChild
{
    public IFoo Foo { get; set; }

    [ProtoMember(1)]
    public string Detail { get; set; }    
}

[ProtoContract]
public class ModuleTwoFoo : IFoo
{
    [ProtoMember(1)]
    public int FooNumber { get; set; }

    [ProtoMember(2)]
    public IList<IFooChild> Children { get; set; }    
}

[ProtoContract]
public class ModuleTwoFooChild : IFooChild
{
    public IFoo Foo { get; set; }

    [ProtoMember(1)]
    public string Detail { get; set; }    
}
kalki
  • 516
  • 2
  • 10

1 Answers1

1

I assume you want to make changes to a model after the serializer has been generated, which would nclude adding sub-types. That isn't currently supported - at the current time you would need to recreate the type-model. It is expected that you will know what you want to work with before you start working with it!

However, I can see value in one of two feature-requests:

  1. To unfreeze a MetaType (blowing away any generated serializers/strategies)
  2. To clone a MetaType or RuntimeTypeModel, but as not-frozen
Marc Gravell
  • 1,026,079
  • 266
  • 2,566
  • 2,900
  • Yes i got the part w.r.t serializer having to be immutable once generated. But option 2 was what i was hoping for, was initially unsure as how to formulate the question. "cloned but not frozen" would be perfect. – kalki Jul 23 '12 at 05:14