LookupStructDefinition() private méthode

private LookupStructDefinition ( Type type ) : StructDefinition
type System.Type
Résultat StructDefinition
Exemple #1
0
 internal void CheckMixedMarshalling(object o, Type type, UInt32 count)
 {
     if (type.IsClass)
     {
         var defn = GR2.LookupStructDefinition(type, o);
         if (defn.MixedMarshal)
         {
             AddMixedMarshalling(o, count, defn);
         }
     }
 }
Exemple #2
0
        private void LoadAttributes(FieldInfo info, GR2Writer writer)
        {
            var attrs = info.GetCustomAttributes(typeof(SerializationAttribute), true);

            if (attrs.Length > 0)
            {
                SerializationAttribute serialization = attrs[0] as SerializationAttribute;

                if (serialization.Section != SectionType.Invalid)
                {
                    PreferredSection = serialization.Section;
                }

                DataArea = serialization.DataArea;

                if (serialization.Type != MemberType.Invalid)
                {
                    Type = serialization.Type;
                }

                if (serialization.TypeSelector != null)
                {
                    TypeSelector = Activator.CreateInstance(serialization.TypeSelector) as VariantTypeSelector;
                }

                if (serialization.SectionSelector != null)
                {
                    SectionSelector = Activator.CreateInstance(serialization.SectionSelector) as SectionSelector;
                }

                if (serialization.Serializer != null)
                {
                    Serializer = Activator.CreateInstance(serialization.Serializer) as NodeSerializer;
                }

                if (writer != null && serialization.Prototype != null)
                {
                    WriteDefinition = writer.LookupStructDefinition(serialization.Prototype);
                }

                if (serialization.Name != null)
                {
                    GrannyName = serialization.Name;
                }

                Prototype         = serialization.Prototype;
                SerializationKind = serialization.Kind;
                ArraySize         = serialization.ArraySize;
                MinVersion        = serialization.MinVersion;
                MaxVersion        = serialization.MaxVersion;
            }
        }
Exemple #3
0
        public static MemberDefinition CreateFromFieldInfo(FieldInfo info, GR2Writer writer)
        {
            var member = new MemberDefinition();
            var type   = info.FieldType;

            member.Name           = info.Name;
            member.GrannyName     = info.Name;
            member.Extra          = new UInt32[] { 0, 0, 0 };
            member.CachedField    = info;
            member.HasCachedField = true;

            member.LoadAttributes(info, writer);

            if (type.IsArray)
            {
                if (member.ArraySize == 0)
                {
                    throw new InvalidOperationException("SerializationAttribute.ArraySize must be set for fixed size arrays");
                }
                type = type.GetElementType();
            }

            if (member.Type == MemberType.Invalid)
            {
                if (type == typeof(SByte))
                {
                    member.Type = MemberType.Int8;
                }
                else if (type == typeof(Byte))
                {
                    member.Type = MemberType.UInt8;
                }
                else if (type == typeof(Int16))
                {
                    member.Type = MemberType.Int16;
                }
                else if (type == typeof(UInt16))
                {
                    member.Type = MemberType.UInt16;
                }
                else if (type == typeof(Int32))
                {
                    member.Type = MemberType.Int32;
                }
                else if (type == typeof(UInt32))
                {
                    member.Type = MemberType.UInt32;
                }
                else if (type == typeof(Half))
                {
                    member.Type = MemberType.Real16;
                }
                else if (type == typeof(Single))
                {
                    member.Type = MemberType.Real32;
                }
                else if (type == typeof(string))
                {
                    member.Type = MemberType.String;
                }
                else if (type == typeof(Transform))
                {
                    member.Type = MemberType.Transform;
                }
                else if (type == typeof(object) || type.IsAbstract || type.IsInterface)
                {
                    member.Type = MemberType.VariantReference;
                }
                else if (type.GetInterfaces().Contains(typeof(IList <object>)))
                {
                    member.Type = MemberType.ReferenceToVariantArray;
                }
                else if (type.GetInterfaces().Contains(typeof(System.Collections.IList)))
                {
                    member.Type = MemberType.ReferenceToArray; // or ArrayOfReferences?
                }
                else
                {
                    member.Type = MemberType.Reference; // or Inline?
                }
            }

            if (member.SerializationKind != SerializationKind.None && member.WriteDefinition == null && writer != null)
            {
                if (member.Type == MemberType.Inline || member.Type == MemberType.Reference)
                {
                    member.WriteDefinition = writer.LookupStructDefinition(type);
                }
                else if (member.Type == MemberType.ReferenceToArray || member.Type == MemberType.ArrayOfReferences)
                {
                    member.WriteDefinition = writer.LookupStructDefinition(type.GetGenericArguments().Single());
                }
            }


            return(member);
        }