/// <summary>
        /// Allocates memory for the static field and initializes it.
        /// </summary>
        /// <param name="field">The field.</param>
        private void CreateStaticField(RuntimeField field)
        {
            Debug.Assert(field != null, @"No field given.");

            // Determine the size of the type & alignment requirements
            int size, alignment;

            architecture.GetTypeRequirements(field.SignatureType, out size, out alignment);

            size = (int)typeLayout.GetFieldSize(field);

            // The linker section to move this field into
            SectionKind section;

            // Does this field have an RVA?
            if (field.RVA != 0)
            {
                // FIXME: Move a static field into ROData, if it is read-only and can be initialized
                // using static analysis
                section = SectionKind.Data;
            }
            else
            {
                section = SectionKind.BSS;
            }

            this.AllocateSpace(field, section, size, alignment);
        }
Beispiel #2
0
        /// <summary>
        /// Allocates memory for the static field and initializes it.
        /// </summary>
        /// <param name="field">The field.</param>
        private void CreateStaticField(RuntimeField field)
        {
            Debug.Assert(field != null, "No field given.");

            // Determine the size of the type & alignment requirements
            int size, alignment;

            _architecture.GetTypeRequirements(field.Type, out size, out alignment);

            // Retrieve the linker
            IAssemblyLinker linker = _compiler.Pipeline.Find <IAssemblyLinker> ();
            // The linker section to move this field into
            SectionKind section;

            // Does this field have an RVA?
            if (IntPtr.Zero != field.RVA)
            {
                // FIXME: Move a static field into ROData, if it is read-only and can be initialized
                // using static analysis
                section = SectionKind.Data;
            }
            else
            {
                section = SectionKind.BSS;
            }

            AllocateSpace(linker, field, section, size, alignment);
        }
        /// <summary>
        /// Initializes a new instance of <see cref="MemberOperand"/>.
        /// </summary>
        /// <param name="field">The runtime field to reference.</param>
        /// <exception cref="System.ArgumentNullException"><paramref name="field"/> is null.</exception>
        public MemberOperand(RuntimeField field)
            : base(field.Type, null, IntPtr.Zero)
        {
            if (field == null)
                throw new ArgumentNullException(@"field");

            this.member = field;
        }
Beispiel #4
0
        /// <summary>
        /// Create a new field.
        /// </summary>
        /// <param name="name">The name of the field to create.</param>
        /// <returns>The field that was created.</returns>
        RuntimeField CreateField(string name)
        {
            var field = new RuntimeField(_contract, name);

            _fields.Add(field);

            return(field);
        }
 /// <summary>
 /// Indicates whether the current object is equal to another object of the same type.
 /// </summary>
 /// <param name="other">An object to compare with this object.</param>
 /// <returns>
 /// true if the current object is equal to the <paramref name="other"/> parameter; otherwise, false.
 /// </returns>
 public override bool Equals(RuntimeField other)
 {
     CilRuntimeField crf = other as CilRuntimeField;
     return (crf != null &&
             this.nameIdx == crf.nameIdx &&
             this.signatureBlobIdx == crf.signatureBlobIdx &&
             base.Equals(other) == true);
 }
 private void InitializeStaticValueFromRVA(Stream stream, int size, RuntimeField field)
 {
     using (Stream source = field.Module.MetadataModule.GetDataSection((long)field.RVA))
     {
         byte[] data = new byte[size];
         source.Read(data, 0, size);
         stream.Write(data, 0, size);
     }
 }
Beispiel #7
0
 private void InitializeStaticValueFromRVA(Stream stream, int size, RuntimeField field)
 {
     using (Stream source = _compiler.Assembly.GetDataSection(field.RVA.ToInt64()))
     {
         byte[] data = new byte[size];
         source.Read(data, 0, size);
         stream.Write(data, 0, size);
     }
 }
