private void InspectFields(FieldDefinitionHandleCollection fields)
        {
            foreach (var fieldHandle in fields)
            {
                var inspectorField = new InspectorField();

                var fieldDef = metaReader.GetFieldDefinition(fieldHandle);

                var customAttr = fieldDef.GetCustomAttributes();

                foreach (var caHandle in customAttr)
                {
                    // Look for InspectorAttribute
                    if (DecodeCustomAttribute(caHandle, inspectorField))
                    {
                        BlobReader      sigReader = metaReader.GetBlobReader(fieldDef.Signature);
                        SignatureHeader header    = sigReader.ReadSignatureHeader();

                        if (header.Kind != SignatureKind.Field)
                        {
                            continue;
                        }

                        var typeCode = sigReader.ReadSignatureTypeCode();

                        string typeName = typeCode.ToString();

                        if (typeCode == SignatureTypeCode.SZArray)
                        {
                            inspectorField.IsArray = true;
                            SignatureTypeCode code = sigReader.ReadSignatureTypeCode();

                            if (code == SignatureTypeCode.TypeHandle)
                            {
                                bool isEnum;
                                DecodeTypeHandleTypeName(sigReader, out typeName, out isEnum);
                            }
                            else
                            {
                                typeName = code.ToString();
                            }
                        }
                        else if (typeCode == SignatureTypeCode.TypeHandle)
                        {
                            bool isEnum;
                            DecodeTypeHandleTypeName(sigReader, out typeName, out isEnum);
                            inspectorField.IsEnum = isEnum;
                        }

                        inspectorField.TypeName = typeName;
                        inspectorField.Name     = metaReader.GetString(fieldDef.Name);
                        _inspectorComponent.Fields[inspectorField.Name] = inspectorField;

                        break;
                    }
                }
            }
        }
Exemple #2
0
        public SignatureType(ref BlobReader signatureReader, MetadataReader mdReader, GenericParameterHandleCollection genericParams)
        {
            SignatureTypeCode signatureTypeCode = signatureReader.ReadSignatureTypeCode();

            Flags = 0;
            if (signatureTypeCode == SignatureTypeCode.SZArray)
            {
                Flags            |= SignatureTypeFlags.ARRAY;
                signatureTypeCode = signatureReader.ReadSignatureTypeCode();
            }

            TypeName = signatureTypeCode.ToString();
            if (signatureTypeCode == SignatureTypeCode.TypeHandle || signatureTypeCode == SignatureTypeCode.ByReference)
            {
                if (signatureTypeCode == SignatureTypeCode.ByReference)
                {
                    Flags |= SignatureTypeFlags.REFERENCE;
                }

                EntityHandle handle = signatureReader.ReadTypeHandle();
                if (handle.Kind == HandleKind.TypeDefinition)
                {
                    TypeDefinition typeDef = mdReader.GetTypeDefinition((TypeDefinitionHandle)handle);
                    TypeName = mdReader.GetString(typeDef.Name);
                }
                else if (handle.Kind == HandleKind.TypeReference)
                {
                    TypeReference typeRef = mdReader.GetTypeReference((TypeReferenceHandle)handle);
                    TypeName = mdReader.GetString(typeRef.Name);
                }
            }
            else if (signatureTypeCode == SignatureTypeCode.GenericMethodParameter)
            {
                int index = signatureReader.ReadCompressedInteger();
                GenericParameter generic = mdReader.GetGenericParameter(genericParams[index]);
                TypeName = mdReader.GetString(generic.Name);
                Flags   |= SignatureTypeFlags.GENERIC;
            }
        }
Exemple #3
0
 public SignatureType(ref BlobReader signatureReader, ref MetadataReader mdReader)
 {
     SignatureTypeCode = signatureReader.ReadSignatureTypeCode();
     IsArray           = (SignatureTypeCode == SignatureTypeCode.SZArray);
     if (IsArray)
     {
         SignatureTypeCode = signatureReader.ReadSignatureTypeCode();
     }
     ClassName = SignatureTypeCode.ToString();
     if (SignatureTypeCode == SignatureTypeCode.TypeHandle || SignatureTypeCode == SignatureTypeCode.ByReference)
     {
         EntityHandle handle = signatureReader.ReadTypeHandle();
         if (handle.Kind == HandleKind.TypeDefinition)
         {
             var typeDef = mdReader.GetTypeDefinition((TypeDefinitionHandle)handle);
             ClassName = mdReader.GetString(typeDef.Name);
         }
         else if (handle.Kind == HandleKind.TypeReference)
         {
             var typeRef = mdReader.GetTypeReference((TypeReferenceHandle)handle);
             ClassName = mdReader.GetString(typeRef.Name);
         }
     }
 }