Exemplo n.º 1
0
 public override object ReadValue(BlobReader reader, Func<string, CustomAttributePropertyType> resolveType)
 {
     switch (Type)
     {
     case PrimitiveType.Boolean:
         return reader.ReadByte() == 0 ? false : true;
     case PrimitiveType.Char:
         return (char)reader.ReadUInt16();
     case PrimitiveType.Int8:
         return reader.ReadSByte();
     case PrimitiveType.Int16:
         return reader.ReadInt16();
     case PrimitiveType.Int32:
         return reader.ReadInt32();
     case PrimitiveType.Int64:
         return reader.ReadInt64();
     case PrimitiveType.UInt8:
         return reader.ReadByte();
     case PrimitiveType.UInt16:
         return reader.ReadUInt16();
     case PrimitiveType.UInt32:
         return reader.ReadUInt32();
     case PrimitiveType.UInt64:
         return reader.ReadUInt64();
     case PrimitiveType.IntNative:
     case PrimitiveType.UIntNative:
         throw new PEException("cannot read native integers");
     case PrimitiveType.Single:
         return reader.ReadSingle();
     case PrimitiveType.Double:
         return reader.ReadDouble();
     case PrimitiveType.String:
         return reader.ReadUTF8SizedString();
     case PrimitiveType.Type:
         return new TypeCustomAttributePropertyValue { Name = reader.ReadUTF8SizedString() };
     case PrimitiveType.Object:
     case PrimitiveType.TypedRef:
     case PrimitiveType.Void:
         throw new PEException("invalid type tag in custom attribute");
     default:
         throw new ArgumentOutOfRangeException();
     }
 }
Exemplo n.º 2
0
 public void Read(IImSeq<CustomAttributePropertyType> fixedArgTypes, BlobReader reader, Func<string, CustomAttributePropertyType> resolveType)
 {
     var fieldArgs = default(Map<string, CustomAttributeProperty>);
     var propertyArgs = default(Map<string, CustomAttributeProperty>);
     if (reader.AtEndOfBlob)
     {
         if (fixedArgTypes.Count > 0)
             throw new PEException("expected fixed arguments in custom attribute");
         FixedArgs = Constants.EmptyCustomAttributeProperties;
         FieldArgs = Constants.EmptyNamedCustomAttributueProperties;
         PropertyArgs = Constants.EmptyNamedCustomAttributueProperties;
     }
     else
     {
         if (reader.ReadUInt16() != prolog)
             throw new PEException("invalid custom attribute");
         if (fixedArgTypes.Count > 0)
         {
             var fixedArgs = new Seq<CustomAttributeProperty>(fixedArgTypes.Count);
             for (var i = 0; i < fixedArgTypes.Count; i++)
             {
                 var type = fixedArgTypes[i];
                 fixedArgs.Add
                     (new CustomAttributeProperty { Type = type, Value = type.ReadValue(reader, resolveType) });
             }
             FixedArgs = fixedArgs;
         }
         else
             FixedArgs = Constants.EmptyCustomAttributeProperties;
         var numNamed = reader.ReadUInt16();
         for (var i = 0; i < numNamed; i++)
         {
             var tag = (TypeSigTag)reader.ReadByte();
             var type = CustomAttributePropertyType.Read(reader, resolveType);
             var nm = reader.ReadUTF8SizedString();
             var prop = new CustomAttributeProperty { Type = type, Value = type.ReadValue(reader, resolveType) };
             if (tag == TypeSigTag.CUSTOM_ATTRIBUTE_FIELD)
             {
                 if (fieldArgs == null)
                     fieldArgs = new Map<string, CustomAttributeProperty>();
                 if (fieldArgs.ContainsKey(nm))
                     throw new PEException("duplicate named field in custom attribute");
                 fieldArgs.Add(nm, prop);
             }
             else if (tag == TypeSigTag.CUSTOM_ATTRIBUTE_PROPERTY)
             {
                 if (propertyArgs == null)
                     propertyArgs = new Map<string, CustomAttributeProperty>();
                 if (propertyArgs.ContainsKey(nm))
                     throw new PEException("duplicate named property in custom attribute");
                 propertyArgs.Add(nm, prop);
             }
             else
                 throw new PEException("invalid custom attribute");
         }
         FieldArgs = fieldArgs ?? Constants.EmptyNamedCustomAttributueProperties;
         PropertyArgs = propertyArgs ?? Constants.EmptyNamedCustomAttributueProperties;
     }
 }
Exemplo n.º 3
0
 public static CustomAttributePropertyType Read(BlobReader reader, Func<string, CustomAttributePropertyType> resolveType)
 {
     var tag = (TypeSigTag)reader.ReadByte();
     var res = default(CustomAttributePropertyType);
     switch (tag)
     {
     case TypeSigTag.SZARRAY:
         res = new ArrayCustomAttributePropertyType();
         break;
     case TypeSigTag.CUSTOM_ATTRIBUTE_BOXED_ARGUMENT:
         res = new ObjectCustomAttributePropertyType();
         break;
     case TypeSigTag.CUSTOM_ATTRIBUTE_ENUM:
         {
             var typeName = reader.ReadUTF8SizedString();
             res = resolveType(typeName);
             if (!(res is EnumCustomAttributePropertyType))
                 throw new PEException("invalid enumeration type in custom attribute");
             break;
         }
     default:
         res = new PrimitiveCustomAttributePropertyType { Type = PrimitiveTypeSig.FromTag(tag) };
         break;
     }
     res.ReadRest(reader, resolveType);
     return res;
 }