Beispiel #8
0
        /// <summary>
        /// Constructor.
        /// </summary>
        /// <param name="builder">The parent builder.</param>
        /// <param name="field">The field to build on.</param>
        internal FieldBuilder(IContractBuilder <T> builder, RuntimeField field) : base(builder)
        {
            Instance = field;

            if (Instance.Accessor == null)
            {
                Instance.Accessor = RuntimeFieldAccessor.From <T>(Instance.Name);
            }
        }
Beispiel #9
0
        public CilRuntimeField(RuntimeField genericField, IMetadataModule module, FieldSignature signature)
            : base(module, genericField.DeclaringType)
        {
            this.Name = genericField.Name;
            this.Attributes = genericField.Attributes;
            this.RVA = genericField.RVA;
            this.Signature = signature;

            this.SetAttributes(genericField.CustomAttributes);
        }
Beispiel #10
0
        /// <summary>
        /// Initializes a new instance of the <see cref="CilGenericField"/> class.
        /// </summary>
        /// <param name="module">The module.</param>
        /// <param name="genericField">The generic field.</param>
        /// <param name="signature">The signature.</param>
        /// <param name="declaringType">Type of the declaring.</param>
        public CilGenericField(ITypeModule module, RuntimeField genericField, FieldSignature signature, CilGenericType declaringType)
            : base(module, declaringType)
        {
            this.Signature = signature;
            this.Attributes = genericField.Attributes;
            //TODO
            //this.SetAttributes(genericField.CustomAttributes);

            base.Name = genericField.Name;
        }
 /// <summary>
 /// Discover the property from the given type.
 /// </summary>
 /// <typeparam name="TEntity">The entity type.</typeparam>
 /// <param name="builder">The parent builder to add to.</param>
 /// <param name="type">The type to discover the properties from.</param>
 void Discover <TEntity>(ContractBuilder <TEntity> builder, TypeInfo type)
 {
     foreach (var property in _fieldDiscovery.Discover(type))
     {
         builder
         .Field(property.Name)
         .Accessor(new RuntimeFieldAccessor(property))
         .Options(RuntimeField.CreateDefaultOptions(property));
     }
 }
        public CilGenericField(IModuleTypeSystem moduleTypeSystem, RuntimeField genericField, FieldSignature signature, CilGenericType declaringType)
            : base(moduleTypeSystem, declaringType)
        {
            this.Signature = signature;
            this.genericField = genericField;
            this.Attributes = genericField.Attributes;
            this.SetAttributes(genericField.CustomAttributes);

            return;
        }
Beispiel #13
0
        /// <summary>
        /// Initializes a new instance of <see cref="MemberOperand"/>.
        /// </summary>
        /// <param name="field">The runtime field to reference.</param>
        /// <exception cref="System.ArgumentNullException"><paramref name="field"/> is null.</exception>
        public MemberOperand(RuntimeField field) :
            base(field.Type, null, IntPtr.Zero)
        {
            if (field == null)
            {
                throw new ArgumentNullException(@"field");
            }

            this.member = field;
        }
        public CilRuntimeField(IModuleTypeSystem moduleTypeSystem, RuntimeField genericField, FieldSignature signature)
            : base(moduleTypeSystem, genericField.DeclaringType)
        {
            this.Name = genericField.Name;
            this.Attributes = genericField.Attributes;
            this.RVA = genericField.RVA;
            this.Signature = signature;

            this.SetAttributes(genericField.CustomAttributes);
        }
Beispiel #15
0
        /// <summary>
        /// Initializes a new instance of the <see cref="CilGenericField"/> class.
        /// </summary>
        /// <param name="module">The module.</param>
        /// <param name="genericField">The generic field.</param>
        /// <param name="signature">The signature.</param>
        /// <param name="declaringType">Type of the declaring.</param>
        public CilGenericField(ITypeModule module, RuntimeField genericField, FieldSignature signature, CilGenericType declaringType) :
            base(module, declaringType)
        {
            this.Signature  = signature;
            this.Attributes = genericField.Attributes;
            //TODO
            //this.SetAttributes(genericField.CustomAttributes);

            base.Name = genericField.Name;
        }
