GetBaseDefinition() public abstract method

public abstract GetBaseDefinition ( ) : MethodInfo
return MethodInfo
        public MethodInfo(System.Reflection.MethodInfo mi)
        {
            name = mi.Name;

            // get acces modifires
            modificators = GetModificators(mi.GetType()) + mi.ToString();
            if (mi.IsAbstract && !mi.DeclaringType.IsInterface)
            {
                modificators += "abstract ";
            }
            if (mi.GetCustomAttribute(typeof(AsyncStateMachineAttribute)) != null)
            {
                modificators += "async ";
            }
            if ((mi.MethodImplementationFlags & MethodImplAttributes.InternalCall) != 0)
            {
                modificators += "extern ";
            }
            if (!mi.Equals(mi.GetBaseDefinition()))
            {
                modificators += "overriden ";
            }
            if (mi.IsVirtual && mi.IsFinal)
            {
                modificators += "sealed ";
            }
            if (mi.IsStatic)
            {
                modificators += "static ";
            }
            if (mi.IsVirtual && !mi.IsFinal && mi.Equals(mi.GetBaseDefinition()) && !mi.DeclaringType.IsInterface)
            {
                modificators += "virtual ";
            }
        }
 private static PropertyInfo GetProperty(MethodInfo propertyGetterOrSetter)
 {
     return
         (from property in propertyGetterOrSetter.DeclaringType.GetProperties(BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic)
          let getMethod = property.GetGetMethod(true)
          let setMethod = property.GetSetMethod(true)
          where (getMethod != null && getMethod.GetBaseDefinition().Equals(propertyGetterOrSetter.GetBaseDefinition()))
              || (setMethod != null && setMethod.GetBaseDefinition().Equals(propertyGetterOrSetter.GetBaseDefinition()))
          select property).Single();
 }
        ///// <summary>
        ///// 创建并返回当前方法的拦截器管道
        ///// </summary>
        //public InterceptorPipeline CreatePipeline(MethodInfo method, Func<IEnumerable<IInterceptor>> getInterceptors)
        //{
        //    var key = InterceptorPipelineKey.ForMethod(method);
        //    if (pipelines.ContainsKey(key))
        //        return pipelines[key];
        //    if (method.GetBaseDefinition() == method)
        //        return pipelines[key] = new InterceptorPipeline(getInterceptors());
        //    return pipelines[key] = CreatePipeline(method.GetBaseDefinition(), getInterceptors);
        //}
        /// <summary>
        /// 创建并返回当前方法的拦截器管道
        /// </summary>
        public InterceptorPipeline CreatePipeline(MethodInfo method, Func<MethodInfo, IEnumerable<IInterceptor>> getInterceptors)
        {
            var key = InterceptorPipelineKey.ForMethod(method);

            if(pipelines.ContainsKey(key))
                return pipelines[key];

            if(method.GetBaseDefinition() == method)
                return pipelines[key] = new InterceptorPipeline(getInterceptors(method));

            return pipelines[key] = CreatePipeline(method.GetBaseDefinition(), getInterceptors);
        }
        private bool IsValidActionMethod(MethodInfo methodInfo, bool stripInfrastructureMethods)
        {
            if (methodInfo.IsSpecialName)
            {
                // not a normal method, e.g. a constructor or an event
                return false;
            }

            if (methodInfo.GetBaseDefinition().DeclaringType.IsAssignableFrom(typeof(AsyncController)))
            {
                // is a method on Object, ControllerBase, Controller, or AsyncController
                return false;
            }

            if (stripInfrastructureMethods)
            {
                if (IsCompletedSuffixedMethod(methodInfo))
                {
                    // do not match FooCompleted() methods, as these are infrastructure methods
                    return false;
                }
            }

            return true;
        }
