private static CustomAttributeTypedArgument LoadObject(IBinaryAccessor accessor, Module module)
        {
            bool isArray     = false;
            int  elementType = (int)accessor.ReadByte();

            if (elementType == ElementType.SzArray)
            {
                isArray     = true;
                elementType = (int)accessor.ReadByte();
            }

            switch (elementType)
            {
            case ElementType.Enum:
            {
                string enumTypeName = CustomAttributeHelper.ReadBlobString(accessor);
                int    length       = isArray ? CustomAttributeHelper.ReadArrayLength(accessor) : 1;
                return(LoadEnum(accessor, module, enumTypeName, isArray, length));
            }

            default:
            {
                int length = isArray ? CustomAttributeHelper.ReadArrayLength(accessor) : 1;
                return(Load(accessor, module, elementType, isArray, length));
            }
            }
        }
コード例 #2
0
        private CustomAttributeTypedArgument LoadValue(IBinaryAccessor accessor, TypeSignature typeSig)
        {
            bool isArray = false;

            while (typeSig.ElementType != null)
            {
                if (typeSig.ElementCode == TypeElementCode.Array)
                {
                    isArray = true;
                }

                typeSig = typeSig.ElementType;
            }

            var typeRef = typeSig as TypeReference;

            if (typeRef == null)
            {
                throw new CodeModelException(string.Format(SR.AssemblyLoadError, _module.Location));
            }

            int length = isArray ? CustomAttributeHelper.ReadArrayLength(accessor) : 1;

            return(CustomAttributeTypedArgument.Load(accessor, _module, typeRef, isArray, length));
        }
        internal static CustomAttributeNamedArgument Load(IBinaryAccessor accessor, Module module)
        {
            var argument = new CustomAttributeNamedArgument();

            int argumentType = accessor.ReadByte();

            switch (argumentType)
            {
            case Metadata.ElementType.Field:
                argument._type = CustomAttributeNamedArgumentType.Field;
                break;

            case Metadata.ElementType.Property:
                argument._type = CustomAttributeNamedArgumentType.Property;
                break;

            default:
                throw new InvalidDataException();
            }

            bool isArray     = false;
            int  elementType = accessor.ReadByte();

            if (elementType == ElementType.SzArray)
            {
                elementType = accessor.ReadByte();
                isArray     = true;
            }

            switch (elementType)
            {
            case ElementType.Enum:
            {
                string enumTypeName = CustomAttributeHelper.ReadBlobString(accessor);
                enumTypeName   = enumTypeName.TrimEnd(new char[] { '\0' });
                argument._name = CustomAttributeHelper.ReadBlobString(accessor);
                int arrayLength = isArray ? CustomAttributeHelper.ReadArrayLength(accessor) : 1;
                argument._value = CustomAttributeTypedArgument.LoadEnum(accessor, module, enumTypeName, isArray, arrayLength);
            }
            break;

            default:
            {
                argument._name = CustomAttributeHelper.ReadBlobString(accessor);
                int arrayLength = isArray ? CustomAttributeHelper.ReadArrayLength(accessor) : 1;
                argument._value = CustomAttributeTypedArgument.Load(accessor, module, elementType, isArray, arrayLength);
            }
            break;
            }

            return(argument);
        }
        private static TypeSignature LoadType(IBinaryAccessor accessor, Module module)
        {
            string typeName = CustomAttributeHelper.ReadBlobString(accessor);

            if (typeName != null)
            {
                typeName = typeName.TrimEnd(new char[] { '\0' });
            }

            if (string.IsNullOrEmpty(typeName))
            {
                return(null);
            }

            var typeSig = TypeSignature.Parse(typeName, true);

            typeSig = (TypeSignature)typeSig.Relocate(module);

            return(typeSig);
        }
        private static CustomAttributeTypedArgument LoadString(IBinaryAccessor accessor, Module module, bool isArray, int arrayLength)
        {
            var type = TypeReference.GetPrimitiveType(PrimitiveTypeCode.String, module.Assembly);

            if (isArray)
            {
                var value = new string[arrayLength];
                for (int i = 0; i < arrayLength; i++)
                {
                    value[i] = CustomAttributeHelper.ReadBlobString(accessor);
                }

                return(new CustomAttributeTypedArgument(value, type));
            }
            else
            {
                string value = CustomAttributeHelper.ReadBlobString(accessor);
                return(new CustomAttributeTypedArgument(value, type));
            }
        }