Beispiel #16
0
        public CilGenericField(RuntimeType declaringType, RuntimeField genericField, FieldSignature signature)
            : base(declaringType.Module, declaringType)
        {
            this.genericField = genericField;
            this.Signature = signature;

            // FIXME: RVA, Address of these?
            this.Attributes = genericField.Attributes;
            this.SetAttributes(genericField.CustomAttributes);
        }
Beispiel #17
0
 private void AllocateSpace(IAssemblyLinker linker, RuntimeField field, SectionKind section, int size, int alignment)
 {
     using (Stream stream = linker.Allocate(field, section, size, alignment))
     {
         if (IntPtr.Zero != field.RVA)
         {
             InitializeStaticValueFromRVA(stream, size, field);
         }
         else
         {
             WriteDummyBytes(stream, size);
         }
     }
 }
 private void AllocateSpace(RuntimeField field, SectionKind section, int size, int alignment)
 {
     using (Stream stream = linker.Allocate(field.ToString(), section, size, alignment))
     {
         if (field.RVA != 0)
         {
             InitializeStaticValueFromRVA(stream, size, field);
         }
         else
         {
             WriteDummyBytes(stream, size);
         }
     }
 }
Beispiel #19
0
        /// <summary>
        /// Discover the property from the given type.
        /// </summary>
        /// <typeparam name="TEntity">The entity type.</typeparam>
        /// <param name="builder">The parent builder to add to.</param>
        /// <param name="type">The type to discover the properties from.</param>
        static void Discover <TEntity>(ContractBuilder <TEntity> builder, TypeInfo type)
        {
            foreach (var property in type.DeclaredProperties)
            {
                builder
                .Field(property.Name)
                .Accessor(new RuntimeFieldAccessor(property))
                .Options(RuntimeField.CreateDefaultOptions(property));
            }

            if (type.BaseType != null && type.BaseType != typeof(object))
            {
                Discover(builder, type.BaseType.GetTypeInfo());
            }
        }
Beispiel #20
0
        /// <summary>
        /// Allocates memory for the static field and initializes it.
        /// </summary>
        /// <param name="field">The field.</param>
        private void CreateStaticField(RuntimeField field)
        {
            Debug.Assert (field != null, "No field given.");

            // Determine the size of the type & alignment requirements
            int size, alignment;
            _architecture.GetTypeRequirements (field.Type, out size, out alignment);

            // Retrieve the linker
            IAssemblyLinker linker = _compiler.Pipeline.Find<IAssemblyLinker> ();
            // The linker section to move this field into
            SectionKind section;
            // Does this field have an RVA?
            if (IntPtr.Zero != field.RVA)
            {
                // FIXME: Move a static field into ROData, if it is read-only and can be initialized
                // using static analysis
                section = SectionKind.Data;
            } else
            {
                section = SectionKind.BSS;
            }

            AllocateSpace (linker, field, section, size, alignment);
        }
Beispiel #21
0
 private void InitializeStaticValueFromRVA(Stream stream, int size, RuntimeField field)
 {
     using (Stream source = _compiler.Assembly.GetDataSection (field.RVA.ToInt64 ()))
     {
         byte[] data = new byte[size];
         source.Read (data, 0, size);
         stream.Write (data, 0, size);
     }
 }
Beispiel #22
0
 /// <summary>
 /// Initializes a new instance of the <see cref="ObjectFieldOperand"/> class.
 /// </summary>
 /// <param name="objectInstance">The operand, representing the object instance.</param>
 /// <param name="field">The referenced field.</param>
 public ObjectFieldOperand(Operand objectInstance, RuntimeField field) :
     base(field.Type, null, field.Address)
 {
 }
Beispiel #23
0
 private void AllocateSpace(IAssemblyLinker linker, RuntimeField field, SectionKind section, int size, int alignment)
 {
     using (Stream stream = linker.Allocate (field, section, size, alignment))
     {
         if (IntPtr.Zero != field.RVA)
             InitializeStaticValueFromRVA (stream, size, field);
         else
             WriteDummyBytes (stream, size);
     }
 }
