hoangduit / protobuf-net

Automatically exported from code.google.com/p/protobuf-net
Other
0 stars 0 forks source link

Method to detect built-in types #443

Open GoogleCodeExporter opened 9 years ago

GoogleCodeExporter commented 9 years ago
Hello,

We are dynamically creating a model and we would like to know which types are 
"built-in" (like "int" or "datetime") without hard-coding this list.
If you try to create a MetaType from a build-in type, it fails with an 
exception "Data of this type has inbuilt behaviour, and cannot be added to a 
model in this way".

For now, I have added this method to the RunTypeModel class:

public bool IsBuiltIn(Type type)
{
    WireType defaultWireType;
    MetaType.AttributeFamily family = MetaType.GetContractFamily(this, type, null);
    IProtoSerializer ser = family == MetaType.AttributeFamily.None
        ? ValueMember.TryGetCoreSerializer(this, DataFormat.Default, type, out defaultWireType, false, false, false, false)
        : null;

    return ser != null;
}

Is there a better method to detect this ?
If not, could you please add such method in the next release?

Thank you

Alessandro De Simone

Original issue reported on code.google.com by aless...@gmail.com on 20 May 2014 at 8:25