示例#1
0
 static void ForceSerialization(TypeConfig typeConfig)
 {
     typeConfig.TypeConstruction      = TypeConstruction.ByUninitialized();
     typeConfig.ReadonlyFieldOverride = ReadonlyFieldHandling.ForcedOverwrite;
     typeConfig.TargetMembers         = TargetMember.PrivateFields;
     typeConfig.CustomResolver        = ForceDynamicResolver;
 }
示例#2
0
        // Built-in support for some specific types
        internal static void ApplySpecializedDefaults(TypeConfig typeConfig)
        {
            var type = typeConfig.Type;

            // All structs
            if (!type.IsPrimitive && type.IsValueType)
            {
                if (typeConfig.TypeConstruction == null)
                {
                    typeConfig.TypeConstruction = ConstructNull.Instance;
                }

                typeConfig.TargetMembers = TargetMember.AllFields;
                return;
            }

            if (type.Assembly == typeof(Expression).Assembly)
            {
                if (!type.IsAbstract && type.IsSubclassOf(typeof(Expression)))
                {
                    typeConfig.TypeConstruction      = TypeConstruction.ByUninitialized();
                    typeConfig.ReadonlyFieldOverride = ReadonlyFieldHandling.ForcedOverwrite;
                    typeConfig.TargetMembers         = TargetMember.AllFields;
                    typeConfig.CustomResolver        = ForceDynamicResolver;
                    return;
                }

                if (type.FullName.StartsWith("System.Runtime.CompilerServices.TrueReadOnlyCollection"))
                {
                    typeConfig.TypeConstruction      = TypeConstruction.ByUninitialized();
                    typeConfig.ReadonlyFieldOverride = ReadonlyFieldHandling.ForcedOverwrite;
                    typeConfig.TargetMembers         = TargetMember.PrivateFields;
                    typeConfig.CustomResolver        = ForceDynamicResolver;
                    return;
                }
            }

            if (type.Assembly == typeof(ReadOnlyCollection <>).Assembly)
            {
                if (type.FullName.StartsWith("System.Collections.ObjectModel.ReadOnlyCollection"))
                {
                    typeConfig.TypeConstruction      = TypeConstruction.ByUninitialized();
                    typeConfig.ReadonlyFieldOverride = ReadonlyFieldHandling.ForcedOverwrite;
                    typeConfig.TargetMembers         = TargetMember.PrivateFields;
                    typeConfig.CustomResolver        = ForceDynamicResolver;
                    return;
                }
            }
        }