Beispiel #24
0
 /// <summary>
 /// Initializes a new instance of the <see cref="StaticFieldOperand"/> class.
 /// </summary>
 /// <param name="field">The field.</param>
 public StaticFieldOperand(RuntimeField field, IntPtr offset) :
     base(field.SignatureType, null, offset)             /* field.Address */
 {
 }
 /// <summary>
 /// Initializes a new instance of the <see cref="ObjectFieldOperand"/> class.
 /// </summary>
 /// <param name="objectInstance">The operand, representing the object instance.</param>
 /// <param name="field">The referenced field.</param>
 public ObjectFieldOperand(Operand objectInstance, RuntimeField field)
     : base(field.SignatureType, null, field.Address)
 {
 }
        /// <summary>
        /// Allocates memory for the static field and initializes it.
        /// </summary>
        /// <param name="field">The field.</param>
        private void CreateStaticField(RuntimeField field)
        {
            Debug.Assert(field != null, @"No field given.");

            // Determine the size of the type & alignment requirements
            int size, alignment;
            _architecture.GetTypeRequirements(field.Type, out size, out alignment);

            if (field.Type.Type == CilElementType.ValueType)
            {
                size = ObjectModelUtility.ComputeTypeSize((field.Type as Metadata.Signatures.ValueTypeSigType).Token, _compiler.Metadata, _architecture);
            }

            // Retrieve the linker
            IAssemblyLinker linker = _compiler.Pipeline.FindFirst<IAssemblyLinker>();
            // The linker section to move this field into
            SectionKind section;
            // Does this field have an RVA?
            if (IntPtr.Zero != field.RVA) {
                // FIXME: Move a static field into ROData, if it is read-only and can be initialized
                // using static analysis
                section = SectionKind.Data;
            }
            else {
                section = SectionKind.BSS;
            }

            AllocateSpace(linker, field, section, size, alignment);
        }
        int ITypeLayout.GetFieldSize(RuntimeField field)
        {
            // If the field is another struct, we have to dig down and compute its size too.
            if (field.SignatureType.Type == CilElementType.ValueType)
            {
                return ((ITypeLayout)this).GetTypeSize(field.DeclaringType);
            }

            int size, alignment;
            architecture.GetTypeRequirements(field.SignatureType, out size, out alignment);

            return size;
        }
 private void InitializeStaticValueFromRVA(Stream stream, int size, RuntimeField field)
 {
     using (Stream source = field.MetadataModule.GetDataSection((long)field.RVA))
     {
         byte[] data = new byte[size];
         source.Read(data, 0, size);
         stream.Write(data, 0, size);
     }
 }
Beispiel #29
0
 /// <summary>
 /// Creates a new SymbolOperand for the given runtime field.
 /// </summary>
 /// <param name="runtimeField">The field to create a symbol operand for.</param>
 /// <returns>The created symbol operand.</returns>
 public static SymbolOperand FromField(RuntimeField runtimeField)
 {
     return(new SymbolOperand(runtimeField.SignatureType, runtimeField.ToString()));
 }
Beispiel #30
0
 /// <summary>
 /// Initializes a new instance of the <see cref="ObjectFieldOperand"/> class.
 /// </summary>
 /// <param name="objectInstance">The operand, representing the object instance.</param>
 /// <param name="field">The referenced field.</param>
 public ObjectFieldOperand(Operand objectInstance, RuntimeField field, IntPtr offset) :
     base(field.SignatureType, null, offset)             /* field.Address */
 {
 }