Esempio n. 5
0
		internal NativeMethodBuilder (MethodInfo minfo) {
			ExportAttribute ea = (ExportAttribute) Attribute.GetCustomAttribute (minfo.GetBaseDefinition (), typeof (ExportAttribute));
			ParameterInfo [] parms = minfo.GetParameters ();

			if (ea == null)
				throw new ArgumentException ("MethodInfo does not have a export attribute");

			rettype = ConvertReturnType (minfo.ReturnType);
			// FIXME: We should detect if this is in a bound assembly or not and only alloc if needed
			Selector = new Selector (ea.Selector ?? minfo.Name, true).Handle;
			Signature = string.Format ("{0}@:", TypeConverter.ToNative (rettype));
			ParameterTypes = new Type [2 + parms.Length];

			ParameterTypes [0] = typeof (NSObject);
			ParameterTypes [1] = typeof (Selector);

			for (int i = 0; i < parms.Length; i++) {
				if (parms [i].ParameterType.IsByRef && (parms[i].ParameterType.IsSubclassOf (typeof (NSObject)) || parms[i].ParameterType == typeof (NSObject)))
					ParameterTypes [i + 2] = typeof (IntPtr).MakeByRefType ();
				else
					ParameterTypes [i + 2] = parms [i].ParameterType;
				Signature += TypeConverter.ToNative (parms [i].ParameterType);
			}
			
			DelegateType = CreateDelegateType (rettype, ParameterTypes);

			this.minfo = minfo;
		}
        private static bool HasSameBaseMethod(MethodInfo first, MethodInfo second)
        {
            var baseOfFirst = first.GetBaseDefinition();
            var baseOfSecond = second.GetBaseDefinition();

            return IsSameMethod(baseOfFirst, baseOfSecond);
        }
Esempio n. 7
0
        internal NativeMethodBuilder(MethodInfo minfo)
        {
            ExportAttribute ea = (ExportAttribute) Attribute.GetCustomAttribute (minfo.GetBaseDefinition (), typeof (ExportAttribute));

            if (ea == null)
                throw new ArgumentException ("MethodInfo does not have a export attribute");

            parms = minfo.GetParameters ();

            rettype = ConvertReturnType (minfo.ReturnType);
            // FIXME: We should detect if this is in a bound assembly or not and only alloc if needed
            Selector = new Selector (ea.Selector ?? minfo.Name, true).Handle;
            Signature = string.Format ("{0}@:", TypeConverter.ToNative (rettype));
            ParameterTypes = new Type [2 + parms.Length];

            ParameterTypes [0] = typeof (NSObject);
            ParameterTypes [1] = typeof (Selector);

            for (int i = 0; i < parms.Length; i++) {
                if (parms [i].ParameterType.IsByRef && (parms[i].ParameterType.GetElementType ().IsSubclassOf (typeof (NSObject)) || parms[i].ParameterType.GetElementType () == typeof (NSObject)))
                    ParameterTypes [i + 2] = typeof (IntPtr).MakeByRefType ();
                else
                    ParameterTypes [i + 2] = parms [i].ParameterType;
                // The TypeConverter will emit a ^@ for a byref type that is a NSObject or NSObject subclass in this case
                // If we passed the ParameterTypes [i+2] as would be more logical we would emit a ^^v for that case, which
                // while currently acceptible isn't representative of what obj-c wants.
                Signature += TypeConverter.ToNative (parms [i].ParameterType);
            }

            DelegateType = CreateDelegateType (rettype, ParameterTypes);

            this.minfo = minfo;
        }
        public override IEnumerable<IRouteAttribute> GetRouteAttributes(MethodInfo actionMethod)
        {
            // Logic from ApiControllerActionSelector

            if (actionMethod.IsSpecialName)
            {
                // not a normal method, e.g. a constructor or an event
                yield break;
            }

            if (actionMethod.GetBaseDefinition().SafeGet(x => x.DeclaringType).IsAssignableFrom(typeof(ApiController)))
            {
                // is a method on Object, IHttpController, ApiController
                yield break;
            }

            foreach (var c in Conventions)
            {
                if (actionMethod.Name.StartsWith(c.HttpMethod.Method, StringComparison.OrdinalIgnoreCase))
                {
                    var requiresId = !string.IsNullOrEmpty(c.Url);

                    if (!_alreadyUsed.Contains(c))
                    {
                        // Check first parameter, if it requires ID
                        if (!requiresId || (actionMethod.GetParameters().Length > 0 && actionMethod.GetParameters()[0].Name.Equals("id", StringComparison.OrdinalIgnoreCase)))
                        {
                            yield return BuildRouteAttribute(c);

                            _alreadyUsed.Add(c);
                        }
                    }
                }
            }
        }
Esempio n. 9
0
 void Classify(MethodInfo method, Dictionary<MethodInfo, MethodInfo> virtuals)
 {
     if(method.IsVirtual) {
         virtuals[method.GetBaseDefinition()] = method;
         return;
     }
     classifier.Classify(method);
 }
