コード例 #1
0
ファイル: SignatureUtil.cs プロジェクト: radtek/Shopdrawing
 internal static void ExtractCustomAttributeArgumentType(ITypeUniverse universe, Module module, byte[] customAttributeBlob, ref int index, out System.Reflection.Adds.CorElementType argumentTypeId, out Type argumentType)
 {
     argumentTypeId = SignatureUtil.ExtractElementType(customAttributeBlob, ref index);
     SignatureUtil.VerifyElementType((System.Reflection.Adds.CorElementType)((int)argumentTypeId));
     if ((int)argumentTypeId == 29)
     {
         System.Reflection.Adds.CorElementType corElementType = SignatureUtil.ExtractElementType(customAttributeBlob, ref index);
         SignatureUtil.VerifyElementType(corElementType);
         if (corElementType == (System.Reflection.Adds.CorElementType.Byref | System.Reflection.Adds.CorElementType.Modifier | System.Reflection.Adds.CorElementType.Sentinel | System.Reflection.Adds.CorElementType.ValueType | System.Reflection.Adds.CorElementType.Void | System.Reflection.Adds.CorElementType.Type))
         {
             argumentType = universe.GetBuiltInType(System.Reflection.Adds.CorElementType.Object).MakeArrayType();
             return;
         }
         argumentType = universe.GetBuiltInType(corElementType).MakeArrayType();
         return;
     }
     if ((int)argumentTypeId != 85)
     {
         if ((int)argumentTypeId == 81)
         {
             argumentType = null;
             return;
         }
         argumentType = universe.GetBuiltInType((System.Reflection.Adds.CorElementType)((int)argumentTypeId));
     }
     else
     {
         argumentType = SignatureUtil.ExtractTypeValue(universe, module, customAttributeBlob, ref index);
         if (argumentType == null)
         {
             throw new ArgumentException(MetadataStringTable.InvalidCustomAttributeFormatForEnum);
         }
     }
 }
コード例 #2
0
ファイル: SignatureUtil.cs プロジェクト: radtek/Shopdrawing
        internal static IList <CustomAttributeTypedArgument> ExtractListOfValues(Type elementType, ITypeUniverse universe, Module module, uint size, byte[] blob, ref int index)
        {
            System.Reflection.Adds.CorElementType typeId = SignatureUtil.GetTypeId(elementType);
            List <CustomAttributeTypedArgument>   customAttributeTypedArguments = new List <CustomAttributeTypedArgument>((int)size);

            if (typeId == System.Reflection.Adds.CorElementType.Object)
            {
                for (int i = 0; (long)i < (ulong)size; i++)
                {
                    System.Reflection.Adds.CorElementType corElementType = SignatureUtil.ExtractElementType(blob, ref index);
                    SignatureUtil.VerifyElementType(corElementType);
                    Type   builtInType = null;
                    object obj         = null;
                    if (corElementType == System.Reflection.Adds.CorElementType.SzArray)
                    {
                        throw new NotImplementedException(MetadataStringTable.ArrayInsideArrayInAttributeNotSupported);
                    }
                    if (corElementType != System.Reflection.Adds.CorElementType.Enum)
                    {
                        builtInType = universe.GetBuiltInType(corElementType);
                        obj         = SignatureUtil.ExtractValue(corElementType, blob, ref index);
                    }
                    else
                    {
                        builtInType = SignatureUtil.ExtractTypeValue(universe, module, blob, ref index);
                        if (builtInType == null)
                        {
                            throw new ArgumentException(MetadataStringTable.InvalidCustomAttributeFormatForEnum);
                        }
                        System.Reflection.Adds.CorElementType typeId1 = SignatureUtil.GetTypeId(MetadataOnlyModule.GetUnderlyingType(builtInType));
                        obj = SignatureUtil.ExtractValue(typeId1, blob, ref index);
                    }
                    customAttributeTypedArguments.Add(new CustomAttributeTypedArgument(builtInType, obj));
                }
            }
            else if (typeId != System.Reflection.Adds.CorElementType.Type)
            {
                if (typeId == System.Reflection.Adds.CorElementType.SzArray)
                {
                    throw new ArgumentException(MetadataStringTable.JaggedArrayInAttributeNotSupported);
                }
                for (int j = 0; (long)j < (ulong)size; j++)
                {
                    object obj1 = SignatureUtil.ExtractValue(typeId, blob, ref index);
                    customAttributeTypedArguments.Add(new CustomAttributeTypedArgument(elementType, obj1));
                }
            }
            else
            {
                for (int k = 0; (long)k < (ulong)size; k++)
                {
                    object obj2 = SignatureUtil.ExtractTypeValue(universe, module, blob, ref index);
                    customAttributeTypedArguments.Add(new CustomAttributeTypedArgument(elementType, obj2));
                }
            }
            return(customAttributeTypedArguments.AsReadOnly());
        }
コード例 #3
0
        public static IEnumerable <CustomAttributeData> GetTypeForwardedToAttributes(MetadataOnlyModule manifestModule)
        {
            ITypeUniverse assemblyResolver = manifestModule.AssemblyResolver;
            Type          builtInType      = assemblyResolver.GetBuiltInType(System.Reflection.Adds.CorElementType.Type);
            Assembly      assembly         = assemblyResolver.GetSystemAssembly();
            Type          type             = assembly.GetType("System.Runtime.CompilerServices.TypeForwardedToAttribute", false, false);

            if (type != null)
            {
                foreach (UnresolvedTypeName rawTypeForwardedToAttribute in PseudoCustomAttributes.GetRawTypeForwardedToAttributes(manifestModule))
                {
                    ConstructorInfo[] constructorInfoArray = type.GetConstructors();
                    Type type1 = rawTypeForwardedToAttribute.ConvertToType(assemblyResolver, manifestModule);
                    List <CustomAttributeTypedArgument> customAttributeTypedArguments = new List <CustomAttributeTypedArgument>(1)
                    {
                        new CustomAttributeTypedArgument(builtInType, type1)
                    };
                    List <CustomAttributeNamedArgument> customAttributeNamedArguments = new List <CustomAttributeNamedArgument>(0);
                    yield return(new MetadataOnlyCustomAttributeData(constructorInfoArray[0], customAttributeTypedArguments, customAttributeNamedArguments));
                }
            }
        }