GuardianX
GuardianX

Reputation: 512

Adding attributes to the fields of RuntimeTypeModel types

I'm constructing non-default RuntimeTypeModel for third-party library classes. However, I require some of the fields to be marked as references, just as you can do that with [ProtoMember(N), AsReference=true]. How can I apply those attributes to the fields of the types defined in my non-default RuntimeTypeModel?

UPDATE

I managed to access fields via MetaType.GetFields() and setting AsReference flag on each field individually, however I don't know if this is the right way to do what I want or maybe there is more straightforward way to do this (which should exist, imo).

Upvotes: 1

Views: 157

Answers (1)

Marc Gravell
Marc Gravell

Reputation: 1062975

As your edit notes, these options are available via MetaType, for example:

var metaType = model.Add(type, false);
model.AddField(1, "Foo").AsReference = true; // AddField returns the ValueMember;
                    // contrast to Add which returns the MetaType for fluent usage

There is also:

metaType.AsReferenceDefault

which indicates (per-type) whether a type should automatically be considered as a reference.

Upvotes: 1

Related Questions