public static void Register(RuntimeTypeModel typeModel, Assembly assembly)
{
foreach (var type in GetTypesSafely(assembly))
{
if (type.IsClass == false && type.IsValueType == false)
continue;
if (Attribute.GetCustomAttribute(type, typeof(ProtoBuf.ProtoContractAttribute)) == null)
continue;
var loweredTypeName = type.Name.ToLower();
if (loweredTypeName.Contains("surrogatedirectives"))
{
foreach (var field in type.GetFields())
{
var sourceType = FindSurrogateSourceType(field.FieldType);
if (sourceType != null)
{
if (typeModel.CanSerialize(sourceType))
continue;
try
{
typeModel.Add(sourceType, false).SetSurrogate(field.FieldType);
}
catch (InvalidOperationException)
{
}
}
}
}
else if (type.Name.ToLower().Contains("surrogate"))
{
var sourceType = FindSurrogateSourceType(type);
if (sourceType != null)
{
if (typeModel.CanSerialize(sourceType))
continue;
try
{
typeModel.Add(sourceType, false).SetSurrogate(type);
}
catch (InvalidOperationException)
{
}
}
}
}
}