Exemplo n.º 1
0
        public void CollectMembers()
        {
            for (int index = 0; index < this._typeDefinition.MemberDefinitions.Count; ++index)
            {
                MemberDefinition memberDefinition = this._typeDefinition.MemberDefinitions[index];
                MemberSaveData   memberSaveData   = (MemberSaveData)null;
                switch (memberDefinition)
                {
                case PropertyDefinition _:
                    PropertyDefinition propertyDefinition = (PropertyDefinition)memberDefinition;
                    PropertyInfo       propertyInfo       = propertyDefinition.PropertyInfo;
                    MemberTypeId       id1 = propertyDefinition.Id;
                    PropertySaveData   propertySaveData = new PropertySaveData(this, propertyDefinition, id1);
                    this._propertyValues.Add(propertyInfo, propertySaveData);
                    memberSaveData = (MemberSaveData)propertySaveData;
                    break;

                case FieldDefinition _:
                    FieldDefinition fieldDefinition = (FieldDefinition)memberDefinition;
                    FieldInfo       fieldInfo       = fieldDefinition.FieldInfo;
                    MemberTypeId    id2             = fieldDefinition.Id;
                    FieldSaveData   fieldSaveData   = new FieldSaveData(this, fieldDefinition, id2);
                    this._fieldValues.Add(fieldInfo, fieldSaveData);
                    memberSaveData = (MemberSaveData)fieldSaveData;
                    break;
                }
                TypeDefinitionBase typeDefinition1 = this.Context.DefinitionContext.GetTypeDefinition(memberDefinition.GetMemberType());
                if (typeDefinition1 is TypeDefinition typeDefinition3 && !typeDefinition3.IsClassDefinition)
                {
                    ObjectSaveData childStruct = this._childStructs[memberDefinition];
                    memberSaveData.InitializeAsCustomStruct(childStruct.ObjectId);
                }
Exemplo n.º 2
0
        private static void ResolveViewModelName(MemberDefinition member,
                                                 ViewModelSettings viewModel, RenderSettings settings)
        {
            var namespaces = member.Dependencies();

            // if we don't have specific namespaces to search, we search them all
            if (namespaces == null || namespaces.Length == 0)
            {
                namespaces = settings.namespaces.Select(n => n.Key).ToArray();
            }

            foreach (var ns in namespaces)
            {
                var vms = FindViewModelSettingsInNamespace(ns, member.PropertyType(), settings);
                if (vms != null)
                {
                    // we are using the discovered view model's namespace
                    viewModel.usings.Add(vms.ViewModelNamespace());
                    if (member is CollectionDefinition)
                    {
                        (member as CollectionDefinition).typeParam = vms.type;
                    }
                    else
                    {
                        (member as PropertyDefinition).type = vms.type;
                    }

                    return; // success - we stop right here
                }
            }

            // if we get here, a view model was never found, so we are not emitting as view model
            member.EmitAsViewModel(false);
        }
Exemplo n.º 3
0
 public object Read(GR2Reader gr2, StructDefinition definition, MemberDefinition member, uint arraySize, object parent)
 {
     var controls = new List<UInt16>((int)arraySize);
     for (int i = 0; i < arraySize; i++)
         controls.Add(gr2.Reader.ReadUInt16());
     return controls;
 }
Exemplo n.º 4
0
        public PointObject()
        {
            var keyX   = new NameKey("x");
            var localX = MemberDefinition.CreateAndBuild(keyX, new AnyType(), Access.ReadWrite);
            var keyY   = new NameKey("y");
            var localY = MemberDefinition.CreateAndBuild(keyY, new AnyType(), Access.ReadWrite);

            RootScope = Model.Instantiated.RootScope.CreateAndBuild(
                Scope.CreateAndBuild(
                    new List <IsStatic>()
            {
                new IsStatic(MemberDefinition.CreateAndBuild(new NameKey("point"), new AnyType(), Access.ReadWrite), false)
            }),
                new[] {
                AssignOperation.CreateAndBuild(
                    ObjectDefiniton.CreateAndBuild(
                        Scope.CreateAndBuild(
                            new List <IsStatic> {
                    new IsStatic(localX, false),
                    new IsStatic(localY, false)
                }),
                        new IAssignOperation[] {
                    AssignOperation.CreateAndBuild(
                        ConstantNumber.CreateAndBuild(5),
                        MemberReference.CreateAndBuild(localX)),
                    AssignOperation.CreateAndBuild(
                        ConstantNumber.CreateAndBuild(2),
                        MemberReference.CreateAndBuild(localY))
                },
                        InterfaceType.CreateAndBuild(new [] { localX, localY })),
                    MemberReference.CreateAndBuild(MemberDefinition.CreateAndBuild(new NameKey("point"), new AnyType(), Access.ReadWrite)))
            },
                EntryPointDefinition.CreateAndBuild(new EmptyType(), MemberDefinition.CreateAndBuild(new NameKey("input"), new NumberType(), Access.ReadWrite), Scope.CreateAndBuild(Array.Empty <IsStatic>()), Array.Empty <ICodeElement>(), Array.Empty <ICodeElement>()));
        }
Exemplo n.º 5
0
        public static TypeDefinition FromBytes(byte[] bytes)
        {
            string parentType;
            int    version;

            MemberDefinition[] members;

            using (var writer = new SimpleByteWriter(bytes))
            {
                parentType = writer.ReadString();
                version    = writer.ReadInt();
                members    = new MemberDefinition[writer.ReadInt()];

                for (int i = 0; i < members.Length; i++)
                {
                    members[i] = MemberDefinition.ReadFromByteWriter(writer);
                }
            }

            return(new TypeDefinition()
            {
                ParentType = parentType,
                Version = version,
                Members = members,
            });
        }
Exemplo n.º 6
0
        public bool IsConditionallyExcluded(IMemberContext ctx, Location loc)
        {
            if ((Kind & (MemberKind.Class | MemberKind.Method)) == 0)
                return false;

            var conditions = MemberDefinition.ConditionalConditions ();
            if (conditions == null)
                return false;

            var m = ctx.CurrentMemberDefinition;
            CompilationSourceFile unit = null;
            while (m != null && unit == null) {
                unit = m as CompilationSourceFile;
                m = m.Parent;
            }

            if (unit != null) {
                foreach (var condition in conditions) {
                    if (unit.IsConditionalDefined (condition))
                        return false;
                }
            }

            return true;
        }
Exemplo n.º 7
0
 private static void ApplyViewModelPropertyAttribute(MemberDefinition prop,
                                                     ViewModelPropertyAttribute attr)
 {
     prop.access = attr.AccessModifier;
     // the read only setting on an attribute is only relevant if its value is true
     prop.readOnly = attr.ReadOnly ? attr.ReadOnly : prop.readOnly;
     prop.summary  = attr.Summary;
 }
Exemplo n.º 8
0
 public void WriteEnumValue(MemberDefinition member)
 {
     Write(GetIndent());
     Write(member.Name);
     if (member.DefaultValue != null)
     {
         Write($" = {member.DefaultValue}");
     }
 }
Exemplo n.º 9
0
 public static StadModel CreateFrom(Stad.Model.StadModelProto proto)
 {
     return(new StadModel(
                proto.Type,
                AnnotationInfo.CreateFrom(proto.Annotationinfo),
                new ReadOnlyCollection <MemberDefinition>(
                    proto.Members.Select(m => MemberDefinition.CreateFrom(m)).ToList())
                ));
 }
Exemplo n.º 10
0
        public PairType()
        {
            var pairTypeNumber =
                InterfaceType.CreateAndBuild(
                    new List <IMemberDefinition> {
                MemberDefinition.CreateAndBuild(new NameKey("x"), new NumberType(), false),
                MemberDefinition.CreateAndBuild(new NameKey("y"), new NumberType(), false)
            });

            var inputKey = new NameKey("input");
            var input    = MemberDefinition.CreateAndBuild(inputKey, new NumberType(), false);

            var methodScope = Scope.CreateAndBuild(new List <Scope.IsStatic> {
                new Scope.IsStatic(input, false)
            });

            var localX = MemberDefinition.CreateAndBuild(new NameKey("x"), new NumberType(), false);
            var localY = MemberDefinition.CreateAndBuild(new NameKey("y"), new NumberType(), false);

            var pairifyKey = new NameKey("pairify");
            var pairify    = MemberDefinition.CreateAndBuild(pairifyKey, MethodType.CreateAndBuild(new NumberType(), pairTypeNumber), false);

            Module = ModuleDefinition.CreateAndBuild(
                Scope.CreateAndBuild(
                    new List <Scope.IsStatic> {
                new Scope.IsStatic(MemberDefinition.CreateAndBuild(pairifyKey, MethodType.CreateAndBuild(new NumberType(), pairTypeNumber), false), false)
            }),
                new ICodeElement[] {
                AssignOperation.CreateAndBuild(
                    MethodDefinition.CreateAndBuild(
                        new NumberType(),
                        pairTypeNumber,
                        input,
                        methodScope,
                        new ICodeElement[] {
                    ReturnOperation.CreateAndBuild(
                        ObjectDefiniton.CreateAndBuild(
                            Scope.CreateAndBuild(
                                new List <Scope.IsStatic> {
                        new Scope.IsStatic(localX, false),
                        new Scope.IsStatic(localY, false)
                    }),
                            new IAssignOperation[] {
                        AssignOperation.CreateAndBuild(
                            MemberReference.CreateAndBuild(input),
                            MemberReference.CreateAndBuild(localX)),
                        AssignOperation.CreateAndBuild(
                            MemberReference.CreateAndBuild(input),
                            MemberReference.CreateAndBuild(localY))
                    }))
                },
                        new ICodeElement[0],
                        false),
                    MemberReference.CreateAndBuild(pairify))
            },
                new NameKey("pair-type"));
        }
Exemplo n.º 11
0
        public Closoure()
        {
            var xKey = new NameKey("x");
            var x    = MemberDefinition.CreateAndBuild(xKey, new NumberType(), false);

            var yKey = new NameKey("y");
            var y    = MemberDefinition.CreateAndBuild(yKey, new NumberType(), false);

            var methodScope = Scope.CreateAndBuild(new List <Scope.IsStatic> {
                new Scope.IsStatic(x, false)
            });
            var innerMethodScope = Scope.CreateAndBuild(new List <Scope.IsStatic> {
                new Scope.IsStatic(y, false)
            }, methodScope);

            Module = ModuleDefinition.CreateAndBuild(
                Scope.CreateAndBuild(
                    new List <Scope.IsStatic>()
            {
                new Scope.IsStatic(MemberDefinition.CreateAndBuild(new NameKey("create-accululator"), new AnyType(), false), false)
            }),
                new[] {
                AssignOperation.CreateAndBuild(
                    MethodDefinition.CreateAndBuild(
                        new NumberType(),
                        MethodType.CreateAndBuild(
                            new NumberType(),
                            new NumberType()),
                        x,
                        methodScope,
                        new ICodeElement[] {
                    ReturnOperation.CreateAndBuild(
                        MethodDefinition.CreateAndBuild(
                            new NumberType(),
                            new NumberType(),
                            y,
                            innerMethodScope,
                            new ICodeElement[] {
                        AssignOperation.CreateAndBuild(
                            AddOperation.CreateAndBuild(
                                MemberReference.CreateAndBuild(x),
                                MemberReference.CreateAndBuild(y)),
                            MemberReference.CreateAndBuild(x)),
                        ReturnOperation.CreateAndBuild(
                            MemberReference.CreateAndBuild(x))
                    },
                            new ICodeElement[0],
                            false)
                        )
                },
                        new ICodeElement[0],
                        false),
                    MemberReference.CreateAndBuild(MemberDefinition.CreateAndBuild(new NameKey("create-accululator"), new AnyType(), false)))
            },
                new NameKey("closoure"));
        }
Exemplo n.º 12
0
        public PairType()
        {
            var pairTypeNumber =
                InterfaceType.CreateAndBuild(
                    new List <IMemberDefinition> {
                MemberDefinition.CreateAndBuild(new NameKey("x"), new NumberType(), Access.ReadWrite),
                MemberDefinition.CreateAndBuild(new NameKey("y"), new NumberType(), Access.ReadWrite)
            });

            var inputKey = new NameKey("input");
            var input    = MemberDefinition.CreateAndBuild(inputKey, new NumberType(), Access.ReadWrite);

            var methodScope = Scope.CreateAndBuild(new List <IsStatic> {
                new IsStatic(input, false)
            });

            var localX = MemberDefinition.CreateAndBuild(new NameKey("x"), new NumberType(), Access.ReadWrite);
            var localY = MemberDefinition.CreateAndBuild(new NameKey("y"), new NumberType(), Access.ReadWrite);

            var pairifyKey = new NameKey("pairify");
            var pairify    = MemberDefinition.CreateAndBuild(pairifyKey, MethodType.CreateAndBuild(new NumberType(), pairTypeNumber), Access.ReadWrite);

            RootScope = Model.Instantiated.RootScope.CreateAndBuild(
                Scope.CreateAndBuild(
                    new List <IsStatic> {
                new IsStatic(MemberDefinition.CreateAndBuild(pairifyKey, MethodType.CreateAndBuild(new NumberType(), pairTypeNumber), Access.ReadWrite), false)
            }),
                new [] {
                AssignOperation.CreateAndBuild(
                    MethodDefinition.CreateAndBuild(
                        pairTypeNumber,
                        input,
                        methodScope,
                        new ICodeElement[] {
                    ReturnOperation.CreateAndBuild(
                        ObjectDefiniton.CreateAndBuild(
                            Scope.CreateAndBuild(
                                new List <IsStatic> {
                        new IsStatic(localX, false),
                        new IsStatic(localY, false)
                    }),
                            new IAssignOperation[] {
                        AssignOperation.CreateAndBuild(
                            MemberReference.CreateAndBuild(input),
                            MemberReference.CreateAndBuild(localX)),
                        AssignOperation.CreateAndBuild(
                            MemberReference.CreateAndBuild(input),
                            MemberReference.CreateAndBuild(localY))
                    },
                            InterfaceType.CreateAndBuild(new [] { localX, localY })))
                },
                        Array.Empty <ICodeElement>()),
                    MemberReference.CreateAndBuild(pairify))
            },
                EntryPointDefinition.CreateAndBuild(new EmptyType(), MemberDefinition.CreateAndBuild(new NameKey("input"), new NumberType(), Access.ReadWrite), Scope.CreateAndBuild(Array.Empty <IsStatic>()), Array.Empty <ICodeElement>(), Array.Empty <ICodeElement>()));
        }
Exemplo n.º 13
0
        public static IMemberDefinition Convert(IIsPossibly <IWeakTypeReference> Type, IConversionContext context, bool ReadOnly, IKey Key)
        {
            var(def, builder) = MemberDefinition.Create();

            var buildIntention = Type.GetOrThrow().TypeDefinition.GetOrThrow().GetValue().GetOrThrow().Cast <IConvertable <IVerifiableType> >().GetBuildIntention(context);

            buildIntention.Build();
            builder.Build(Key, buildIntention.Tobuild, ReadOnly);
            return(def);
        }
Exemplo n.º 14
0
        //public IMemberDefinition Convert(IConversionContext context)
        //{
        //    return MemberDefinitionShared.Convert(Type, context, Access, Key);
        //}

        public virtual IBuildIntention <IMemberDefinition> GetBuildIntention(IConversionContext context)
        {
            var(toBuild, maker) = MemberDefinition.Create();
            return(new BuildIntention <IMemberDefinition>(toBuild, () =>
            {
                maker.Build(
                    Key,
                    Type.GetValue().Is1OrThrow().Convert(context),
                    Access);
            }));
        }
Exemplo n.º 15
0
        public Type SelectType(MemberDefinition member, object node)
        {
            var list = node as System.Collections.IList;

            if (list == null || list.Count == 0)
            {
                return(null);
            }

            return((list[0] as Vertex).Prototype());
        }
Exemplo n.º 16
0
 public static IBuildIntention <IMemberDefinition> GetBuildIntention(IIsPossibly <IWeakTypeReference> Type, IConversionContext context, bool ReadOnly, IKey Key)
 {
     var(toBuild, maker) = MemberDefinition.Create();
     return(new BuildIntention <IMemberDefinition>(toBuild, () =>
     {
         maker.Build(
             Key,
             Type.GetOrThrow().TypeDefinition.GetOrThrow().GetValue().GetOrThrow().ConvertTypeOrThrow(context),
             ReadOnly);
     }));
 }
Exemplo n.º 17
0
 public void WriteProperty(MemberDefinition member, bool optional = false, bool knockout = default)
 {
     Write(GetIndent());
     Write(member.Name.ToCamel());
     if (optional)
     {
         Write('?');
     }
     Write(": ");
     Write(GetDataType(member.Type, _settings.Prefix, _settings.Suffix, member.IsCollection, knockout));
     WriteLine(';');
 }
Exemplo n.º 18
0
        private ClassDefinition BuildClass(Table table)
        {
            var defn = new ClassDefinition
            {
                Name = table.PocoClassName,
                //Name = RemoveSuffix(table.DataObjectClassName, "_t"),
                OriginalTableName = table.TableName,
                AdapterName       = table.TableName.Replace("_", "") + (AdapterSuffix ?? "")
            };

            foreach (var column in table.Columns.Values)
            {
                var memberName = column.MemberName;
                if (AdjustColumnTypes)
                {
                    //if (column.MemberName.EndsWith("_ID"))
                    //{
                    //	memberName = RemoveSuffix(column.MemberName, "_ID") + "Id";
                    //}
                    //else
                    //{
                    //	memberName = Regex.Replace(column.MemberName, "^F[0-9]+_", "");
                    //	memberName = RemoveSuffix(memberName, "_VC");
                    //	memberName = RemoveSuffix(memberName, "_BT");
                    //	memberName = RemoveSuffix(memberName, "_DT");
                    //	memberName = RemoveSuffix(memberName, "_IN");
                    //	memberName = RemoveSuffix(memberName, "_TX");
                    //	memberName = RemoveSuffix(memberName, "_DC");
                    //	memberName = RemoveSuffix(memberName, "_SM");
                    //	memberName = RemoveSuffix(memberName, "_TI");
                    //	memberName = RemoveSuffix(memberName, "_CH");
                    //	memberName = RemoveSuffix(memberName, "_BI");
                    //	memberName = RemoveSuffix(memberName, "_MX");
                    //	memberName = RemoveSuffix(memberName, "_PC");
                    //}

                    memberName = memberName.Replace("_", "");
                }

                var member = new MemberDefinition
                {
                    Name = memberName,
                    Type = GetColumnType(memberName, column),
                    OriginalColumnName = column.MemberName,
                    Skip = column.IsIdentity
                };

                defn.Members.Add(member);
            }

            return(defn);
        }
Exemplo n.º 19
0
        protected virtual void InitializeMemberCache(bool onlyTypes)
        {
            MemberDefinition.LoadMembers(this, onlyTypes, ref cache);

            if (onlyTypes)
            {
                state |= StateFlags.PendingMemberCacheMembers;
            }
            else
            {
                state &= ~StateFlags.PendingMemberCacheMembers;
            }
        }
Exemplo n.º 20
0
 internal override void SetNewContext(bool fromMoveNext)
 {
     base.SetNewContext(fromMoveNext);
     if (m_header != null)
     {
         m_header.SetNewContext();
     }
     if (m_instance != null)
     {
         m_instance.SetNewContext();
     }
     MemberDefinition?.ResetVisibilityComputationCache();
 }
Exemplo n.º 21
0
            internal static MemberDefinition Read(Stream input, Endian endian, StringTable stringTable)
            {
                var instance  = new MemberDefinition();
                var nameIndex = input.ReadValueS64(endian);

                instance.Name         = stringTable.Get(nameIndex);
                instance.TypeHash     = input.ReadValueU32(endian);
                instance.Size         = input.ReadValueU32(endian);
                instance.Offset       = input.ReadValueU32(endian);
                instance.DefaultType  = input.ReadValueU32(endian);
                instance.DefaultValue = input.ReadValueU64(endian);
                return(instance);
            }
        public Type SelectType(MemberDefinition member, StructDefinition defn, object parent)
        {
            var fieldName = defn.Members[0].Name;

            if (fieldName.Substring(0, 16) != "CurveDataHeader_")
            {
                throw new ParsingException("Unrecognized curve data header type: " + fieldName);
            }

            var curveType = fieldName.Substring(16);

            return(CurveRegistry.Resolve(curveType));
        }
Exemplo n.º 23
0
        public Closoure()
        {
            var xKey = new NameKey("x");
            var x    = MemberDefinition.CreateAndBuild(xKey, new NumberType(), Access.ReadWrite);

            var yKey = new NameKey("y");
            var y    = MemberDefinition.CreateAndBuild(yKey, new NumberType(), Access.ReadWrite);

            var methodScope = Scope.CreateAndBuild(new List <IsStatic> {
                new IsStatic(x, false)
            });
            var innerMethodScope = Scope.CreateAndBuild(new List <IsStatic> {
                new IsStatic(y, false)
            });

            RootScope = Model.Instantiated.RootScope.CreateAndBuild(
                Scope.CreateAndBuild(
                    new List <IsStatic>()
            {
                new IsStatic(MemberDefinition.CreateAndBuild(new NameKey("create-accululator"), new AnyType(), Access.ReadWrite), false)
            }),
                new [] {
                AssignOperation.CreateAndBuild(
                    MethodDefinition.CreateAndBuild(
                        MethodType.CreateAndBuild(
                            new NumberType(),
                            new NumberType()),
                        x,
                        methodScope,
                        new ICodeElement[] {
                    ReturnOperation.CreateAndBuild(
                        MethodDefinition.CreateAndBuild(
                            new NumberType(),
                            y,
                            innerMethodScope,
                            new ICodeElement[] {
                        AssignOperation.CreateAndBuild(
                            AddOperation.CreateAndBuild(
                                MemberReference.CreateAndBuild(x),
                                MemberReference.CreateAndBuild(y)),
                            MemberReference.CreateAndBuild(x)),
                        ReturnOperation.CreateAndBuild(MemberReference.CreateAndBuild(x))
                    },
                            Array.Empty <ICodeElement>())
                        )
                },
                        Array.Empty <ICodeElement>()),
                    MemberReference.CreateAndBuild(MemberDefinition.CreateAndBuild(new NameKey("create-accululator"), new AnyType(), Access.ReadWrite)))
            },
                EntryPointDefinition.CreateAndBuild(new EmptyType(), MemberDefinition.CreateAndBuild(new NameKey("input"), new NumberType(), Access.ReadWrite), Scope.CreateAndBuild(Array.Empty <IsStatic>()), Array.Empty <ICodeElement>(), Array.Empty <ICodeElement>()));
        }
Exemplo n.º 24
0
        private void AddMember(StructDefinition defn, String name, MemberType type, UInt32 arraySize)
        {
            var member = new MemberDefinition
            {
                Type       = type,
                Name       = name,
                GrannyName = name,
                Definition = null,
                ArraySize  = arraySize,
                Extra      = new UInt32[] { 0, 0, 0 },
                Unknown    = 0
            };

            defn.Members.Add(member);
        }
Exemplo n.º 25
0
        public object Read(GR2Reader reader, StructDefinition definition, MemberDefinition member, uint arraySize, object parent)
        {
            Type type;

            if (!VertexTypeCache.TryGetValue(parent, out type))
            {
                type = SelectType(member, definition, parent);
                VertexTypeCache.Add(parent, type);
            }

            var vertex = Helpers.CreateInstance(type);

            (vertex as Vertex).Unserialize(reader);
            return(vertex);
        }
Exemplo n.º 26
0
        public object Read(GR2Reader reader, StructDefinition definition, MemberDefinition member, uint arraySize, object parent)
        {
            VertexDescriptor descriptor;

            if (!VertexTypeCache.TryGetValue(parent, out descriptor))
            {
                descriptor = ConstructDescriptor(member, definition, parent);
                VertexTypeCache.Add(parent, descriptor);
            }

            var vertex = descriptor.CreateInstance();

            vertex.Unserialize(reader);
            return(vertex);
        }
Exemplo n.º 27
0
        public override bool Equals(object obj)
        {
            if (ReferenceEquals(obj, null))
            {
                return(false);
            }
            else if (!(obj is MemberDefinition))
            {
                return(false);
            }

            MemberDefinition otherMember = (MemberDefinition)obj;

            return(MemberType == otherMember.MemberType && FieldName == otherMember.FieldName);
        }
Exemplo n.º 28
0
        /// <summary>
        /// Registers the property.
        /// </summary>
        /// <param name="property">The property.</param>
        /// <param name="parameters">The parameters.</param>
        /// <param name="prefix">The prefix.</param>
        private void RegisterProperty(Expression <Func <TService, object> > property, IList <Type> parameters,
                                      string prefix)
        {
            Argument.IsNotNull("property", property);

            var memberExpression = property.GetMemberExpression();
            var methodName       = string.Format("{0}{1}", prefix, memberExpression.Member.Name);
            var memberDefinition = new MemberDefinition(methodName, parameters);

            if (!ServiceType.IsInterfaceEx())
            {
                Require.OverridableProperty <TService>(memberDefinition.MemberName);
            }

            RegisterMemberDefinitions(new[] { memberDefinition });
        }
Exemplo n.º 29
0
        protected virtual void InitializeMemberCache(bool onlyTypes)
        {
            try {
                MemberDefinition.LoadMembers(this, onlyTypes, ref cache);
            } catch (Exception e) {
                throw new InternalErrorException(e, "Unexpected error when loading type `{0}'", GetSignatureForError());
            }

            if (onlyTypes)
            {
                state |= StateFlags.PendingMemberCacheMembers;
            }
            else
            {
                state &= ~StateFlags.PendingMemberCacheMembers;
            }
        }
Exemplo n.º 30
0
        public SectionType SelectSection(MemberDefinition member, Type type, object obj)
        {
            var vertices = obj as List <Vertex>;

            if (vertices == null || vertices.Count == 0)
            {
                return(SectionType.RigidVertex);
            }

            if (vertices[0].Format.HasBoneWeights)
            {
                return(SectionType.DeformableVertex);
            }
            else
            {
                return(SectionType.RigidVertex);
            }
        }
Exemplo n.º 31
0
        public SectionType SelectSection(MemberDefinition member, Type type, object obj)
        {
            var vertices = obj as System.Collections.IList;

            if (vertices == null || vertices.Count == 0)
            {
                return(SectionType.RigidVertex);
            }

            if (Vertex.Description(vertices[0].GetType()).BoneWeights)
            {
                return(SectionType.DeformableVertex);
            }
            else
            {
                return(SectionType.RigidVertex);
            }
        }
Exemplo n.º 32
0
 public InvocationResolveResult(MemberDefinition member, params ResolveResult[] arguments)
     : base(member)
 {
     Arguments = arguments.ToList().AsReadOnly();
 }
Exemplo n.º 33
0
 public InvocationResolveResult(MemberDefinition member, IEnumerable<ResolveResult> arguments)
     : this(member, arguments.ToArray())
 {
 }
Exemplo n.º 34
0
        public object Read(GR2Reader reader, StructDefinition definition, MemberDefinition member, uint arraySize, object parent)
        {
            Type type;
            if (!VertexTypeCache.TryGetValue(parent, out type))
            {
                type = SelectType(member, definition, parent);
                VertexTypeCache.Add(parent, type);
            }

            var vertex = Helpers.CreateInstance(type);
            (vertex as Vertex).Unserialize(reader);
            return vertex;
        }
Exemplo n.º 35
0
 public Type SelectType(MemberDefinition member, StructDefinition defn, object parent)
 {
     return VertexFormatRegistry.FindByStruct(defn);
 }
Exemplo n.º 36
0
        private object ReadElement(MemberDefinition definition, object node, Type propertyType, object parent)
        {
#if DEBUG_GR2_SERIALIZATION
            var offsetInFile = Stream.Position;
#endif

            var kind = definition.SerializationKind;
            Debug.Assert(kind == SerializationKind.Builtin || !definition.IsScalar);
            if (node == null && 
                propertyType != null && 
                !definition.IsScalar &&
                (kind == SerializationKind.Builtin || kind == SerializationKind.UserElement) && 
                // Variant construction is a special case as we don't know the struct defn beforehand
                definition.Type != MemberType.VariantReference)
            {
                node = Helpers.CreateInstance(propertyType);
            }

            switch (definition.Type)
            {
                case MemberType.Inline:
                    Debug.Assert(definition.Definition.IsValid);
#if DEBUG_GR2_SERIALIZATION
                    System.Console.WriteLine(String.Format(" === Inline Struct {0} === ", definition.Name));
#endif
                    if (kind == SerializationKind.UserElement || kind == SerializationKind.UserMember)
                        node = definition.Serializer.Read(this, definition.Definition.Resolve(this), definition, 0, parent);
                    else
                        node = ReadStruct(definition.Definition.Resolve(this), definition.Type, node, parent);
#if DEBUG_GR2_SERIALIZATION
                    System.Console.WriteLine(" === End Struct === ");
#endif
                    break;

                case MemberType.Reference:
                    {
                        Debug.Assert(definition.Definition.IsValid);
                        var r = ReadReference();

                        if (r.IsValid && parent != null)
                        {
                            var originalPos = Stream.Position;
                            Seek(r);
#if DEBUG_GR2_SERIALIZATION
                            System.Console.WriteLine(String.Format(" === Struct <{0}> at {1:X8} === ", definition.Name, Stream.Position));
#endif
                            if (kind == SerializationKind.UserElement || kind == SerializationKind.UserMember)
                                node = definition.Serializer.Read(this, definition.Definition.Resolve(this), definition, 0, parent);
                            else
                                node = ReadStruct(definition.Definition.Resolve(this), definition.Type, node, parent);
#if DEBUG_GR2_SERIALIZATION
                            System.Console.WriteLine(" === End Struct === ");
#endif
                            Stream.Seek(originalPos, SeekOrigin.Begin);
                        }
                        else
                            node = null;
                        break;
                    }

                case MemberType.VariantReference:
                    {
                        var structRef = ReadStructReference();
                        var r = ReadReference();

                        if (r.IsValid && parent != null)
                        {
                            var structDefn = structRef.Resolve(this);
                            if (definition.TypeSelector != null && definition.Type == MemberType.VariantReference)
                                propertyType = definition.TypeSelector.SelectType(definition, structDefn, parent);
                            if (propertyType != null)
                                node = Helpers.CreateInstance(propertyType);

                            if (node != null)
                            {
                                var originalPos = Stream.Position;
                                Seek(r);
#if DEBUG_GR2_SERIALIZATION
                                System.Console.WriteLine(String.Format(" === Variant Struct <{0}> at {1:X8} === ", definition.Name, Stream.Position));
#endif
                                if (kind == SerializationKind.UserElement || kind == SerializationKind.UserMember)
                                    node = definition.Serializer.Read(this, structDefn, definition, 0, parent);
                                else
                                    node = ReadStruct(structRef.Resolve(this), definition.Type, node, parent);
#if DEBUG_GR2_SERIALIZATION
                                System.Console.WriteLine(" === End Struct === ");
#endif
                                Stream.Seek(originalPos, SeekOrigin.Begin);
                            }
                        }
                        else
                            node = null;
                        break;
                    }

                case MemberType.ArrayOfReferences:
                    {
                        // Serializing as a struct member is nooooot a very good idea here.
                        Debug.Assert(kind != SerializationKind.UserMember);
                        Debug.Assert(definition.Definition.IsValid);
                        var indices = ReadArrayIndicesReference();
#if DEBUG_GR2_SERIALIZATION
                        System.Console.WriteLine(String.Format("    Array of references at [{0:X8}]", indices.Offset));
#endif

                        Debug.Assert(indices.IsValid == (indices.Size != 0));

                        if (indices.IsValid && node != null && parent != null)
                        {
                            var items = node as System.Collections.IList;
                            var type = items.GetType().GetGenericArguments().Single();

                            var refs = indices.Resolve(this);
                            var originalPos = Stream.Position;
                            for (int i = 0; i < refs.Count; i++)
                            {
                                Seek(refs[i]);
#if DEBUG_GR2_SERIALIZATION
                                System.Console.WriteLine(String.Format(" === Struct <{0}> at {1:X8} === ", definition.Name, Stream.Position));
#endif
                                if (kind == SerializationKind.UserElement)
                                {
                                    object element = definition.Serializer.Read(this, definition.Definition.Resolve(this), definition, 0, parent);
                                    items.Add(element);
                                }
                                else
                                {
                                    object element = Helpers.CreateInstance(type);
                                    // TODO: Only create a new instance if we don't have a CachedStruct available!
                                    element = ReadStruct(definition.Definition.Resolve(this), definition.Type, element, parent);
                                    items.Add(element);

                                }
#if DEBUG_GR2_SERIALIZATION
                                System.Console.WriteLine(" === End Struct === ");
#endif
                            }

                            Stream.Seek(originalPos, SeekOrigin.Begin);
                            node = items;
                        }
                        else
                            node = null;
                        break;
                    }

                case MemberType.ReferenceToArray:
                case MemberType.ReferenceToVariantArray:
                    {
                        StructReference structRef;
                        if (definition.Type == MemberType.ReferenceToVariantArray)
                            structRef = ReadStructReference();
                        else
                            structRef = definition.Definition;

                        var itemsRef = ReadArrayReference();

                        Debug.Assert(itemsRef.IsValid == (itemsRef.Size != 0));

                        if (itemsRef.IsValid && 
                            parent != null &&
                            (node != null || kind == SerializationKind.UserMember))
                        {
                            Debug.Assert(structRef.IsValid);
                            var structType = structRef.Resolve(this);
                            var originalPos = Stream.Position;
                            Seek(itemsRef);

                            if (kind == SerializationKind.UserMember)
                            {
                                // For ReferenceTo(Variant)Array, we start serialization after resolving the array ref itself.
                                node = definition.Serializer.Read(this, structType, definition, itemsRef.Size, parent);
                            }
                            else
                            {
                                var items = node as System.Collections.IList;
                                var type = items.GetType().GetGenericArguments().Single();
                                if (definition.Type == MemberType.ReferenceToVariantArray && 
                                    kind != SerializationKind.UserElement &&
                                    definition.TypeSelector != null)
                                    type = definition.TypeSelector.SelectType(definition, structType, parent);

                                for (int i = 0; i < itemsRef.Size; i++)
                                {
#if DEBUG_GR2_SERIALIZATION
                                    System.Console.WriteLine(String.Format(" === Struct <{0}> at {1:X8} === ", definition.Name, Stream.Position));
#endif
                                    if (kind == SerializationKind.UserElement)
                                    {
                                        object element = definition.Serializer.Read(this, structType, definition, 0, parent);
                                        items.Add(element);
                                    }
                                    else
                                    {
                                        object element = Helpers.CreateInstance(type);
                                        element = ReadStruct(structType, definition.Type, element, parent);
                                        items.Add(element);
                                    }
#if DEBUG_GR2_SERIALIZATION
                                    System.Console.WriteLine(" === End Struct === ");
#endif
                                }
                            }

                            Stream.Seek(originalPos, SeekOrigin.Begin);
                        }
                        else
                            node = null;
                        break;
                    }

                case MemberType.String:
                    var str = ReadStringReference();
                    if (str.IsValid)
                        node = str.Resolve(this);
                    else
                        node = null;
                    break;

                case MemberType.Transform:
                    var transform = new Transform();
                    transform.Flags = Reader.ReadUInt32();

                    for (int i = 0; i < 3; i++)
                        transform.Translation[i] = Reader.ReadSingle();

                    transform.Rotation.X = Reader.ReadSingle();
                    transform.Rotation.Y = Reader.ReadSingle();
                    transform.Rotation.Z = Reader.ReadSingle();
                    transform.Rotation.W = Reader.ReadSingle();

                    for (int i = 0; i < 3; i++)
                    {
                        for (int j = 0; j < 3; j++)
                            transform.ScaleShear[i, j] = Reader.ReadSingle();
                    }

                    node = transform;
                    break;

                case MemberType.Real16:
                    throw new NotImplementedException("TODO");

                case MemberType.Real32:
                    node = Reader.ReadSingle();
                    break;

                case MemberType.Int8:
                case MemberType.BinormalInt8:
                    node = Reader.ReadSByte();
                    break;

                case MemberType.UInt8:
                case MemberType.NormalUInt8:
                    node = Reader.ReadByte();
                    break;

                case MemberType.Int16:
                case MemberType.BinormalInt16:
                    node = Reader.ReadInt16();
                    break;

                case MemberType.UInt16:
                case MemberType.NormalUInt16:
                    node = Reader.ReadUInt16();
                    break;

                case MemberType.Int32:
                    node = Reader.ReadInt32();
                    break;

                case MemberType.UInt32:
                    node = Reader.ReadUInt32();
                    break;

                default:
                    throw new ParsingException(String.Format("Unhandled member type: {0}", definition.Type.ToString()));
            }

#if DEBUG_GR2_SERIALIZATION
            if (node != null)
                System.Console.WriteLine(String.Format("    [{0:X8}] {1}: {2}", offsetInFile, definition.Name, node.ToString()));
            else
                System.Console.WriteLine(String.Format("    [{0:X8}] {1}: <null>", offsetInFile, definition.Name));
#endif

            return node;
        }
Exemplo n.º 37
0
        internal void QueueArrayWrite(SectionType section, bool dataArea, Type elementType, MemberDefinition member, System.Collections.IList list)
        {
            QueuedArraySerialization serialization;
            serialization.section = section;
            serialization.dataArea = dataArea;
            if (member.PreferredSection != SectionType.Invalid)
                serialization.section = member.PreferredSection;
            else if (member.SectionSelector != null)
                serialization.section = member.SectionSelector.SelectSection(member, elementType, list);
            serialization.elementType = elementType;
            serialization.member = member;
            serialization.list = list;

            Sections[(int)serialization.section].CheckMixedMarshalling(list[0], elementType, (UInt32)list.Count);
            ArrayWrites.Add(serialization);
        }
Exemplo n.º 38
0
        internal void WriteInstance(MemberDefinition definition, Type propertyType, object node)
        {
            if (definition.ArraySize == 0)
            {
                WriteElement(definition, propertyType, node);
                return;
            }

            if (propertyType.IsArray)
            {
                // If the property is a native array (ie. SomeType[]), create an array instance and set its values
                var elementType = propertyType.GetElementType();

                Array arr = node as Array;
                Debug.Assert(arr.Length == definition.ArraySize);
                for (int i = 0; i < definition.ArraySize; i++)
                {
                    WriteElement(definition, elementType, arr.GetValue(i));
                }
            }
            else
            {
                // For non-native arrays we always assume the property is an IList<T>
                var items = node as System.Collections.IList;
                var elementType = items.GetType().GetGenericArguments().Single();
                foreach (var element in items)
                {
                    WriteElement(definition, elementType, element);
                }
            }
        }
Exemplo n.º 39
0
        private void WriteElement(MemberDefinition definition, Type propertyType, object node)
        {
            var type = definition.CachedField.FieldType;
            bool dataArea = definition.DataArea || (Writer == DataWriter);

            switch (definition.Type)
            {
                case MemberType.Inline:
                    if (definition.SerializationKind == SerializationKind.UserMember)
                        definition.Serializer.Write(this.GR2, this, definition, node);
                    else
                        WriteStruct(type, node, false);
                    break;

                case MemberType.Reference:
                    {
                        WriteReference(node);
                        if (node != null)
                        {
                            GR2.QueueStructWrite(Type, dataArea, definition, type, node);
                        }
                        break;
                    }

                case MemberType.VariantReference:
                    {
                        if (node != null)
                        {
                            var inferredType = node.GetType();
                            if (definition.TypeSelector != null)
                            {
                                var variantType = definition.TypeSelector.SelectType(definition, node);
                                if (variantType != null)
                                    inferredType = variantType;
                            }

                            WriteStructReference(GR2.LookupStructDefinition(inferredType));
                            WriteReference(node);

                            GR2.QueueStructWrite(Type, dataArea, definition, inferredType, node);
                        }
                        else
                        {
                            WriteStructReference(null);
                            WriteReference(null);
                        }
                        break;
                    }

                case MemberType.ArrayOfReferences:
                    {
                        // Serializing as a struct member is nooooot a very good idea here.
                        // Debug.Assert(kind != SerializationKind.UserMember);
                        var list = node as System.Collections.IList;
                        WriteArrayIndicesReference(list);

                        if (list != null && list.Count > 0)
                        {
                            GR2.QueueArrayWrite(Type, dataArea, type.GetGenericArguments().Single(), definition, list);
                        }

                        break;
                    }

                case MemberType.ReferenceToArray:
                    {
                        var list = node as System.Collections.IList;
                        WriteArrayIndicesReference(list);

                        if (list != null && list.Count > 0)
                        {
                            GR2.QueueArrayWrite(Type, dataArea, type.GetGenericArguments().Single(), definition, list);
                        }
                        break;
                    }

                case MemberType.ReferenceToVariantArray:
                    {
                        var list = node as System.Collections.IList;

                        if (list != null && list.Count > 0)
                        {
                            var inferredType = list[0].GetType();
                            if (definition.TypeSelector != null)
                            {
                                var variantType = definition.TypeSelector.SelectType(definition, node);
                                if (variantType != null)
                                    inferredType = variantType;
                            }

                            WriteStructReference(GR2.LookupStructDefinition(inferredType));
                            WriteArrayIndicesReference(list);
                            GR2.QueueArrayWrite(Type, dataArea, inferredType, definition, list);
                        }
                        else
                        {
                            WriteStructReference(null);
                            WriteArrayIndicesReference(list);
                        }
                        break;
                    }

                case MemberType.String:
                    WriteStringReference(node as string);
                    break;

                case MemberType.Transform:
                    var transform = node as Transform;
                    Writer.Write(transform.Flags);

                    for (int i = 0; i < 3; i++)
                        Writer.Write(transform.Translation[i]);

                    Writer.Write(transform.Rotation.X);
                    Writer.Write(transform.Rotation.Y);
                    Writer.Write(transform.Rotation.Z);
                    Writer.Write(transform.Rotation.W);

                    for (int i = 0; i < 3; i++)
                    {
                        for (int j = 0; j < 3; j++)
                            Writer.Write(transform.ScaleShear[i, j]);
                    }
                    break;

                case MemberType.Real16:
                    Writer.Write((Half)node);
                    break;

                case MemberType.Real32:
                    Writer.Write((Single)node);
                    break;

                case MemberType.Int8:
                case MemberType.BinormalInt8:
                    Writer.Write((SByte)node);
                    break;

                case MemberType.UInt8:
                case MemberType.NormalUInt8:
                    Writer.Write((Byte)node);
                    break;

                case MemberType.Int16:
                case MemberType.BinormalInt16:
                    Writer.Write((Int16)node);
                    break;

                case MemberType.UInt16:
                case MemberType.NormalUInt16:
                    Writer.Write((UInt16)node);
                    break;

                case MemberType.Int32:
                    Writer.Write((Int32)node);
                    break;

                case MemberType.UInt32:
                    Writer.Write((UInt32)node);
                    break;

                default:
                    throw new ParsingException(String.Format("Unhandled member type: {0}", definition.Type.ToString()));
            }
        }
Exemplo n.º 40
0
        public void WriteStructDefinition(StructDefinition defn)
        {
            Debug.Assert(Writer == MainWriter);
            GR2.ObjectOffsets[defn] = new SectionReference(Type, (UInt32)MainStream.Position);

            var tag = GR2.Header.tag;
            foreach (var member in defn.Members)
            {
                if (member.ShouldSerialize(tag))
                {
                    WriteMemberDefinition(member);
                }
            }

            var end = new MemberDefinition();
            end.Type = MemberType.None;
            end.Extra = new UInt32[] { 0, 0, 0 };
            WriteMemberDefinition(end);
        }
Exemplo n.º 41
0
        internal void WriteArray(MemberDefinition arrayDefn, Type elementType, System.Collections.IList list)
        {
            bool dataArea = arrayDefn.DataArea || (Writer == DataWriter);
            AlignWrite();

            switch (arrayDefn.Type)
            {
                case MemberType.ArrayOfReferences:
                    {
                        // Serializing as a struct member is nooooot a very good idea here.
                        // Debug.Assert(kind != SerializationKind.UserMember);

                        // Reference lists are always written to the data area
                        var oldWriter = Writer;
                        Writer = DataWriter;

                        StoreObjectOffset(list);
                        for (int i = 0; i < list.Count; i++)
                        {
                            WriteReference(list[i]);
                            GR2.QueueStructWrite(Type, dataArea, arrayDefn, elementType, list[i]);
                        }

                        Writer = oldWriter;
                        break;
                    }

                case MemberType.ReferenceToArray:
                case MemberType.ReferenceToVariantArray:
                    {
                        StoreObjectOffset(list);

                        if (arrayDefn.SerializationKind == SerializationKind.UserMember)
                        {
                            arrayDefn.Serializer.Write(this.GR2, this, arrayDefn, list);
                        }
                        else if (arrayDefn.SerializationKind == SerializationKind.UserElement)
                        {
                            for (int i = 0; i < list.Count; i++)
                            {
                                StoreObjectOffset(list[i]);
                                arrayDefn.Serializer.Write(this.GR2, this, arrayDefn, list[i]);
                            }
                        }
                        else
                        {
                            for (int i = 0; i < list.Count; i++)
                            {
                                WriteStruct(elementType, list[i], false);
                            }
                        }

                        GR2.FlushPendingWrites();

                        break;
                    }

                default:
                    throw new ParsingException(String.Format("Unhandled array member type: {0}", arrayDefn.Type.ToString()));
            }
        }
Exemplo n.º 42
0
 public void WriteMemberDefinition(MemberDefinition defn)
 {
     Writer.Write((UInt32)defn.Type);
     WriteStringReference(defn.GrannyName);
     WriteStructReference(defn.WriteDefinition);
     Writer.Write(defn.ArraySize);
     for (var i = 0; i < MemberDefinition.ExtraTagCount; i++)
         Writer.Write(defn.Extra[i]);
     if (GR2.Magic.Is32Bit)
         Writer.Write(defn.Unknown);
     else
         Writer.Write((UInt64)defn.Unknown);
 }
Exemplo n.º 43
0
 public void Write(GR2Writer writer, WritableSection section, MemberDefinition member, object obj)
 {
     (obj as Vertex).Serialize(section);
 }
Exemplo n.º 44
0
        public MemberDefinition ReadMemberDefinition()
        {
#if DEBUG_GR2_SERIALIZATION
            var defnOffset = Stream.Position;
#endif
            var defn = new MemberDefinition();
            int typeId = Reader.ReadInt32();
            if (typeId > (uint)MemberType.Max)
                throw new ParsingException(String.Format("Unsupported member type: {0}", typeId));

            defn.Type = (MemberType)typeId;
            var name = ReadStringReference();
            Debug.Assert(!defn.IsValid || name.IsValid);
            if (defn.IsValid)
            {
                defn.Name = name.Resolve(this);
                defn.GrannyName = defn.Name;
            }
            defn.Definition = ReadStructReference();
            defn.ArraySize = Reader.ReadUInt32();
            defn.Extra = new UInt32[MemberDefinition.ExtraTagCount];
            for (var i = 0; i < MemberDefinition.ExtraTagCount; i++)
                defn.Extra[i] = Reader.ReadUInt32();
            // TODO 64-bit: ???
            if (Magic.Is32Bit)
                defn.Unknown = Reader.ReadUInt32();
            else
                defn.Unknown = (UInt32)Reader.ReadUInt64();

            Debug.Assert(defn.Unknown == 0);

            if (defn.Type == MemberType.Inline || defn.Type == MemberType.Reference || defn.Type == MemberType.ArrayOfReferences ||
                defn.Type == MemberType.ReferenceToArray)
                Debug.Assert(defn.Definition.IsValid);

#if DEBUG_GR2_SERIALIZATION
            string description;
            if (defn.IsValid)
            {
                if (defn.ArraySize != 0)
                    description = String.Format("    [{0:X8}] {1}: {2}[{3}]", defnOffset, defn.Name, defn.Type.ToString(), defn.ArraySize);
                else
                    description = String.Format("    [{0:X8}] {1}: {2}", defnOffset, defn.Name, defn.Type.ToString());

                if (defn.Definition.IsValid)
                {
                    if (!DebugPendingResolve.Contains(defn.Definition))
                    {
                        DebugPendingResolve.Add(defn.Definition);
                        System.Console.WriteLine(String.Format(" ===== Debug resolve for {0:X8} ===== ", defn.Definition.Offset));
                        defn.Definition.Resolve(this);
                        System.Console.WriteLine(String.Format(" ===== End debug resolve for {0:X8} ===== ", defn.Definition.Offset));
                    }
                    description += String.Format(" <struct {0:X8}>", defn.Definition.Offset);
                }

                if (defn.Extra[0] != 0 || defn.Extra[1] != 0 || defn.Extra[2] != 0)
                    description += String.Format(" Extra: {0} {1} {2}", defn.Extra[0], defn.Extra[1], defn.Extra[2]);
            }
            else
            {
                description = String.Format("    <invalid>: {0}", defn.Type.ToString());
            }

            System.Console.WriteLine(description);
#endif
            return defn;
        }
Exemplo n.º 45
0
 public void Write(GR2Writer writer, WritableSection section, MemberDefinition member, object obj)
 {
     var items = obj as List<UInt16>;
     for (int i = 0; i < items.Count; i++)
         section.Writer.Write(items[i]);
 }
Exemplo n.º 46
0
        internal void QueueStructWrite(SectionType section, bool dataArea, MemberDefinition member, Type type, object obj)
        {
            QueuedSerialization serialization;
            serialization.section = section;
            serialization.dataArea = dataArea;
            if (member.PreferredSection != SectionType.Invalid)
                serialization.section = member.PreferredSection;
            else if (member.SectionSelector != null)
                serialization.section = member.SectionSelector.SelectSection(member, type, obj);
            serialization.type = type;
            serialization.member = member;
            serialization.obj = obj;

            Sections[(int)serialization.section].CheckMixedMarshalling(obj, type, 1);
            StructWrites.Add(serialization);
        }
Exemplo n.º 47
0
        public SectionType SelectSection(MemberDefinition member, Type type, object obj)
        {
            var vertices = obj as System.Collections.IList;
            if (vertices == null || vertices.Count == 0)
                return SectionType.RigidVertex;

            if (Vertex.Description(vertices[0].GetType()).BoneWeights)
                return SectionType.DeformableVertex;
            else
                return SectionType.RigidVertex;
        }
Exemplo n.º 48
0
        internal object ReadInstance(MemberDefinition definition, object node, Type propertyType, object parent)
        {
            if (definition.SerializationKind == SerializationKind.UserRaw)
                return definition.Serializer.Read(this, null, definition, 0, parent);

            if (definition.ArraySize == 0)
            {
                return ReadElement(definition, node, propertyType, parent);
            }

            Type elementType = null;
            if (propertyType != null)
            {
                if (definition.SerializationKind == SerializationKind.UserMember)
                {
                    // Do unserialization directly on the whole array if per-member serialization was requested.
                    // This mode is a bit odd, as we resolve StructRef-s for non-arrays, but don't for array types.
                    StructDefinition defn = null;
                    if (definition.Definition.IsValid)
                        defn = definition.Definition.Resolve(this);
                    return definition.Serializer.Read(this, defn, definition, definition.ArraySize, parent);
                }
                else if (propertyType.IsArray)
                {
                    // If the property is a native array (ie. SomeType[]), create an array instance and set its values
                    elementType = propertyType.GetElementType();

                    Array objs = Helpers.CreateArrayInstance(propertyType, (int)definition.ArraySize) as Array;
                    for (int i = 0; i < definition.ArraySize; i++)
                    {
                        objs.SetValue(ReadElement(definition, objs.GetValue(i), elementType, parent), i);
                    }
                    return objs;
                }
                else
                {
                    // For non-native arrays we always assume the property is an IList<T>
                    if (node == null)
                        node = Helpers.CreateInstance(propertyType);

                    var items = node as System.Collections.IList;
                    var type = items.GetType().GetGenericArguments().Single();
                    for (int i = 0; i < definition.ArraySize; i++)
                    {
                        items.Add(ReadElement(definition, null, elementType, parent));
                    }

                    return items;
                }
            }
            else
            {
                for (int i = 0; i < definition.ArraySize; i++)
                    ReadElement(definition, null, null, parent);
                return null;
            }
        }
Exemplo n.º 49
0
 public MemberResolveResult(MemberDefinition member)
     : base(member == null ? null : (member is TypeDefinition ? (TypeDefinition)member : member.MemberType))
 {
     Member = member;
 }
Exemplo n.º 50
0
        public Type SelectType(MemberDefinition member, object node)
        {
            var list = node as System.Collections.IList;
            if (list == null || list.Count == 0)
                return null;

            return (list[0] as Vertex).Prototype();
        }