Esempio n. 10
0
        private static MethodInfo GetBaseDefinition(MethodInfo method)
        {
            if (method.IsGenericMethod && !method.IsGenericMethodDefinition)
            {
                method = method.GetGenericMethodDefinition();
            }

            return method.GetBaseDefinition();
        }
		protected virtual bool IsActionMethod(MethodInfo method)
        {
            Precondition.Require(method, () => Error.ArgumentNull("method"));

            if (method.IsDefined(typeof(IgnoreActionAttribute), false))
                return false;

            return (!method.IsAbstract && !method.IsSpecialName && !method.ContainsGenericParameters &&
                typeof(Controller).IsAssignableFrom(method.GetBaseDefinition().DeclaringType));
        }
		protected virtual bool IsActionMethod(MethodInfo method, 
			bool ignoreInfrastructureMethods)
		{
			if (method.GetBaseDefinition().DeclaringType.IsAssignableFrom(typeof(AsyncController)))
				return false;

			if (ignoreInfrastructureMethods && IsCompletedSuffixedMethod(method))
				return false;
			
			return true;
		}
        protected virtual IMethodCallTranslator GetItem(MethodInfo key)
        {
            if (key == null)
            {
                throw new ArgumentNullException("key");
            }

            IMethodCallTranslator translator;
            if (Registry.TryGetValue(key, out translator))
            {
                return translator;
            }

            if (key.IsGenericMethod && !key.IsGenericMethodDefinition)
            {
                if (Registry.TryGetValue(key.GetGenericMethodDefinition(), out translator))
                {
                    return translator;
                }
            }

            // Check if the generic form of the declaring type matches
            translator = GetItemFromGenericType(key);
            if (translator != null)
            {
                return translator;
            }

            // Check any interfaces that may have a matching method
            translator = GetItemFromInterfaces(key);
            if (translator != null)
            {
                return translator;
            }

            // Finally, check base method if this is a virtual method
            var baseMethod = key.GetBaseDefinition();
            if ((baseMethod != null) && (baseMethod != key))
            {
                return GetItem(baseMethod);
            }

            // No match found
            return null;
        }
Esempio n. 14
0
        private HandlerPipeline CreatePipeline(MethodInfo method, IEnumerable<ICallHandler> handlers)
        {
            HandlerPipelineKey key = HandlerPipelineKey.ForMethod(method);
            if (pipelines.ContainsKey(key))
            {
                return pipelines[key];
            }

            if (method.GetBaseDefinition() == method)
            {
                pipelines[key] = new HandlerPipeline(handlers);
                return pipelines[key];
            }

            var basePipeline = CreatePipeline(method.GetBaseDefinition(), handlers);
            pipelines[key] = basePipeline;
            return basePipeline;
            
        }
Esempio n. 15
0
 public MethodInf(MethodInfo method, IFieldHandlerFactory fieldHandlerFactory)
 {
     MethodInfo = method;
     _name = method.Name;
     foreach (var itf in GetInterfacesForMethod(method.DeclaringType, method.GetBaseDefinition()))
     {
         _ifaceName = itf.Name;
         break;
     }
     var syncReturnType = method.ReturnType.UnwrapTask();
     if (syncReturnType != typeof(void))
         _resultFieldHandler = fieldHandlerFactory.CreateFromType(syncReturnType, FieldHandlerOptions.None);
     var parameterInfos = method.GetParameters();
     _parameters = new ParameterInf[parameterInfos.Length];
     for (int i = 0; i < parameterInfos.Length; i++)
     {
         _parameters[i] = new ParameterInf(parameterInfos[i], fieldHandlerFactory);
     }
 }
        static StackObject *GetBaseDefinition_8(ILIntepreter __intp, StackObject *__esp, IList <object> __mStack, CLRMethod __method, bool isNewObj)
        {
            ILRuntime.Runtime.Enviorment.AppDomain __domain = __intp.AppDomain;
            StackObject *ptr_of_this_method;
            StackObject *__ret = ILIntepreter.Minus(__esp, 1);

            ptr_of_this_method = ILIntepreter.Minus(__esp, 1);
            System.Reflection.MethodInfo instance_of_this_method = (System.Reflection.MethodInfo) typeof(System.Reflection.MethodInfo).CheckCLRTypes(StackObject.ToObject(ptr_of_this_method, __domain, __mStack));
            __intp.Free(ptr_of_this_method);

            var result_of_this_method = instance_of_this_method.GetBaseDefinition();

            object obj_result_of_this_method = result_of_this_method;

            if (obj_result_of_this_method is CrossBindingAdaptorType)
            {
                return(ILIntepreter.PushObject(__ret, __mStack, ((CrossBindingAdaptorType)obj_result_of_this_method).ILInstance));
            }
            return(ILIntepreter.PushObject(__ret, __mStack, result_of_this_method));
        }
