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)); } } }
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); }