Akka.Interfaced.ProtobufSerializer.AutoSurrogate.Register C# (CSharp) Метод

Register() публичный статический Метод

public static Register ( ProtoBuf.Meta.RuntimeTypeModel typeModel, Assembly assembly ) : void
typeModel ProtoBuf.Meta.RuntimeTypeModel
assembly System.Reflection.Assembly
Результат void
        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)
                        {
                        }
                    }
                }
            }
        }

Same methods

AutoSurrogate::Register ( ProtoBuf.Meta.RuntimeTypeModel typeModel ) : void

Usage Example

        public static TypeModel CreateTypeModel()
        {
            RuntimeTypeModel typeModel = TypeModel.Create();

            AkkaSurrogate.Register(typeModel);
            AutoSurrogate.Register(typeModel);
            return(typeModel);
        }