本文整理汇总了C#中System.Reflection.MethodInfo类的典型用法代码示例。如果您正苦于以下问题:C# MethodInfo类的具体用法?C# MethodInfo怎么用?C# MethodInfo使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
MethodInfo类属于System.Reflection命名空间,在下文中一共展示了MethodInfo类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: AddParameterDescriptionsToModel
private void AddParameterDescriptionsToModel(ActionApiDescriptionModel actionModel, MethodInfo method, ApiDescription apiDescription)
{
if (!apiDescription.ParameterDescriptions.Any())
{
return;
}
var matchedMethodParamNames = ArrayMatcher.Match(
apiDescription.ParameterDescriptions.Select(p => p.Name).ToArray(),
method.GetParameters().Select(GetMethodParamName).ToArray()
);
for (var i = 0; i < apiDescription.ParameterDescriptions.Count; i++)
{
var parameterDescription = apiDescription.ParameterDescriptions[i];
var matchedMethodParamName = matchedMethodParamNames.Length > i
? matchedMethodParamNames[i]
: parameterDescription.Name;
actionModel.AddParameter(new ParameterApiDescriptionModel(
parameterDescription.Name,
matchedMethodParamName,
parameterDescription.Type,
parameterDescription.RouteInfo?.IsOptional ?? false,
parameterDescription.RouteInfo?.DefaultValue,
parameterDescription.RouteInfo?.Constraints?.Select(c => c.GetType().Name).ToArray(),
parameterDescription.Source.Id
)
);
}
}
示例2: SqlCallProcedureInfo
public SqlCallProcedureInfo(MethodInfo method, ISerializationTypeInfoProvider typeInfoProvider)
{
if (method == null) {
throw new ArgumentNullException("method");
}
if (typeInfoProvider == null) {
throw new ArgumentNullException("typeInfoProvider");
}
SqlProcAttribute procedure = GetSqlProcAttribute(method);
schemaName = procedure.SchemaName;
name = procedure.Name;
timeout = procedure.Timeout;
deserializeReturnNullOnEmptyReader = procedure.DeserializeReturnNullOnEmptyReader;
deserializeRowLimit = procedure.DeserializeRowLimit;
deserializeCallConstructor = procedure.DeserializeCallConstructor;
SortedDictionary<int, SqlCallParameterInfo> sortedParams = new SortedDictionary<int, SqlCallParameterInfo>();
outArgCount = 0;
foreach (ParameterInfo parameterInfo in method.GetParameters()) {
if ((parameterInfo.GetCustomAttributes(typeof(SqlNameTableAttribute), true).Length > 0) || (typeof(XmlNameTable).IsAssignableFrom(parameterInfo.ParameterType))) {
if (xmlNameTableParameter == null) {
xmlNameTableParameter = parameterInfo;
}
} else {
SqlCallParameterInfo sqlParameterInfo = new SqlCallParameterInfo(parameterInfo, typeInfoProvider, ref outArgCount);
sortedParams.Add(parameterInfo.Position, sqlParameterInfo);
}
}
parameters = sortedParams.Select(p => p.Value).ToArray();
returnTypeInfo = typeInfoProvider.GetSerializationTypeInfo(method.ReturnType);
if ((procedure.UseReturnValue != SqlReturnValue.Auto) || (method.ReturnType != typeof(void))) {
useReturnValue = (procedure.UseReturnValue == SqlReturnValue.ReturnValue) || ((procedure.UseReturnValue == SqlReturnValue.Auto) && (typeInfoProvider.TypeMappingProvider.GetMapping(method.ReturnType).DbType == SqlDbType.Int));
}
}
示例3: GetObjectCall
private static BaseInvokableCall GetObjectCall(UnityEngine.Object target, MethodInfo method, ArgumentCache arguments)
{
System.Type type = typeof(UnityEngine.Object);
if (!string.IsNullOrEmpty(arguments.unityObjectArgumentAssemblyTypeName))
{
System.Type type1 = System.Type.GetType(arguments.unityObjectArgumentAssemblyTypeName, false);
if (type1 != null)
{
type = type1;
}
else
{
type = typeof(UnityEngine.Object);
}
}
System.Type type2 = typeof(CachedInvokableCall<>);
System.Type[] typeArguments = new System.Type[] { type };
System.Type[] types = new System.Type[] { typeof(UnityEngine.Object), typeof(MethodInfo), type };
ConstructorInfo constructor = type2.MakeGenericType(typeArguments).GetConstructor(types);
UnityEngine.Object unityObjectArgument = arguments.unityObjectArgument;
if ((unityObjectArgument != null) && !type.IsAssignableFrom(unityObjectArgument.GetType()))
{
unityObjectArgument = null;
}
object[] parameters = new object[] { target, method, unityObjectArgument };
return (constructor.Invoke(parameters) as BaseInvokableCall);
}
示例4: MethodTokenExpression
public MethodTokenExpression(MethodInfo method)
{
this.method = method;
#if !MONO
declaringType = method.DeclaringType;
#endif
}
示例5: HasSameBaseMethod
private static bool HasSameBaseMethod(MethodInfo first, MethodInfo second)
{
var baseOfFirst = GetBaseDefinition(first);
var baseOfSecond = GetBaseDefinition(second);
return IsSameMethod(baseOfFirst, baseOfSecond);
}
示例6: MethodInvocationValidator
/// <summary>
/// Creates a new <see cref="MethodInvocationValidator"/> instance.
/// </summary>
/// <param name="method">Method to be validated</param>
/// <param name="parameterValues">List of arguments those are used to call the <paramref name="method"/>.</param>
public MethodInvocationValidator(MethodInfo method, object[] parameterValues)
{
_method = method;
_parameterValues = parameterValues;
_parameters = method.GetParameters();
_validationErrors = new List<ValidationResult>();
}
示例7: Verify
/// <summary>
/// Verifies that `x.Equals(y)` 3 times on an instance of the type returns same
/// value, if the supplied method is an override of the
/// <see cref="object.Equals(object)"/>.
/// </summary>
/// <param name="methodInfo">The method to verify</param>
public override void Verify(MethodInfo methodInfo)
{
if (methodInfo == null)
throw new ArgumentNullException("methodInfo");
if (methodInfo.ReflectedType == null ||
!methodInfo.IsObjectEqualsOverrideMethod())
{
// The method is not an override of the Object.Equals(object) method
return;
}
var instance = this.builder.CreateAnonymous(methodInfo.ReflectedType);
var other = this.builder.CreateAnonymous(methodInfo.ReflectedType);
var results = Enumerable.Range(1, 3)
.Select(i => instance.Equals(other))
.ToArray();
if (results.Any(result => result != results[0]))
{
throw new EqualsOverrideException(string.Format(CultureInfo.CurrentCulture,
"The type '{0}' overrides the object.Equals(object) method incorrectly, " +
"calling x.Equals(y) multiple times should return the same value.",
methodInfo.ReflectedType.FullName));
}
}
示例8: CheckMethod
private static void CheckMethod(MethodInfo mainMethod, MethodInfo observableMethod)
{
Assert.Equal(mainMethod.MemberType, observableMethod.MemberType);
Assert.Equal(mainMethod.Name, observableMethod.Name);
CheckParameters(mainMethod, observableMethod);
CheckReturnValue(mainMethod, observableMethod);
}
示例9: ReflectedAsyncActionDescriptor
internal ReflectedAsyncActionDescriptor(MethodInfo asyncMethodInfo, MethodInfo completedMethodInfo, string actionName, ControllerDescriptor controllerDescriptor, bool validateMethods) {
if (asyncMethodInfo == null) {
throw new ArgumentNullException("asyncMethodInfo");
}
if (completedMethodInfo == null) {
throw new ArgumentNullException("completedMethodInfo");
}
if (String.IsNullOrEmpty(actionName)) {
throw Error.ParameterCannotBeNullOrEmpty("actionName");
}
if (controllerDescriptor == null) {
throw new ArgumentNullException("controllerDescriptor");
}
if (validateMethods) {
string asyncFailedMessage = VerifyActionMethodIsCallable(asyncMethodInfo);
if (asyncFailedMessage != null) {
throw new ArgumentException(asyncFailedMessage, "asyncMethodInfo");
}
string completedFailedMessage = VerifyActionMethodIsCallable(completedMethodInfo);
if (completedFailedMessage != null) {
throw new ArgumentException(completedFailedMessage, "completedMethodInfo");
}
}
AsyncMethodInfo = asyncMethodInfo;
CompletedMethodInfo = completedMethodInfo;
_actionName = actionName;
_controllerDescriptor = controllerDescriptor;
_uniqueId = new Lazy<string>(CreateUniqueId);
}
示例10: GetTypeJavaScript
private string GetTypeJavaScript(MethodInfo[] ajaxMethodInfos)
{
StringBuilder javascriptBuilder = new StringBuilder();
javascriptBuilder.Append("// author: lcomplete,\n\n");
javascriptBuilder.AppendFormat("if(typeof {0} ==\"undefined\") {0}={{}};\n", _type.Namespace);
javascriptBuilder.AppendFormat("if(typeof {0}_class ==\"undefined\") {0}_class={{}};\n", _type.FullName);
javascriptBuilder.AppendFormat("{0}_class=function(){{}};\n", _type.FullName);
javascriptBuilder.AppendFormat(
"Object.extend({0}_class.prototype,Object.extend(new Iridescent.AjaxClass(), {{\n", _type.FullName);
foreach (var ajaxMethodInfo in ajaxMethodInfos)
{
var parameters = ajaxMethodInfo.GetParameters();
var joinParameters = (from parameterInfo in parameters
select parameterInfo.Name).ToArray();
javascriptBuilder.AppendFormat("\t{0}:function({1}) {{\n", ajaxMethodInfo.Name,
string.Join(",", joinParameters));
javascriptBuilder.AppendFormat("\t\treturn this.invoke(\"{0}\",{{{1}}},this.{0}.getArguments().slice({2}));\n",
ajaxMethodInfo.Name,
string.Join(",",(from joinParameter in joinParameters
select "\""+joinParameter+"\":"+joinParameter).ToArray()),
parameters.Length);
javascriptBuilder.Append("\t},\n");
}
javascriptBuilder.AppendFormat(
"\turl:\"/Iridescent/Ajax/{0}.ashx\"\n}}));\n", _type.FullName + "," + _type.Assembly.GetName().Name);
javascriptBuilder.AppendFormat("{0}=new {0}_class();", _type.FullName);
return javascriptBuilder.ToString();
}
示例11: checkTransactionProperties
private void checkTransactionProperties( ITransactionAttributeSource tas, MethodInfo method, TransactionPropagation transactionPropagation )
{
ITransactionAttribute ta = tas.ReturnTransactionAttribute( method, null );
Assert.IsTrue( ta != null );
Assert.IsTrue( ta.TransactionIsolationLevel == IsolationLevel.Unspecified );
Assert.IsTrue( ta.PropagationBehavior == transactionPropagation);
}
示例12: RedirectCalls
/// <summary>
/// Redirects all calls from method 'from' to method 'to'.
/// </summary>
/// <param name="from"></param>
/// <param name="to"></param>
public static RedirectCallsState RedirectCalls(MethodInfo from, MethodInfo to)
{
// GetFunctionPointer enforces compilation of the method.
var fptr1 = from.MethodHandle.GetFunctionPointer();
var fptr2 = to.MethodHandle.GetFunctionPointer();
return PatchJumpTo(fptr1, fptr2);
}
示例13: TestUnit
public TestUnit(MethodInfo methodInfo, string description = "")
: this()
{
this.MethodInfo = methodInfo.Name;
this.Name = methodInfo.Name;
this.Description = description;
}
示例14: GenerateCommand
public static SqlCommand GenerateCommand(SqlConnection Connection, MethodInfo Method, object[] Values, CommandType SQLCommandType, string SQLCommandText)
{
if (Method == null)
{
Method = (MethodInfo)new StackTrace().GetFrame(1).GetMethod();
}
SqlCommand command = new SqlCommand();
command.Connection = Connection;
command.CommandType = SQLCommandType;
if (SQLCommandText.Length == 0)
{
command.CommandText = Method.Name;
}
else
{
command.CommandText = SQLCommandText;
}
if (command.CommandType == CommandType.StoredProcedure)
{
GenerateCommandParameters(command, Method, Values);
command.Parameters.Add(ReturnValueParameterName, SqlDbType.Int).Direction = ParameterDirection.ReturnValue;
}
return command;
}
示例15: CallMethod
public static void CallMethod(this ILGenerator generator, MethodInfo methodInfo)
{
if (methodInfo.IsFinal || !methodInfo.IsVirtual)
generator.Emit(OpCodes.Call, methodInfo);
else
generator.Emit(OpCodes.Callvirt, methodInfo);
}