Пример #1
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 ()));
 }
Пример #2
0
 public ReflectionAttributeMap(Attribute attribute)
 {
     _attribute = attribute;
 }
Пример #3
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);
     }
     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));
 }
Пример #4
0
        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]);
        }
Пример #5
0
        static void Process(MethodBase method, IKVM.Reflection.Type returnType, CustomAttributeData attrData)
        {
            string returnTypeString = returnType == TypeManager.VoidType ? "void" : TypeToC(returnType);

            string unmanagedMethodName = method.Name.Replace(".", "_");

            var namedArguments = attrData.NamedArguments ?? new CustomAttributeNamedArgument[0];
            foreach (var arg in namedArguments)
            {
                if (arg.MemberInfo.Name == "ReturnType")
                    returnTypeString = arg.TypedValue.Value.ToString();
                else if (arg.MemberInfo.Name == "Name")
                    unmanagedMethodName = arg.TypedValue.Value.ToString();
            }

            var paramList = new List<string>();

            if (!method.IsStatic)
            {
                // Add *this* parameter
                paramList.Add(FormatParameter(
                    "MonoObject*",
                    TypeToString(method.DeclaringType),
                    "self"
                    ));
            }

            foreach (var info in method.GetParameters())
            {
                paramList.Add(FormatParameter(
                    TypeToC(info.ParameterType),
                    TypeToString(info.ParameterType),
                    info.Name
                    ));
            }
            
            paramList.Add("MonoObject **ex");


            string qualMethodName = String.Format("{0}_{1}", method.DeclaringType.Name, unmanagedMethodName);

            string qualMethodDecl = String.Format("{0} (THUNKCALL *{1})({2});",
                returnTypeString,
                qualMethodName,
                String.Join(", ", paramList));

            currentMethods.Add(new ThunkMethodInfo(
                method.Name,
                qualMethodName, qualMethodDecl,
                method.ToString(),
                method.IsGenericMethodDefinition));
        }
Пример #6
0
 public List <CustomAttributeData> __GetCustomAttributesFor(int token)
 {
     return(CustomAttributeData.GetCustomAttributesImpl(new List <CustomAttributeData>(), this, token, null));
 }
Пример #7
0
 public IList <CustomAttributeData> GetCustomAttributesData()
 {
     return(CustomAttributeData.GetCustomAttributes(this));
 }
Пример #8
0
 public IList <CustomAttributeData> __GetCustomAttributes(Type attributeType, bool inherit)
 {
     return(CustomAttributeData.__GetCustomAttributes(this, attributeType, inherit));
 }
Пример #9
0
 public bool IsDefined(Type attributeType, bool inherit)
 {
     return(CustomAttributeData.__GetCustomAttributes(this, attributeType, inherit).Count != 0);
 }