本文整理汇总了C#中System.Reflection.MethodInfo.GetBaseDefinition方法的典型用法代码示例。如果您正苦于以下问题:C# MethodInfo.GetBaseDefinition方法的具体用法?C# MethodInfo.GetBaseDefinition怎么用?C# MethodInfo.GetBaseDefinition使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Reflection.MethodInfo
的用法示例。
在下文中一共展示了MethodInfo.GetBaseDefinition方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: GetProperty
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();
}
示例2: CreatePipeline
///// <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);
}
示例3: NativeMethodBuilder
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;
}
示例4: IsValidActionMethod
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;
}
示例5: HasSameBaseMethod
private static bool HasSameBaseMethod(MethodInfo first, MethodInfo second)
{
var baseOfFirst = first.GetBaseDefinition();
var baseOfSecond = second.GetBaseDefinition();
return IsSameMethod(baseOfFirst, baseOfSecond);
}
示例6: GetRouteAttributes
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);
}
}
}
}
}
示例7: NativeMethodBuilder
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;
}
示例8: Classify
void Classify(MethodInfo method, Dictionary<MethodInfo, MethodInfo> virtuals)
{
if(method.IsVirtual) {
virtuals[method.GetBaseDefinition()] = method;
return;
}
classifier.Classify(method);
}
示例9: GetBaseDefinition
private static MethodInfo GetBaseDefinition(MethodInfo method)
{
if (method.IsGenericMethod && !method.IsGenericMethodDefinition)
{
method = method.GetGenericMethodDefinition();
}
return method.GetBaseDefinition();
}
示例10: IsActionMethod
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));
}
示例11: IsActionMethod
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;
}
示例12: GetItem
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;
}
示例13: MethodInf
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);
}
}
示例14: CreatePipeline
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;
}
示例15: MethodAddVirtual
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?");
*/
}
}