Пример #1
0
        private static IEnumerable <IScriptField> CreateFields(MonoManager manager, TypeDefinition type, IReadOnlyDictionary <GenericParameter, TypeReference> arguments)
        {
            List <IScriptField> fields = new List <IScriptField>();

            foreach (FieldDefinition field in type.Fields)
            {
                if (!MonoField.IsSerializable(field, arguments))
                {
                    continue;
                }

                MonoField monoField = new MonoField(manager, field, arguments);
                fields.Add(monoField);
            }
            return(fields);
        }
Пример #2
0
        internal MonoType(MonoManager manager, TypeReference type, IReadOnlyDictionary <GenericParameter, TypeReference> arguments) :
            base(type.Namespace, ToPrimitiveType(type), type.Name, GetBaseType(manager, type, arguments))
        {
            if (type.IsGenericParameter)
            {
                throw new ArgumentException(nameof(type));
            }
            if (MonoField.IsSerializableArray(type))
            {
                throw new ArgumentException(nameof(type));
            }

            string uniqueName = GetUniqueName(type);

            manager.AssemblyManager.AddSerializableType(uniqueName, this);
            Fields = CreateFields(manager, type, arguments);
        }
Пример #3
0
        private static Field[] CreateFields(MonoManager manager, TypeReference type, IReadOnlyDictionary <GenericParameter, TypeReference> arguments)
        {
            TypeDefinition definition = type.Resolve();
            List <Field>   fields     = new List <Field>();

            foreach (FieldDefinition field in definition.Fields)
            {
                if (MonoField.IsSerializable(field, arguments))
                {
                    TypeReference    fieldType  = GetSerializedElementType(field.FieldType, arguments);
                    SerializableType scriptType = manager.GetSerializableType(fieldType, arguments);
                    bool             isArray    = IsSerializableArray(field.FieldType, arguments);
                    Field            fieldStruc = new Field(scriptType, isArray, field.Name);
                    fields.Add(fieldStruc);
                }
            }
            return(fields.ToArray());
        }
Пример #4
0
        internal MonoType(MonoManager manager, MonoTypeContext context) :
            base(context.Type.Namespace, ToPrimitiveType(context.Type), MonoUtils.GetName(context.Type))
        {
            if (context.Type.ContainsGenericParameter)
            {
                throw new ArgumentException(nameof(context));
            }
            if (MonoField.IsSerializableArray(context.Type))
            {
                throw new ArgumentException(nameof(context));
            }

            string uniqueName = GetUniqueName(context.Type);

            manager.AssemblyManager.AddSerializableType(uniqueName, this);
            Base   = GetBaseType(manager, context);
            Fields = CreateFields(manager, context);
        }
Пример #5
0
        private static Field[] CreateFields(MonoManager manager, MonoTypeContext context)
        {
            List <Field>   fields     = new List <Field>();
            TypeDefinition definition = context.Type.Resolve();
            IReadOnlyDictionary <GenericParameter, TypeReference> arguments = context.GetContextArguments();

            foreach (FieldDefinition field in definition.Fields)
            {
                if (MonoField.IsSerializable(field, arguments))
                {
                    MonoTypeContext  fieldContext    = new MonoTypeContext(field.FieldType, arguments);
                    MonoTypeContext  resolvedContext = fieldContext.Resolve();
                    MonoTypeContext  serFieldContext = GetSerializedElementContext(resolvedContext);
                    SerializableType scriptType      = manager.GetSerializableType(serFieldContext);
                    bool             isArray         = MonoField.IsSerializableArray(resolvedContext.Type);
                    Field            fieldStruc      = new Field(scriptType, isArray, field.Name);
                    fields.Add(fieldStruc);
                }
            }
            return(fields.ToArray());
        }
Пример #6
0
 private MonoField(MonoField copy) :
     base(copy)
 {
 }
Пример #7
0
        private static bool IsSerializableArray(TypeReference type, IReadOnlyDictionary <GenericParameter, TypeReference> arguments)
        {
            TypeReference resolvedType = type.ContainsGenericParameter ? MonoUtils.ResolveGenericParameter(type, arguments) : type;

            return(MonoField.IsSerializableArray(resolvedType));
        }