Esempio n. 17
0
        public MethodAddVirtual(Type modifyingType, MethodInfo virtual_method, MethodInfo custom_method, MethodHookType type = MethodHookType.RunAfter, MethodHookFlags flags = MethodHookFlags.None)
            : base(virtual_method, custom_method, type, flags)
        {
            ModifyingType = modifyingType;
            if (ModifyingType == null)
                throw new ArgumentException("No target type specified!");
            if (!virtual_method.DeclaringType.IsAssignableFrom(modifyingType))
                throw new ArgumentException("Given Type [" + ModifyingType.FullName + "] is not a child of target [" + virtual_method.DeclaringType + "]!");
            base.Validate_4_ParameterLayout();

            if (modifyingType
                .GetMethods(BindingFlags.Instance | BindingFlags.Static | BindingFlags.Public | BindingFlags.NonPublic)
                .Select(m => m.GetBaseDefinition())
                .Contains(virtual_method.GetBaseDefinition()))
            {
                if (virtual_method.DeclaringType == modifyingType)
                {
                    throw new ArgumentException("Can't add a new virtual override method [" + virtual_method.Name + "]. Type [" + modifyingType.FullName + "] appears to already have such one. May just use a hook?");
                }
            }
            else
            {
                throw new NotImplementedException("This part hopefully isn't necessary ever :p");
                /*
                 * MAKE SURE THAT WE HAVE THE REF TO ACTUAL BASE FUNCTION WE MODIFY ... required to to base.ourfunc();
                 *
                var tMeth = modifyingType
                    .GetMethods();
                var virtParamTypes = virtual_method.GetParameters().Select(p => p.ParameterType);
                var similarMethods = modifyingType
                    .GetMethods()
                    .Where(f => f.Name == virtual_method.Name
                        && f.ReturnType == virtual_method.ReturnType
                        && f.IsStatic == virtual_method.IsStatic
                        && f.GetParameters().Select(p => p.ParameterType).SequenceEqual(virtParamTypes)
                    );
                if (similarMethods.Count() > 0)
                    throw new ArgumentException("Can't add a new virtual override method [" + virtual_method.Name + "]. Type [" + modifyingType.FullName + "] appears to already have such one. May just use a hook?");
                */
            }
        }
Esempio n. 18
0
        private static string GetTypeModifiers(System.Reflection.MethodInfo methodInfo)
        {
            if (methodInfo.IsAbstract)
            {
                return("abstract");
            }
            if (methodInfo.IsStatic)
            {
                return("static");
            }
            if (methodInfo.IsVirtual)
            {
                return("virtual");
            }
            if (methodInfo.GetBaseDefinition() != methodInfo)
            {
                return("override");
            }

            return("");
        }
Esempio n. 19
0
		private unsafe static void RegisterMethod (MethodInfo minfo, Type type, IntPtr handle) {
			ExportAttribute ea = (ExportAttribute) Attribute.GetCustomAttribute (minfo.GetBaseDefinition (), typeof (ExportAttribute));
			if (ea == null || (minfo.IsVirtual && minfo.DeclaringType != type && minfo.DeclaringType.Assembly == NSObject.MonoMacAssembly))
				return;

			RegisterMethod (minfo, ea, type, handle);
		}
Esempio n. 20
0
 public bool SupportsMethod(MethodInfo method)
 {
     return method != null && method.Name == "ToString" && method.GetBaseDefinition().DeclaringType == typeof(object);
 }
Esempio n. 21
0
 public static MethodInfo GetBaseDefinition(this MethodInfo method)
 {
     Requires.NotNull(method, nameof(method));
     return(method.GetBaseDefinition());
 }
