Title: protobuf-net - list supported types
Tags: c#;protobuf-net
Question: I'm working on a custom ProtoBufFormatter (: MediaTypeFormatter) that is capable of registering own types on the fly to the RuntimeTypeModel used to serialize/deserialze. 

To reduce the need of try{}catch{} blocks it would be great to filter out already supported types before adding them to the RuntimeTypeModel. The readme only offers a "vague" list types that are supported by default and the method Model.GetTypes() only returns a list of types that are manually added to the current model.

Readme: https://github.com/mgravell/protobuf-net

I'm using protobuf-net 2.4.0

So I'm wondering if there is any easy way to check if a type is already supported by the current RuntimeTypeModel?
Currently I'm using something like this to prefilter types:

```    private bool IsSimpleType(Type type)
    {
        return
            type.IsPrimitive ||
            _additionalSimpleTypes.Contains(type) ||
            Convert.GetTypeCode(type) != TypeCode.Object ||
            (type.IsGenericType &amp;&amp; type.GetGenericTypeDefinition() == typeof(Nullable<&gt;) &amp;&amp; IsSimpleType(type.GetGenericArguments()[0]));
    }

    private Type[] _additionalSimpleTypes = new Type[]
    {
                typeof(Enum),
                typeof(String),
                typeof(String[]),
                typeof(Decimal),
                typeof(DateTime),
                typeof(DateTimeOffset),
                typeof(TimeSpan),
                typeof(Guid),
                typeof(Uri),
                typeof(Byte),
                typeof(Byte[]),
                typeof(Char),
                typeof(Boolean),
                typeof(Object),
                typeof(Version)
    };

    private Type[] _listTypes = new Type[]
    {
        typeof(Enum),
                typeof(IEnumerable<&gt;),
                typeof(List<&gt;),
                typeof(IList<&gt;)
    };
```

Comment: That would be great. Any other idea how to test if a type is already supported without try'n'error?

Comment: I don't think such a method exists today; we could add one, of course...

Here is the accepted answer: Try:

``` ProtoBuf.Meta.RuntimeTypeModel.Default.CanSerialize(Type type)
```



{'source': 'StackExchangeDataset', 'subset': 'stackoverflow.com', 'metadata': {'AnswerCount': 1, 'CommentCount': 2, 'ContentLicense': 'CC BY-SA 4.0', 'CreationDate': '2019:00:01/14/19', 'FavoriteCount': None, 'PostTypeId': 1, 'Tags': '<c#><protobuf-net>', 'Title': 'protobuf-net - list supported types', 'ViewCount': 413, 'id': 54177121, 'user_AboutMe': '<p>"If at first, the idea is not absurd, then there is no hope for it." <em>- Albert Einstein</em></p>\n', 'user_AccountId': 6508801.0, 'user_DisplayName': 'M. Altmann', 'user_Reputation': 716.0, 'user_Views': 38.0, 'user_id': 5036838.0}}