Beispiel #31
0
        public static void RefactorVariable(VariableData variable, string name, UnityEngine.Object owner)
        {
            bool      isLocal = false;
            uNodeRoot graph   = owner as uNodeRoot;

            if (graph == null)
            {
                INode <uNodeRoot> node = owner as INode <uNodeRoot>;
                if (node != null)
                {
                    graph   = node.GetOwner();
                    isLocal = true;
                }
            }
            if (graph != null)
            {
                HashSet <GameObject> referencedGraphs = new HashSet <GameObject>();
                if (!isLocal)
                {
                    RuntimeField field = null;
                    if (graph is IIndependentGraph)
                    {
                        if (GraphUtility.IsTempGraphObject(graph.gameObject))
                        {
                            var prefab = uNodeEditorUtility.GetGameObjectSource(graph.gameObject, null);
                            if (prefab != null)
                            {
                                var oriGraph = prefab.GetComponent <uNodeRoot>();
                                if (oriGraph != null)
                                {
                                    field = ReflectionUtils.GetRuntimeType(oriGraph).GetField(variable.Name) as RuntimeField;
                                }
                            }
                        }
                        else
                        {
                            field = ReflectionUtils.GetRuntimeType(graph).GetField(variable.Name) as RuntimeField;
                        }
                    }
                    FieldInfo nativeMember = null;
                    if (graph.GeneratedTypeName.ToType(false) != null)
                    {
                        var type = graph.GeneratedTypeName.ToType(false);
                        nativeMember = type.GetField(variable.Name, MemberData.flags);
                    }
                    var graphPrefabs = uNodeEditorUtility.FindPrefabsOfType <uNodeRoot>();
                    foreach (var prefab in graphPrefabs)
                    {
                        var        gameObject    = prefab;
                        GameObject prefabContent = null;
                        if (GraphUtility.HasTempGraphObject(prefab))
                        {
                            gameObject = GraphUtility.GetTempGraphObject(prefab);
                        }
                        else if (uNodeEditorUtility.IsPrefab(prefab))
                        {
                            prefabContent = PrefabUtility.LoadPrefabContents(AssetDatabase.GetAssetPath(prefab));
                            gameObject    = prefabContent;
                        }
                        var  scripts = gameObject.GetComponentsInChildren <MonoBehaviour>(true);
                        bool hasUndo = false;
                        Func <object, bool> scriptValidation = (obj) => {
                            MemberData member = obj as MemberData;
                            if (member != null)
                            {
                                var members = member.GetMembers(false);
                                if (members != null)
                                {
                                    for (int i = 0; i < members.Length; i++)
                                    {
                                        var m = members[i];
                                        if (member.namePath.Length > i + 1)
                                        {
                                            if (m == field || m == nativeMember)
                                            {
                                                if (!hasUndo && prefabContent == null)
                                                {
                                                    uNodeEditorUtility.RegisterFullHierarchyUndo(gameObject, "Rename Variable: " + variable.Name);
                                                    hasUndo = true;
                                                }
                                                var path = member.namePath;
                                                path[i + 1] = name;
                                                member.name = string.Join(".", path);
                                                if (m == nativeMember)
                                                {
                                                    referencedGraphs.Add(prefab);
                                                }
                                                return(true);
                                            }
                                        }
                                    }
                                }
                            }
                            return(false);
                        };
                        if (field != null || nativeMember != null)
                        {
                            bool hasChanged = false;
                            Array.ForEach(scripts, script => {
                                bool flag = AnalizerUtility.AnalizeObject(script, scriptValidation);
                                if (flag)
                                {
                                    hasChanged = true;
                                    hasUndo    = false;
                                    uNodeGUIUtility.GUIChanged(script);
                                    uNodeEditorUtility.MarkDirty(script);
                                }
                            });
                            if (hasChanged)
                            {
                                if (gameObject != prefab)
                                {
                                    uNodeEditorUtility.RegisterFullHierarchyUndo(prefab, "Rename Variable: " + variable.Name);
                                    if (prefabContent == null)
                                    {
                                        //Save the temporary graph
                                        GraphUtility.AutoSaveGraph(gameObject);
                                    }
                                    else
                                    {
                                        //Save the prefab contents
                                        uNodeEditorUtility.SavePrefabAsset(gameObject, prefab);
                                    }
                                }
                                uNodeEditorUtility.MarkDirty(prefab);
                            }
                        }
                        if (prefabContent != null)
                        {
                            PrefabUtility.UnloadPrefabContents(prefabContent);
                        }
                    }
                }
                string oldVarName = variable.Name;
                variable.Name = name;
                Func <object, bool> validation = delegate(object OBJ) {
                    return(CallbackRenameVariable(OBJ, owner, variable.Name, oldVarName));
                };
                graph.Refresh();
                Array.ForEach(graph.nodes, item => AnalizerUtility.AnalizeObject(item, validation));
                if (GraphUtility.IsTempGraphObject(graph.gameObject))
                {
                    var prefab = uNodeEditorUtility.GetGameObjectSource(graph.gameObject, null);
                    uNodeEditorUtility.RegisterFullHierarchyUndo(prefab, "Rename Variable: " + oldVarName);
                    GraphUtility.AutoSaveGraph(graph.gameObject);
                }
                uNodeEditor.ClearGraphCache();
                uNodeEditor.window?.Refresh(true);
                DoCompileReferences(graph, referencedGraphs);
            }
        }
 /// <summary>
 /// Initializes a new instance of the <see cref="StaticFieldOperand"/> class.
 /// </summary>
 /// <param name="field">The field.</param>
 public StaticFieldOperand(RuntimeField field)
     : base(field.SignatureType, null, field.Address)
 {
 }
 private void AllocateSpace(RuntimeField field, SectionKind section, int size, int alignment)
 {
     using (Stream stream = linker.Allocate(field.ToString(), section, size, alignment))
     {
         if (field.RVA != 0)
         {
             InitializeStaticValueFromRVA(stream, size, field);
         }
         else
         {
             WriteDummyBytes(stream, size);
         }
     }
 }
 /// <summary>
 /// Constructor.
 /// </summary>
 /// <param name="builder">The parent builder.</param>
 /// <param name="field">The field to build on.</param>
 internal FieldDeserializationBuilder(FieldBuilder <T> builder, RuntimeField field) : base(builder, field)
 {
 }