Esempio n. 22
0
 //======================================================================================
 // For virtual non-new slot methods, returns the least derived method that occupies the slot.
 // For everything else, return "this".
 //======================================================================================
 public static MethodInfo GetRuntimeBaseDefinition(this MethodInfo method)
 {
     return(method.GetBaseDefinition());
 }
 private bool IsOverriddenMethod(MethodInfo methodInfo)
 {
     return methodInfo != null && methodInfo.DeclaringType != methodInfo.GetBaseDefinition ().DeclaringType;
 }
Esempio n. 24
0
        //https://msdn.microsoft.com/en-us/library/system.reflection.methodinfo.getbasedefinition(v=vs.110).aspx
        internal static bool IsInterfaceImpl(MethodInfo mti, Type[] cgTypesInterfaces)
        {
            if (mti == null)
                return false;
            if (cgTypesInterfaces == null || cgTypesInterfaces.Length <= 0)
                return false;
            try
            {
                var bdef = mti.GetBaseDefinition();
                if (bdef == null)
                    return false;
                //If the current MethodInfo object represents an interface implementation,
                //the GetBaseDefinition method returns the current MethodInfo object.
                if (!bdef.Equals(mti))
                    return false;

                foreach (var i in cgTypesInterfaces)
                {
                    var iMethods = i.GetMethods();

                    foreach (var im in iMethods)
                    {
                        if (im.Name != mti.Name)
                            continue;
                        var imParams = im.GetParameters();
                        var mtiParams = mti.GetParameters();

                        if (imParams.Length != mtiParams.Length)
                            continue;

                        if (mti.NfReturnType() != im.NfReturnType())
                            return false;

                        if (imParams.Length == 0)
                            return true;

                        var imParamTypes = imParams.Select(x => x.NfParameterType()).ToList();
                        var mtiParamTypes = mtiParams.Select(x => x.NfParameterType()).ToList();

                        return imParamTypes.All(x => mtiParamTypes.Any(y => x == y));
                    }
                }
            }
            catch
            {
                return false;
            }
            return false;
        }
Esempio n. 25
0
		protected bool IsFinalizer(MethodInfo methodInfo)
		{
			return methodInfo.Name == "Finalize" && methodInfo.GetBaseDefinition().DeclaringType == typeof(object);
		}
 public static MethodInfo GetRuntimeBaseDefinition(this MethodInfo method)
 {
     RuntimeReflectionExtensions.CheckAndThrow(method);
     return(method.GetBaseDefinition());
 }
Esempio n. 27
0
 public static MethodInfo GetRuntimeBaseDefinition(this MethodInfo method)
 {
     CheckAndThrow(method);
     return(method.GetBaseDefinition());
 }
Esempio n. 28
0
		internal NativeMethodBuilder (MethodInfo minfo) : this (minfo, minfo.DeclaringType, (ExportAttribute) Attribute.GetCustomAttribute (minfo.GetBaseDefinition (), typeof (ExportAttribute))) {}
Esempio n. 29
0
 private static bool IsOverride(MethodInfo method)
 {
     if(method.GetBaseDefinition() != method)
     {
         return true;
     }
     return false;
 }
Esempio n. 30
0
 public override System.Reflection.MethodInfo GetBaseDefinition()
 {
     return(_realMethod.GetBaseDefinition());
 }
Esempio n. 31
0
        protected string TryTranslateMethodCall(string context, string[] args, MethodInfo method)
        {
            if (method == null) return null;
            IJsMethodTranslator translator;
            if (MethodTranslators.TryGetValue(method, out translator))
            {
                return translator.TranslateCall(context, args, method);
            }
            if (method.IsGenericMethod)
            {
                var genericMethod = method.GetGenericMethodDefinition();
                if (MethodTranslators.TryGetValue(genericMethod, out translator))
                {
                    return translator.TranslateCall(context, args, method);
                }
            }

            foreach (var iface in method.DeclaringType.GetInterfaces())
            {
                if (Interfaces.Contains(iface))
                {
                    var map = method.DeclaringType.GetInterfaceMap(iface);
                    var imIndex = Array.IndexOf(map.TargetMethods, method);
                    if (imIndex >= 0 && MethodTranslators.ContainsKey(map.InterfaceMethods[imIndex]))
                        return MethodTranslators[map.InterfaceMethods[imIndex]].TranslateCall(context, args, method);
                }
            }
            if (method.DeclaringType.IsGenericType && !method.DeclaringType.IsGenericTypeDefinition)
            {
                var genericType = method.DeclaringType.GetGenericTypeDefinition();
                var m2 = genericType.GetMethod(method.Name, BindingFlags.Instance | BindingFlags.Static | BindingFlags.NonPublic | BindingFlags.Public);
                if (m2 != null)
                {
                    var r2 = TryTranslateMethodCall(context, args, m2);
                    if (r2 != null) return r2;
                }
            }
			if (method.DeclaringType == typeof(Array))
			{
				var m2 = typeof(Array).GetMethod(method.Name, BindingFlags.Instance | BindingFlags.Static | BindingFlags.NonPublic | BindingFlags.Public);
				if (m2 != null)
				{
					var r2 = TryTranslateMethodCall(context, args, m2);
					if (r2 != null) return r2;
				}
			}
			var baseMethod = method.GetBaseDefinition();
            if (baseMethod != null && baseMethod != method) return TryTranslateMethodCall(context, args, baseMethod);
            else return null;
        }
