本文整理汇总了C#中System.Reflection.MethodInfo类的典型用法代码示例。如果您正苦于以下问题:C# MethodInfo类的具体用法?C# MethodInfo怎么用?C# MethodInfo使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
MethodInfo类属于System.Reflection命名空间,在下文中一共展示了MethodInfo类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的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
)
);
}
}
开发者ID:vytautask,项目名称:aspnetboilerplate,代码行数:31,代码来源:AspNetCoreApiDescriptionModelProvider.cs
示例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));
}
}
开发者ID:avonwyss,项目名称:bsn-modulestore,代码行数:33,代码来源:SqlCallProcedureInfo.cs
示例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);
}
开发者ID:randomize,项目名称:VimConfig,代码行数:27,代码来源:PersistentCall.cs
示例4: MethodTokenExpression
public MethodTokenExpression(MethodInfo method)
{
this.method = method;
#if !MONO
declaringType = method.DeclaringType;
#endif
}
开发者ID:vbedegi,项目名称:Castle.Core,代码行数:7,代码来源:MethodTokenExpression.cs
示例5: HasSameBaseMethod
private static bool HasSameBaseMethod(MethodInfo first, MethodInfo second)
{
var baseOfFirst = GetBaseDefinition(first);
var baseOfSecond = GetBaseDefinition(second);
return IsSameMethod(baseOfFirst, baseOfSecond);
}
开发者ID:bluePlayer,项目名称:FakeItEasy,代码行数:7,代码来源:MethodInfoManager.cs
示例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>();
}
开发者ID:lizhi5753186,项目名称:BDF,代码行数:12,代码来源:MethodInvocationValidator.cs
示例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));
}
}
开发者ID:RyanLiu99,项目名称:AutoFixture,代码行数:33,代码来源:EqualsSuccessiveAssertion.cs
示例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);
}
开发者ID:naveensrinivasan,项目名称:octokit.net,代码行数:7,代码来源:SyncObservableClients.cs
示例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);
}
开发者ID:nobled,项目名称:mono,代码行数:32,代码来源:ReflectedAsyncActionDescriptor.cs
示例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();
}
开发者ID:lcomplete,项目名称:Iridescent,代码行数:29,代码来源:TypeJavascriptHandler.cs
示例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);
}
开发者ID:Binodesk,项目名称:spring-net,代码行数:7,代码来源:TransactionAttributeSourceEditorTests.cs
示例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);
}
开发者ID:earalov,项目名称:Skylines-NaturalResourcesBrush,代码行数:12,代码来源:RedirectionHelper.cs
示例13: TestUnit
public TestUnit(MethodInfo methodInfo, string description = "")
: this()
{
this.MethodInfo = methodInfo.Name;
this.Name = methodInfo.Name;
this.Description = description;
}
开发者ID:pmizel,项目名称:DevMentor.TestEngine,代码行数:7,代码来源:TestUnit.cs
示例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;
}
开发者ID:huayang912,项目名称:cs-dotnetnuke,代码行数:29,代码来源:SqlCommandGenerator.cs
示例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);
}
开发者ID:modulexcite,项目名称:FluentHtml,代码行数:7,代码来源:ILGeneratorExtensions.cs
示例16: IsSameMethod
private static bool IsSameMethod(MethodInfo first, MethodInfo second)
{
return first.DeclaringType == second.DeclaringType
&& first.MetadataToken == second.MetadataToken
&& first.Module == second.Module
&& first.GetGenericArguments().SequenceEqual(second.GetGenericArguments());
}
开发者ID:bluePlayer,项目名称:FakeItEasy,代码行数:7,代码来源:MethodInfoManager.cs
示例17: GetMethodInterceptors
protected IList<IInterceptor> GetMethodInterceptors(MethodInfo Method)
{
if (this.MethodInterceptorRegistrations.ContainsKey(Method))
return this.MethodInterceptorRegistrations[Method];
else
return null;
}
开发者ID:robinli,项目名称:TheOrigin,代码行数:7,代码来源:DynamicProxyBase.cs
示例18: GetInterceptedMethod
private static MethodInfo GetInterceptedMethod(MethodInfo interceptionMethod)
{
var parameterTypes = from parameter in interceptionMethod.GetParameters()
select parameter.ParameterType;
return interceptionMethod.DeclaringType.GetMethod(interceptionMethod.GetMethodNameWithoutTilde(), parameterTypes.ToArray());
}
开发者ID:handcraftsman,项目名称:BlackBoxRecorder,代码行数:7,代码来源:DependencyPlayback.cs
示例19: ParameterizedMethodSuite
/// <summary>
/// Construct from a MethodInfo
/// </summary>
/// <param name="method"></param>
public ParameterizedMethodSuite(MethodInfo method)
: base(method.ReflectedType.FullName, method.Name)
{
this.maintainTestOrder = true;
this.isTheory = Reflect.HasAttribute(method, NUnitFramework.TheoryAttribute, true);
this.method = method;
}
开发者ID:rmterra,项目名称:AutoTest.Net,代码行数:11,代码来源:ParameterizedTestMethodSuite.cs
示例20: DefineMethod
public static MethodBuilder DefineMethod(this TypeBuilder typeBuilder, MethodInfo method, MethodAttributes? attributes = null, ParameterInfo[] parameters = null)
{
Type[] parametersTypes = null;
MethodBuilder methodBuilder = null;
parameters = parameters ?? method.GetParameters();
parametersTypes = parameters.ToArray(parameter => parameter.ParameterType);
attributes = attributes ?? method.Attributes & ~MethodAttributes.Abstract;
methodBuilder = typeBuilder.DefineMethod(method.Name, attributes.Value, method.ReturnType, parametersTypes);
parameters.ForEach(1, (parameter, i) => {
var parameterBuilder = methodBuilder.DefineParameter(i, parameter.Attributes, parameter.Name);
if (parameter.IsDefined<ParamArrayAttribute>()) {
parameterBuilder.SetCustomAttribute<ParamArrayAttribute>();
}
else if (parameter.IsOut) {
parameterBuilder.SetCustomAttribute<OutAttribute>();
}
else if (parameter.IsOptional) {
parameterBuilder.SetCustomAttribute<OptionalAttribute>()
.SetConstant(parameter.DefaultValue);
}
});
return methodBuilder;
}
开发者ID:sagifogel,项目名称:NCop,代码行数:27,代码来源:ReflectionUtils.cs
注:本文中的System.Reflection.MethodInfo类示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论