Beispiel #35
0
        /// <summary>
        /// Attempt to find the field with the given name.
        /// </summary>
        /// <param name="name">The name of the field to find.</param>
        /// <param name="field">The field that was found with the given name, or null if not field could be found.</param>
        /// <returns>true if a field with the given name was found, false if not.</returns>
        bool TryFindField(string name, out RuntimeField field)
        {
            field = _fields.SingleOrDefault(f => String.Equals(f.Name, name, StringComparison.OrdinalIgnoreCase));

            return(field != null);
        }
 /// <summary>
 /// Creates a new SymbolOperand for the given runtime field.
 /// </summary>
 /// <param name="runtimeField">The field to create a symbol operand for.</param>
 /// <returns>The created symbol operand.</returns>
 public static SymbolOperand FromField(RuntimeField runtimeField)
 {
     return new SymbolOperand(runtimeField.SignatureType, runtimeField.ToString());
 }
Beispiel #37
0
 /// <summary>
 /// Initializes a new instance of the <see cref="StaticFieldOperand"/> class.
 /// </summary>
 /// <param name="field">The field.</param>
 public StaticFieldOperand(RuntimeField field) :
     base(field.Type, null, field.Address)
 {
 }
        /// <summary>
        /// Allocates memory for the static field and initializes it.
        /// </summary>
        /// <param name="field">The field.</param>
        private void CreateStaticField(RuntimeField field)
        {
            Debug.Assert(field != null, @"No field given.");

            // Determine the size of the type & alignment requirements
            int size, alignment;
            architecture.GetTypeRequirements(field.SignatureType, out size, out alignment);

            size = (int)((ITypeLayout)this).GetFieldSize(field);

            // The linker section to move this field into
            SectionKind section;
            // Does this field have an RVA?
            if (field.RVA != 0)
            {
                // FIXME: Move a static field into ROData, if it is read-only and can be initialized
                // using static analysis
                section = SectionKind.Data;
            }
            else
            {
                section = SectionKind.BSS;
            }

            this.AllocateSpace(field, section, size, alignment);
        }
