Exemplo n.º 1
0
		public override MethodBase SelectMethod(BindingFlags bindingAttr, MethodBase[] match, Type[] types, ParameterModifier[] modifiers)
		{
			int matchCount = 0;
			foreach (MethodBase method in match)
			{
				if (MatchParameterTypes(method.GetParameters(), types))
				{
					match[matchCount++] = method;
				}
			}

			if (matchCount == 0)
			{
				return null;
			}

			MethodBase bestMatch = match[0];
			bool ambiguous = false;
			for (int i = 1; i < matchCount; i++)
			{
				SelectBestMatch(match[i], types, ref bestMatch, ref ambiguous);
			}
			if (ambiguous)
			{
				throw new AmbiguousMatchException();
			}
			return bestMatch;
		}
Exemplo n.º 2
0
			private string GetMethodFullName (MethodBase m)
			{
				StringBuilder sb = new StringBuilder ();

				StackTraceHelper.GetFullNameForStackTrace (sb, m);

				return sb.ToString ();
			}
		internal static void AddDeclaredExceptions(MethodBase mb, IKVM.Internal.MapXml.Throws[] throws)
		{
			if (throws != null)
			{
				string[] exceptions = new string[throws.Length];
				for (int i = 0; i < exceptions.Length; i++)
				{
					exceptions[i] = throws[i].Class;
				}
				AttributeHelper.SetThrowsAttribute(mb, exceptions);
			}
		}
		public static IList<CustomAttributeData> __GetDeclarativeSecurity(MethodBase method)
		{
			if ((method.Attributes & MethodAttributes.HasSecurity) != 0)
			{
				return method.Module.GetDeclarativeSecurity(method.MetadataToken);
			}
			else
			{
				return EmptyList;
			}
		}
Exemplo n.º 5
0
		public abstract MethodBase SelectMethod(BindingFlags bindingAttr, MethodBase[] match, Type[] types, ParameterModifier[] modifiers);
Exemplo n.º 6
0
		public virtual MethodBase BindToMethod(BindingFlags bindingAttr, MethodBase[] match, ref object[] args, ParameterModifier[] modifiers, CultureInfo culture, string[] names, out object state)
		{
			throw new InvalidOperationException();
		}
Exemplo n.º 7
0
		private static void SelectBestMatch(MethodBase candidate, Type[] types, ref MethodBase currentBest, ref bool ambiguous)
		{
			switch (MatchSignatures(currentBest.MethodSignature, candidate.MethodSignature, types))
			{
				case 1:
					return;
				case 2:
					ambiguous = false;
					currentBest = candidate;
					return;
			}

			if (currentBest.MethodSignature.MatchParameterTypes(candidate.MethodSignature))
			{
				int depth1 = GetInheritanceDepth(currentBest.DeclaringType);
				int depth2 = GetInheritanceDepth(candidate.DeclaringType);
				if (depth1 > depth2)
				{
					return;
				}
				else if (depth1 < depth2)
				{
					ambiguous = false;
					currentBest = candidate;
					return;
				}
			}

			ambiguous = true;
		}
Exemplo n.º 8
0
		private static MethodBase SelectBestMatch(MethodBase mb1, MethodBase mb2, Type[] types, ref bool ambiguous)
		{
			switch (MatchSignatures(mb1.MethodSignature, mb2.MethodSignature, types))
			{
				case 1:
					return mb1;
				case 2:
					return mb2;
			}

			if (mb1.MethodSignature.MatchParameterTypes(mb2.MethodSignature))
			{
				int depth1 = GetInheritanceDepth(mb1.DeclaringType);
				int depth2 = GetInheritanceDepth(mb2.DeclaringType);
				if (depth1 > depth2)
				{
					return mb1;
				}
				else if (depth1 < depth2)
				{
					return mb2;
				}
			}

			ambiguous = true;
			return mb1;
		}
Exemplo n.º 9
0
        static bool IsAccessor(MethodBase methodInfo)
        {
            if (!methodInfo.IsSpecialName)
                return false;

            var name = methodInfo.Name;
            return
                name.StartsWith("get_", StringComparison.Ordinal) ||
                name.StartsWith("set_", StringComparison.Ordinal) ||
                name.StartsWith("add_", StringComparison.Ordinal) ||
                name.StartsWith("remove_", StringComparison.Ordinal) ||
                name.StartsWith("raise_", StringComparison.Ordinal);
        }
Exemplo n.º 10
0
 void TranslateModifiers(MethodBase method, AbstractUnresolvedMember m)
 {
     if (m.DeclaringTypeDefinition.Kind == TypeKind.Interface) {
         // interface members don't have modifiers, but we want to handle them as "public abstract"
         m.Accessibility = Accessibility.Public;
         m.IsAbstract = true;
     } else {
         m.Accessibility = GetAccessibility(method.Attributes);
         if (method.IsAbstract) {
             m.IsAbstract = true;
             m.IsOverride = !method.Attributes.HasFlag (MethodAttributes.NewSlot);
         } else if (method.IsFinal) {
             if (!method.Attributes.HasFlag (MethodAttributes.NewSlot)) {
                 m.IsSealed = true;
                 m.IsOverride = true;
             }
         } else if (method.IsVirtual) {
             if (method.Attributes.HasFlag (MethodAttributes.NewSlot))
                 m.IsVirtual = true;
             else
                 m.IsOverride = true;
         }
         m.IsStatic = method.IsStatic;
     }
 }
Exemplo n.º 11
0
 public IUnresolvedMethod ReadMethod(MethodBase method, IUnresolvedTypeDefinition parentType, SymbolKind methodType = SymbolKind.Method)
 {
     return ReadMethod((MethodInfo)method, parentType, methodType, null);
 }
 MethodBase[] GetVTableMethods(VTableFixups fixups)
 {
     var methods = new MethodBase[fixups.Count];
     byte[] buf = new byte[8];
     int fixuprva = fixups.RVA;
     for (int i = 0; i < fixups.Count; i++)
     {
         module.__ReadDataFromRVA(fixuprva, buf, 0, 4);
         methods[i] = module.ResolveMethod(BitConverter.ToInt32(buf, 0));
         if ((fixups.Type & COR_VTABLE_32BIT) != 0)
         {
             fixuprva += 4;
         }
         if ((fixups.Type & COR_VTABLE_64BIT) != 0)
         {
             fixuprva += 8;
         }
     }
     return methods;
 }
Exemplo n.º 13
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));
        }
Exemplo n.º 14
0
Arquivo: Binder.cs Projeto: koush/mono
		public abstract MethodBase BindToMethod(BindingFlags bindingAttr, MethodBase[] match, ref object[] args, ParameterModifier[] modifiers, CultureInfo culture, string[] names, out object state);
Exemplo n.º 15
0
		internal void AddXmlMapParameterAttributes(MethodBase method, string className, string methodName, string methodSig, ref ParameterBuilder[] pbs)
		{
			IKVM.Internal.MapXml.Param[] parameters = classLoader.GetXmlMapParameters(className, methodName, methodSig);
			if(parameters != null)
			{
				if(pbs == null)
				{
					// let's hope that the parameters array is the right length
					pbs = GetParameterBuilders(method, parameters.Length, null);
				}
				for(int i = 0; i < pbs.Length; i++)
				{
					if(parameters[i].Attributes != null)
					{
						foreach(IKVM.Internal.MapXml.Attribute attr in parameters[i].Attributes)
						{
							AttributeHelper.SetCustomAttribute(classLoader, pbs[i], attr);
						}
					}
				}
			}
		}