Example #1
0
        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());
        }
Example #2
0
 internal static System.Reflection.Adds.CorElementType GetTypeId(Type type)
 {
     System.Reflection.Adds.CorElementType corElementType;
     if (type.IsEnum)
     {
         return(SignatureUtil.GetTypeId(MetadataOnlyModule.GetUnderlyingType(type)));
     }
     if (type.IsArray)
     {
         return(System.Reflection.Adds.CorElementType.SzArray);
     }
     if (!SignatureUtil.TypeMapForAttributes.LookupPrimitive(type, out corElementType))
     {
         throw new ArgumentException(MetadataStringTable.UnsupportedTypeInAttributeSignature);
     }
     return(corElementType);
 }