Beispiel #39
0
        /// <summary>
        /// Parses an elementary field, parameter or property definition.
        /// </summary>
        /// <param name="module">The metadata module, which contains the attribute blob.</param>
        /// <param name="reader">The binary reader to read data From.</param>
        /// <param name="sigType">The signature type of the field, parameter or property to read.</param>
        /// <returns>An object, which represents the value read From the attribute blob.</returns>
        /// <exception cref="System.NotSupportedException"><paramref name="sigType"/> is not yet supported.</exception>
        private static object ParseElem(IMetadataModule module, BinaryReader reader, SigType sigType)
        {
            object result;

            switch (sigType.Type)
            {
            case CilElementType.Boolean:
                result = (1 == reader.ReadByte());
                break;

            case CilElementType.Char:
                result = (char)reader.ReadUInt16();
                break;

            case CilElementType.I1:
                result = reader.ReadSByte();
                break;

            case CilElementType.I2:
                result = reader.ReadInt16();
                break;

            case CilElementType.I4:
                result = reader.ReadInt32();
                break;

            case CilElementType.I8:
                result = reader.ReadInt64();
                break;

            case CilElementType.U1:
                result = reader.ReadByte();
                break;

            case CilElementType.U2:
                result = reader.ReadUInt16();
                break;

            case CilElementType.U4:
                result = reader.ReadUInt32();
                break;

            case CilElementType.U8:
                result = reader.ReadUInt64();
                break;

            case CilElementType.R4:
                result = reader.ReadSingle();
                break;

            case CilElementType.R8:
                result = reader.ReadDouble();
                break;

            case CilElementType.String:
                result = ParseSerString(reader);
                break;

            case CilElementType.Type:

            {
                string typeName = ParseSerString(reader);
                result = Type.GetType(typeName);
            }

            break;

            case CilElementType.Class:

            {
                string   typeName = ParseSerString(reader);
                string[] type     = typeName.Split(',');
                if (type.Length > 1)
                {
                    result = Type.GetType(typeName);
                }
                else
                {
                    result = Type.GetType(typeName + ", " + module.Name);
                }
            }

            break;

            case CilElementType.ValueType:

            {
                ValueTypeSigType vtSigType = sigType as ValueTypeSigType;
                ITypeSystem      ts        = RuntimeBase.Instance.TypeLoader;
                RuntimeType      type      = ts.GetType(module, vtSigType.Token);
                RuntimeType      baseType  = type.BaseType;
                if ("System" == baseType.Namespace && "Enum" == baseType.Name)
                {
                    // Retrieve the value__ field to get the enums integer type
                    Debug.Assert(type.Fields.Count == 1, "More than one field in the enum.");
                    RuntimeField value = type.Fields[0];
                    Debug.Assert(value.Name == "value__", "First field of enum not named value__");
                    result = ParseElem(module, reader, value.Type);
                    Type enumType = Type.GetType(type.Namespace + "." + type.Name);
                    result = Enum.ToObject(enumType, result);
                }
                else
                {
                    throw new NotSupportedException();
                }
            }

            break;

            case CilElementType.Object:
                throw new NotSupportedException();

            default:

                throw new NotSupportedException();
            }

            return(result);
        }
Beispiel #40
0
        /// <summary>
        /// Indicates whether the current object is equal to another object of the same type.
        /// </summary>
        /// <param name="other">An object to compare with this object.</param>
        /// <returns>
        /// true if the current object is equal to the <paramref name="other"/> parameter; otherwise, false.
        /// </returns>
        public override bool Equals(RuntimeField other)
        {
            CilRuntimeField crf = other as CilRuntimeField;

            return(crf != null && this.nameIdx == crf.nameIdx && this.signature == crf.signature && base.Equals(other) == true);
        }