本文整理汇总了C#中System.Reflection.MethodBase类的典型用法代码示例。如果您正苦于以下问题:C# MethodBase类的具体用法?C# MethodBase怎么用?C# MethodBase使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
MethodBase类属于System.Reflection命名空间,在下文中一共展示了MethodBase类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: FormatMethod
protected virtual string FormatMethod(MethodBase method)
{
var sb = new StringBuilder();
if (method.DeclaringType != null)
{
sb.Append(method.DeclaringType.FullName);
sb.Append(".");
}
sb.Append(method.Name);
if (method.IsGenericMethod)
{
sb.Append("<");
sb.Append(string.Join(", ", method.GetGenericArguments().Select(t => t.Name)));
sb.Append(">");
}
sb.Append("(");
var f = false;
foreach (var p in method.GetParameters())
{
if (f) sb.Append(", ");
else f = true;
sb.Append(p.ParameterType.Name);
sb.Append(' ');
sb.Append(p.Name);
}
sb.Append(")");
return sb.ToString();
}
示例2: Action
public override object Action(object target, MethodBase method, object[] parameters, object result)
{
string namePrincipal = Thread.CurrentPrincipal.Identity.Name;
if (namePrincipal == string.Empty)
{
namePrincipal = "Anonymous User";
}
namePrincipal = "User: " + namePrincipal;
string text = "Assambly: " + target.ToString() + "\nMethod: " + method.Name;
string content = Helper.ReadFile(_pathInternal);
try
{
Helper.SaveToFile(namePrincipal, text, content, _pathInternal);
}
catch
{
throw;
}
return null;
}
示例3: ReflectedMethod
public ReflectedMethod(Identifier name, MethodBase method, Type targetType)
: base(name, null, method, targetType)
{
DeclaringName = method.DeclaringType != targetType
? IdentifierFor.Method(method, method.DeclaringType)
: name;
}
示例4: MethodTracerItem
/// <summary>
/// Constructor.
/// </summary>
public MethodTracerItem(TypeEnum itemType, TracerItem.PriorityEnum priority, string message, MethodBase methodInfo, string threadName, string threadId)
: base(itemType, priority, message)
{
_methodBase = methodInfo;
_threadId = threadId;
_threadName = threadName;
}
示例5: CompileTimeValidate
// Validate the attribute usage.
public override bool CompileTimeValidate( MethodBase method )
{
// Don't apply to constructors.
if ( method is ConstructorInfo )
{
Message.Write( SeverityType.Error, "CX0001", "Cannot cache constructors." );
return false;
}
MethodInfo methodInfo = (MethodInfo) method;
// Don't apply to void methods.
if ( methodInfo.ReturnType.Name == "Void" )
{
Message.Write( SeverityType.Error, "CX0002", "Cannot cache void methods." );
return false;
}
// Does not support out parameters.
ParameterInfo[] parameters = method.GetParameters();
for ( int i = 0; i < parameters.Length; i++ )
{
if ( parameters[i].IsOut )
{
Message.Write( SeverityType.Error, "CX0003", "Cannot cache methods with return values." );
return false;
}
}
return true;
}
示例6: IsStatic
//===========================================================================================
private bool IsStatic(MethodBase[] methods)
{
if (methods.Length != 1)
return false;
return IsStatic(methods[0]);
}
示例7: InitialiseProperties
public void InitialiseProperties(
Type classUnderTest,
object instanceUnderTest,
MethodBase methodUnderTest,
object[] parameters,
string nullParameter,
int nullIndex,
IExecutionSetup executionSetup)
{
// Act
var sut = new MethodData(
classUnderTest,
instanceUnderTest,
methodUnderTest,
parameters,
nullParameter,
nullIndex,
executionSetup);
// Assert
Assert.Same(classUnderTest, sut.ClassUnderTest);
Assert.Equal(instanceUnderTest, sut.InstanceUnderTest);
Assert.Same(methodUnderTest, sut.MethodUnderTest);
Assert.Same(parameters, sut.Parameters);
Assert.Same(nullParameter, sut.NullParameter);
Assert.Equal(nullIndex, sut.NullIndex);
Assert.Same(executionSetup, sut.ExecutionSetup);
}
示例8: MonoMethodMessage
public MonoMethodMessage (MethodBase method, object [] out_args)
{
if (method != null)
InitMessage ((MonoMethod)method, out_args);
else
args = null;
}
示例9: GetNumberOfStackPushes
public override int GetNumberOfStackPushes(MethodBase aMethod)
{
switch (OpCode)
{
case Code.Initobj:
return 0;
case Code.Ldelema:
return 1;
case Code.Newarr:
return 1;
case Code.Box:
return 1;
case Code.Stelem:
return 0;
case Code.Ldelem:
return 1;
case Code.Isinst:
return 1;
case Code.Castclass:
return 1;
case Code.Constrained:
return 0;
case Code.Unbox_Any:
return 1;
case Code.Unbox:
return 1;
case Code.Stobj:
return 0;
case Code.Ldobj:
return 1;
default:
throw new NotImplementedException("OpCode '" + OpCode + "' not implemented!");
}
}
示例10: TypeActivationContext
/// <summary>
/// Initializes a new instance of the MethodActivationContext class.
/// </summary>
/// <param name="target">The object instance that initiated the activation request.</param>
/// <param name="targetMethod">The method where the activation was invoked.</param>
/// <param name="concreteType">The type to be constructed.</param>
/// <param name="additionalArguments">The additional arguments that will be passed to the constructor.</param>
public TypeActivationContext(object target, MethodBase targetMethod,
Type concreteType, object[] additionalArguments)
: base(concreteType, additionalArguments)
{
Target = target;
TargetMethod = targetMethod;
}
示例11: FromMethod
/// <summary>
/// Creates a REST call from a given method.
/// If the method has no marker, a null is returned
/// </summary>
/// <param name="methodBase">The method base.</param>
/// <returns></returns>
public static RestCall FromMethod(MethodBase methodBase)
{
var httpGet = methodBase.GetCustomAttribute<HttpGetAttribute>();
if (httpGet != null)
return new RestCall("GET", httpGet.UriTemplate);
return null;
}
示例12: Action
public override object Action(object target, MethodBase method, object[] parameters, object result)
{
string namePrincipal = Thread.CurrentPrincipal.Identity.Name;
if (namePrincipal == string.Empty)
{
namePrincipal = "Anonymous User";
}
namePrincipal = "User: " + namePrincipal;
string text = new StringBuilder()
.AppendFormat("Assambly: {0}", target).AppendLine()
.AppendFormat("Method: {0}", method.Name).AppendLine().AppendLine()
.AppendFormat("InnerException: {0}" + (result as Exception).InnerException)
.ToString();
string content = Helper.ReadFile(_pathInternal);
try
{
Helper.SaveToFile(namePrincipal, text, content, _pathInternal);
}
catch
{
throw;
}
return null;
}
示例13: CreateLocalsForByRefParams
protected byte CreateLocalsForByRefParams(byte paramArrayIndex, MethodBase invocationInfo)
{
byte numberOfByRefParams = 0;
ParameterInfo[] parameters = invocationInfo.GetParameters();
for (int i = 0; i < ParameterTypes.Length; i++)
{
Type paramType = ParameterTypes[i];
if (paramType.IsByRef)
{
Type type = paramType.GetElementType();
Emit.DeclareLocal(type);
if (!parameters[i].IsOut) // no initialization necessary is 'out' parameter
{
Emit.ldarg(paramArrayIndex)
.ldc_i4(i)
.ldelem_ref
.CastFromObject(type)
.stloc(numberOfByRefParams)
.end();
}
numberOfByRefParams++;
}
}
return numberOfByRefParams;
}
示例14: ExceptionThrowingTest
public ExceptionThrowingTest(TimeSpan runningTime, MethodBase method, Exception thrownException, IObjectInstance instance = null,
IEnumerable<IObjectInstance> arguments = null)
: base(runningTime, method, instance, arguments)
{
if (thrownException == null) throw new ArgumentNullException("thrownException");
Exception = thrownException;
}
示例15: Method
internal Method(MethodBase methodBase, UtilityFactory factory)
{
if (methodBase == null)
throw new ArgumentNullException("methodBase");
this.methodBase = methodBase;
this.factory = factory;
}