Ejemplo n.º 1
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);
        }
Ejemplo n.º 2
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());
        }