本文整理汇总了C#中MethodBase类的典型用法代码示例。如果您正苦于以下问题:C# MethodBase类的具体用法?C# MethodBase怎么用?C# MethodBase使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
MethodBase类属于命名空间,在下文中一共展示了MethodBase类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: ComputeToString
public static String ComputeToString(MethodBase contextMethod, RuntimeType[] methodTypeArguments, RuntimeParameterInfo[] runtimeParametersAndReturn)
{
StringBuilder sb = new StringBuilder(30);
sb.Append(runtimeParametersAndReturn[0].ParameterTypeString);
sb.Append(' ');
sb.Append(contextMethod.Name);
if (methodTypeArguments.Length != 0)
{
String sep = "";
sb.Append('[');
foreach (RuntimeType methodTypeArgument in methodTypeArguments)
{
sb.Append(sep);
sep = ",";
String name = methodTypeArgument.InternalNameIfAvailable;
if (name == null)
name = ToStringUtils.UnavailableType;
sb.Append(methodTypeArgument.Name);
}
sb.Append(']');
}
sb.Append('(');
sb.Append(ComputeParametersString(runtimeParametersAndReturn, 1));
sb.Append(')');
return sb.ToString();
}
示例2: Intercept
public object Intercept(MethodBase decoratedMethod, MethodBase implementationMethod, object[] arguments)
{
if (this.implementationMethodTarget == null)
{
throw new InvalidOperationException("Something has gone seriously wrong with StaticProxy.Fody." +
".Initialize(implementationMethodTarget) must be called once before any .Intercept(..)");
}
// since we only support methods, not constructors, this is actually a MethodInfo
var decoratedMethodInfo = (MethodInfo)decoratedMethod;
ITargetInvocation targetInvocation = this.targetInvocationFactory.Create(this.implementationMethodTarget, implementationMethod);
IInvocation invocation = this.invocationFactory
.Create(targetInvocation, decoratedMethodInfo, arguments, this.interceptors.ToArray());
invocation.Proceed();
if (invocation.ReturnValue == null && !this.typeInformation.IsNullable(decoratedMethodInfo.ReturnType))
{
string message = string.Format(
CultureInfo.InvariantCulture,
"Method {0}.{1} has return type {2} which is a value type. After the invocation the invocation the return value was null. Please ensure that your interceptors call IInvocation.Proceed() or sets a valid IInvocation.ReturnValue.",
this.implementationMethodTarget.GetType().FullName,
decoratedMethodInfo,
decoratedMethodInfo.ReturnType.FullName);
throw new InvalidOperationException(message);
}
return invocation.ReturnValue;
}
示例3: BindToMethod
public override MethodBase BindToMethod(
BindingFlags bindingAttr,
MethodBase[] match,
ref object[] args,
ParameterModifier[] modifiers,
CultureInfo culture,
string[] names,
out object state)
{
if (match == null)
{
throw new ArgumentNullException("match");
}
// Arguments are not being reordered.
state = null;
// Find a parameter match and return the first method with
// parameters that match the request.
foreach (MethodBase mb in match)
{
ParameterInfo[] parameters = mb.GetParameters();
if (ParametersMatch(parameters, args))
{
return mb;
}
}
return null;
}
示例4: RuntimeFatMethodParameterInfo
private RuntimeFatMethodParameterInfo(MethodBase member, MethodHandle methodHandle, int position, ParameterHandle parameterHandle, ReflectionDomain reflectionDomain, MetadataReader reader, Handle typeHandle, TypeContext typeContext)
: base(member, position, reflectionDomain, reader, typeHandle, typeContext)
{
_methodHandle = methodHandle;
_parameterHandle = parameterHandle;
_parameter = parameterHandle.GetParameter(reader);
}
示例5: SelectMethod
public override sealed MethodBase SelectMethod(BindingFlags bindingAttr, MethodBase[] match, Type[] types, ParameterModifier[] modifiers)
{
if (!((bindingAttr & ~SupportedBindingFlags) == 0) && modifiers == null)
throw new NotImplementedException();
return LimitedBinder.SelectMethod(match, types);
}
示例6: BindToMethod
public override sealed MethodBase BindToMethod(BindingFlags bindingAttr, MethodBase[] match, ref object[] args, ParameterModifier[] modifiers, CultureInfo culture, string[] names, out object state)
{
if (!((bindingAttr & ~SupportedBindingFlags) == 0) && modifiers == null && culture == null && names == null)
throw new NotImplementedException();
state = null;
return LimitedBinder.BindToMethod(match, ref args);
}
示例7: RuntimeMethodParameterInfo
protected RuntimeMethodParameterInfo(MethodBase member, int position, ReflectionDomain reflectionDomain, MetadataReader reader, Handle typeHandle, TypeContext typeContext)
: base(member, position)
{
_reflectionDomain = reflectionDomain;
Reader = reader;
_typeHandle = typeHandle;
_typeContext = typeContext;
}
示例8: Init
public override void Init(object instance, MethodBase method, object[] args)
{
_instance = instance;
_method = method;
_args = args;
if (method.Name == "ApiHandler") _logoType = "接口通道ApiHandler";
else if (method.Name == "InfoApiHandler") _logoType = "接口通道InfoApiHandler";
else if (method.Name == "StreamApiHandler") _logoType = "接口通道StreamApiHandler";
}
示例9: GetParameterTypes
// returns array of the types of the parameters of the method specified by methodinfo
public static Type[] GetParameterTypes( MethodBase methodbase )
{
ParameterInfo[] parameterinfos = methodbase.GetParameters();
Type[] paramtypes = new Type[ parameterinfos.GetUpperBound(0) + 1 ];
for( int i = 0; i < parameterinfos.GetUpperBound(0) + 1; i ++ )
{
paramtypes[i] = parameterinfos[i].ParameterType;
}
return paramtypes;
}
示例10: GetFullNameForStackTrace
public static void GetFullNameForStackTrace (StringBuilder sb, MethodBase mi)
{
var declaringType = mi.DeclaringType;
if (declaringType.IsGenericType && !declaringType.IsGenericTypeDefinition)
declaringType = declaringType.GetGenericTypeDefinition ();
// Get generic definition
var bindingflags = BindingFlags.Instance | BindingFlags.Static | BindingFlags.Public | BindingFlags.NonPublic;
foreach (var m in declaringType.GetMethods (bindingflags)) {
if (m.MetadataToken == mi.MetadataToken) {
mi = m;
break;
}
}
sb.Append (declaringType.ToString ());
sb.Append (".");
sb.Append (mi.Name);
if (mi.IsGenericMethod) {
Type[] gen_params = mi.GetGenericArguments ();
sb.Append ("[");
for (int j = 0; j < gen_params.Length; j++) {
if (j > 0)
sb.Append (",");
sb.Append (gen_params [j].Name);
}
sb.Append ("]");
}
ParameterInfo[] p = mi.GetParameters ();
sb.Append (" (");
for (int i = 0; i < p.Length; ++i) {
if (i > 0)
sb.Append (", ");
Type pt = p[i].ParameterType;
if (pt.IsGenericType && ! pt.IsGenericTypeDefinition)
pt = pt.GetGenericTypeDefinition ();
sb.Append (pt.ToString());
if (p [i].Name != null) {
sb.Append (" ");
sb.Append (p [i].Name);
}
}
sb.Append (")");
}
示例11: ParameterBuilder
// Constructor.
internal ParameterBuilder(TypeBuilder type, MethodBase method,
int position, ParameterAttributes attributes,
String strParamName)
{
// Initialize the internal state.
this.type = type;
this.method = method;
// Register this item to be detached later.
type.module.assembly.AddDetach(this);
// Create the parameter.
lock(typeof(AssemblyBuilder))
{
this.privateData = ClrParameterCreate
(((IClrProgramItem)method).ClrHandle,
position, attributes, strParamName);
}
}
示例12: GetVTableMethods
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;
}
示例13: Log
/// <summary>
/// Used by MethodTimer.
/// </summary>
/// <param name="methodBase"></param>
/// <param name="milliseconds"></param>
public static void Log(MethodBase methodBase, long milliseconds)
{
Log(methodBase.DeclaringType, methodBase.Name, milliseconds);
}
示例14: ApplyAttributes
// Define each type attribute (in/out/ref) and
// the argument names.
public void ApplyAttributes (IMemberContext mc, MethodBase builder)
{
if (Count == 0)
return;
MethodBuilder mb = builder as MethodBuilder;
ConstructorBuilder cb = builder as ConstructorBuilder;
var pa = mc.Module.PredefinedAttributes;
for (int i = 0; i < Count; i++) {
this [i].ApplyAttributes (mb, cb, i + 1, pa);
}
}
示例15: GetMetaInfo
public MethodBase GetMetaInfo ()
{
//
// inflatedMetaInfo is extra field needed for cases where we
// inflate method but another nested type can later inflate
// again (the cache would be build with inflated metaInfo) and
// TypeBuilder can work with method definitions only
//
if (inflatedMetaInfo == null) {
if ((state & StateFlags.PendingMetaInflate) != 0) {
var dt_meta = DeclaringType.GetMetaInfo ();
if (DeclaringType.IsTypeBuilder) {
if (IsConstructor)
inflatedMetaInfo = TypeBuilder.GetConstructor (dt_meta, (ConstructorInfo) MemberDefinition.Metadata);
else
inflatedMetaInfo = TypeBuilder.GetMethod (dt_meta, (MethodInfo) MemberDefinition.Metadata);
} else {
#if STATIC
// it should not be reached
throw new NotImplementedException ();
#else
inflatedMetaInfo = MethodInfo.GetMethodFromHandle (MemberDefinition.Metadata.MethodHandle, dt_meta.TypeHandle);
#endif
}
state &= ~StateFlags.PendingMetaInflate;
} else {
inflatedMetaInfo = MemberDefinition.Metadata;
}
}
if ((state & StateFlags.PendingMakeMethod) != 0) {
var sre_targs = new MetaType[targs.Length];
for (int i = 0; i < sre_targs.Length; ++i)
sre_targs[i] = targs[i].GetMetaInfo ();
inflatedMetaInfo = ((MethodInfo) inflatedMetaInfo).MakeGenericMethod (sre_targs);
state &= ~StateFlags.PendingMakeMethod;
}
return inflatedMetaInfo;
}