Esempio n. 32
0
      private static MethodInvoker SpitAndInstantiateClassFor(MethodInfo method){
        TypeBuilder tb = MethodInvoker.module.DefineType("invoker"+MethodInvoker.count++, TypeAttributes.Public, typeof(MethodInvoker));
        MethodBuilder mb = tb.DefineMethod("Invoke", MethodAttributes.Public|MethodAttributes.Virtual|MethodAttributes.ReuseSlot, 
          typeof(Object), new Type[]{typeof(Object), typeof(Object[])});
#if !DEBUG
        mb.SetCustomAttribute(new CustomAttributeBuilder(CompilerGlobals.debuggerStepThroughAttributeCtor, new Object[]{}));
        mb.SetCustomAttribute(new CustomAttributeBuilder(CompilerGlobals.debuggerHiddenAttributeCtor, new Object[]{}));
#endif      
        ILGenerator il = mb.GetILGenerator();
        if (!method.DeclaringType.IsPublic) method = method.GetBaseDefinition();
        Type obT = method.DeclaringType;
        if (!method.IsStatic){
          il.Emit(OpCodes.Ldarg_1);
          if (obT.IsValueType){
            Convert.EmitUnbox(il, obT, Type.GetTypeCode(obT));
            Convert.EmitLdloca(il, obT);
          }else{
            il.Emit(OpCodes.Castclass, obT);
          }
        }
        ParameterInfo[] parameters = method.GetParameters();
        LocalBuilder[] outTemps = null;
        for (int i = 0, n = parameters.Length; i < n; i++){
          il.Emit(OpCodes.Ldarg_2);
          ConstantWrapper.TranslateToILInt(il, i);
          Type pt = parameters[i].ParameterType;
          if (pt.IsByRef){
            pt = pt.GetElementType();
            if (outTemps == null) outTemps = new LocalBuilder[n];
            outTemps[i] = il.DeclareLocal(pt);
            il.Emit(OpCodes.Ldelem_Ref);
            if (pt.IsValueType)
              Convert.EmitUnbox(il, pt, Type.GetTypeCode(pt));
            il.Emit(OpCodes.Stloc, outTemps[i]);
            il.Emit(OpCodes.Ldloca, outTemps[i]);
          }else{
            il.Emit(OpCodes.Ldelem_Ref);
            if (pt.IsValueType)
              Convert.EmitUnbox(il, pt, Type.GetTypeCode(pt));
          }
        }
        if (!method.IsStatic && method.IsVirtual && !method.IsFinal && !obT.IsSealed)
          il.Emit(OpCodes.Callvirt, method);
        else
          il.Emit(OpCodes.Call, method);
        Type rt = method.ReturnType;
        if (rt == Typeob.Void)
          il.Emit(OpCodes.Ldnull);
        else if (rt.IsValueType)
          il.Emit(OpCodes.Box, rt);
        if (outTemps != null){
          for (int i = 0, n = parameters.Length; i < n; i++){
            LocalBuilder loc = outTemps[i];
            if (loc != null){
              il.Emit(OpCodes.Ldarg_2);
              ConstantWrapper.TranslateToILInt(il, i);
              il.Emit(OpCodes.Ldloc, loc);
              Type pt = parameters[i].ParameterType.GetElementType();
              if (pt.IsValueType)
                il.Emit(OpCodes.Box, pt);
              il.Emit(OpCodes.Stelem_Ref);
            }
          }
        }
        il.Emit(OpCodes.Ret);
        Type t = tb.CreateType();
        return (MethodInvoker)Activator.CreateInstance(t);
      }
        private static bool IsValidActionMethod(MethodInfo methodInfo, bool stripInfrastructureMethods) {
            if (methodInfo.IsSpecialName) {
                // not a normal method, e.g. a constructor or an event
                return false;
            }

            if (methodInfo.GetBaseDefinition().DeclaringType.IsAssignableFrom(typeof(AsyncController))) {
                // is a method on Object, ControllerBase, Controller, or AsyncController
                return false;
            };

            if (stripInfrastructureMethods) {
                string methodName = methodInfo.Name;
                if (methodName.StartsWith("End", StringComparison.OrdinalIgnoreCase) || methodName.EndsWith("Completed", StringComparison.OrdinalIgnoreCase)) {
                    // do not match EndFoo() or FooCompleted() methods, as these are infrastructure methods
                    return false;
                }
            }

            return true;
        }
