decimal? TryDecodeDecimalConstantAttribute(CustomAttributeData attribute) { if (attribute.ConstructorArguments.Count != 5) return null; var reader = new BlobReader(attribute.__GetBlob(), null); if (reader.ReadUInt16() != 0x0001) { Debug.WriteLine("Unknown blob prolog"); return null; } // DecimalConstantAttribute has the arguments (byte scale, byte sign, uint hi, uint mid, uint low) or (byte scale, byte sign, int hi, int mid, int low) // Both of these invoke the Decimal constructor (int lo, int mid, int hi, bool isNegative, byte scale) with explicit argument conversions if required. var ctorArgs = new object[attribute.ConstructorArguments.Count]; for (int i = 0; i < ctorArgs.Length; i++) { switch (attribute.ConstructorArguments[i].ArgumentType.FullName) { case "System.Byte": ctorArgs[i] = reader.ReadByte(); break; case "System.Int32": ctorArgs[i] = reader.ReadInt32(); break; case "System.UInt32": ctorArgs[i] = unchecked((int)reader.ReadUInt32()); break; default: return null; } } if (!ctorArgs.Select(a => a.GetType()).SequenceEqual(new[] { typeof(byte), typeof(byte), typeof(int), typeof(int), typeof(int) })) return null; return new decimal((int)ctorArgs[4], (int)ctorArgs[3], (int)ctorArgs[2], (byte)ctorArgs[1] != 0, (byte)ctorArgs[0]); }
public IUnresolvedAttribute ReadAttribute(CustomAttributeData attribute) { if (attribute == null) throw new ArgumentNullException("attribute"); var ctor = attribute.Constructor; ITypeReference attributeType = ReadTypeReference(attribute.AttributeType); IList<ITypeReference> ctorParameterTypes = EmptyList<ITypeReference>.Instance; var parameters = ctor.GetParameters (); if (parameters.Length > 0) { ctorParameterTypes = new ITypeReference[parameters.Length]; for (int i = 0; i < ctorParameterTypes.Count; i++) { ctorParameterTypes[i] = ReadTypeReference(parameters[i].ParameterType); } ctorParameterTypes = interningProvider.InternList(ctorParameterTypes); } return interningProvider.Intern(new CecilUnresolvedAttribute(attributeType, ctorParameterTypes, attribute.__GetBlob ())); }
public IUnresolvedAttribute ReadAttribute(CustomAttributeData attribute) { if (attribute == null) throw new ArgumentNullException("attribute"); var ctor = attribute.Constructor; ITypeReference attributeType = ReadTypeReference(attribute.AttributeType); IList<ITypeReference> ctorParameterTypes = EmptyList<ITypeReference>.Instance; var parameters = ctor.GetParameters (); if (parameters.Length > 0) { ctorParameterTypes = new ITypeReference[parameters.Length]; for (int i = 0; i < ctorParameterTypes.Count; i++) { ctorParameterTypes[i] = ReadTypeReference(parameters[i].ParameterType); } ctorParameterTypes = interningProvider.InternList(ctorParameterTypes); } byte[] blob; try { blob = attribute.__GetBlob (); } catch (Exception e) { blob = new byte[0]; Console.Error.WriteLine ("IKVM error while getting blob:" + e); } return interningProvider.Intern(new UnresolvedAttributeBlob(attributeType, ctorParameterTypes, blob)); }