예제 #1
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(SigType other)
        {
            ValueTypeSigType vtst = other as ValueTypeSigType;

            if (vtst == null)
            {
                return(false);
            }

            return(base.Equals(other) == true && _token == vtst._token);
        }
예제 #2
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);
        }