Esempio n. 34
0
        private static MethodInfo GetMethodOnTypeThatImplementsInterfaceMethod(Type type, MethodInfo method)
        {
            var baseDefinition = method.GetBaseDefinition();

            if (!baseDefinition.DeclaringType.IsInterface || !TypeImplementsInterface(type, baseDefinition.DeclaringType))
            {
                return null;
            }

            var interfaceMap = type.GetInterfaceMap(baseDefinition.DeclaringType);

            return
                (from methodTargetPair in interfaceMap.InterfaceMethods
                     .Zip(interfaceMap.TargetMethods, (interfaceMethod, targetMethod) => new { InterfaceMethod = interfaceMethod, TargetMethod = targetMethod })
                 where HasSameBaseMethod(EnsureNonGeneric(methodTargetPair.InterfaceMethod), EnsureNonGeneric(method))
                 select MakeGeneric(methodTargetPair.TargetMethod, method)).First();
        }
Esempio n. 35
0
 public static MethodInfo GetBaseDefinition(this MethodInfo method)
 {
     ArgumentNullException.ThrowIfNull(method);
     return(method.GetBaseDefinition());
 }
Esempio n. 36
0
 private static bool IsValidActionMethod(MethodInfo methodInfo)
 {
     return !(methodInfo.IsSpecialName ||
              methodInfo.GetBaseDefinition().DeclaringType.IsAssignableFrom(typeof(Controller)));
 }
Esempio n. 37
0
 public static EventInfo GetEvent(MethodInfo eventAdderOrRemover)
 {
     return
         (from e in eventAdderOrRemover.DeclaringType.GetEvents()
          where object.Equals(e.GetAddMethod().GetBaseDefinition(), eventAdderOrRemover.GetBaseDefinition())
              || object.Equals(e.GetRemoveMethod().GetBaseDefinition(), eventAdderOrRemover.GetBaseDefinition())
          select e).SingleOrDefault();
 }
Esempio n. 38
0
        /// <summary>
        /// This is an exact copy from ApiControllerActionSelector.
        /// </summary>
        private static bool IsValidActionMethod(MethodInfo methodInfo)
        {
            if (methodInfo.IsSpecialName)
            {
                // not a normal method, e.g. a constructor or an event
                return false;
            }

            if (methodInfo.GetBaseDefinition().DeclaringType.IsAssignableFrom(TypeHelper.ApiControllerType))
            {
                // is a method on Object, IHttpController, ApiController
                return false;
            }

            return true;
        }
Esempio n. 39
0
 /// <summary>
 /// Gets the specified method's ID Value. If the method has not been scanned already, a new ID Value is created.
 /// </summary>
 /// <param name="aMethod">The method to get the ID Value of.</param>
 /// <returns>The method's ID Value.</returns>
 public string GetMethodIDValue(MethodInfo aMethod)
 {
     string methodSignature = Utils.GetMethodSignature(aMethod);
     string result = null;
     if (MethodIDValues.ContainsKey(methodSignature))
     {
         result = MethodIDValues[methodSignature];
     }
     else
     {
         //Check if method is actually an override
         // - If so, use the same method ID value as parent method
         MethodInfo baseDefMethod = aMethod.GetBaseDefinition();
         if (baseDefMethod != aMethod)
         {
             result = GetMethodIDValue(baseDefMethod);
         }
         else
         {
             result = (currentMethodIDValue++).ToString();
         }
         MethodIDValues.Add(methodSignature, result);
     }
     return result;
 }