本文整理汇总了C#中System.GetParameters方法的典型用法代码示例。如果您正苦于以下问题:C# System.GetParameters方法的具体用法?C# System.GetParameters怎么用?C# System.GetParameters使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System
的用法示例。
在下文中一共展示了System.GetParameters方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: HasTestCasesFor
public bool HasTestCasesFor(System.Reflection.MethodInfo method)
{
if (method.GetParameters().Length == 0)
return false;
foreach (ParameterInfo parameter in method.GetParameters())
if (!dataPointProvider.HasDataFor(parameter))
return false;
return true;
}
示例2: GetInstance
public override object GetInstance(System.Reflection.ConstructorInfo constructor, object[] parameters = null)
{
if (cache.ContainsKey(constructor.DeclaringType))
{
return cache[constructor.DeclaringType];
}
var dependencies = constructor.GetParameters();
if (dependencies.Count() == 0)
{
var instance = Activator.CreateInstance(constructor.DeclaringType);
cache.Add(constructor.DeclaringType, instance);
return instance;
}
else
{
if (parameters == null || parameters.Count() != dependencies.Count())
{
throw new Exception("Incorrect number of parameters to invoke instance.");
}
var instance = constructor.Invoke(parameters);
cache.Add(constructor.DeclaringType, instance);
return instance;
}
}
示例3: LogicalMethodInfo
private LogicalMethodInfo(System.Reflection.MethodInfo beginMethodInfo, System.Reflection.MethodInfo endMethodInfo, WebMethod webMethod)
{
this.methodInfo = beginMethodInfo;
this.endMethodInfo = endMethodInfo;
this.methodName = beginMethodInfo.Name.Substring(5);
if (webMethod != null)
{
this.binding = webMethod.binding;
this.attribute = webMethod.attribute;
this.declaration = webMethod.declaration;
}
ParameterInfo[] parameters = beginMethodInfo.GetParameters();
if (((parameters.Length < 2) || (parameters[parameters.Length - 1].ParameterType != typeof(object))) || (parameters[parameters.Length - 2].ParameterType != typeof(AsyncCallback)))
{
throw new InvalidOperationException(Res.GetString("WebMethodMissingParams", new object[] { beginMethodInfo.DeclaringType.FullName, beginMethodInfo.Name, typeof(AsyncCallback).FullName, typeof(object).FullName }));
}
this.stateParam = parameters[parameters.Length - 1];
this.callbackParam = parameters[parameters.Length - 2];
this.inParams = GetInParameters(beginMethodInfo, parameters, 0, parameters.Length - 2, true);
ParameterInfo[] paramInfos = endMethodInfo.GetParameters();
this.resultParam = paramInfos[0];
this.outParams = GetOutParameters(endMethodInfo, paramInfos, 1, paramInfos.Length - 1, true);
this.parameters = new ParameterInfo[this.inParams.Length + this.outParams.Length];
this.inParams.CopyTo(this.parameters, 0);
this.outParams.CopyTo(this.parameters, this.inParams.Length);
this.retType = endMethodInfo.ReturnType;
this.isVoid = this.retType == typeof(void);
this.attributes = new Hashtable();
}
示例4: CreateParameters
/// <summary>
/// 创建一个ParameterCollection
/// </summary>
/// <param name="method"></param>
/// <param name="jsonString"></param>
/// <returns></returns>
public static ParameterCollection CreateParameters(System.Reflection.MethodInfo method, string jsonString)
{
if (!string.IsNullOrEmpty(jsonString))
{
JObject obj = JObject.Parse(jsonString);
if (obj.Count > 0)
{
var pis = method.GetParameters();
object[] parameters = new object[pis.Length];
var index = 0;
foreach (var p in pis)
{
var property = obj.Properties().SingleOrDefault(o => string.Compare(o.Name, p.Name, true) == 0);
if (property != null)
{
//获取Json值
string value = property.Value.ToString(Newtonsoft.Json.Formatting.None);
object jsonValue = CoreHelper.ConvertJsonValue(p.ParameterType, value);
parameters[index] = jsonValue;
}
index++;
}
//创建参数集合
return CreateParameters(method, parameters);
}
}
//如果json检测不通过,返回空的参数集合
return new ParameterCollection();
}
示例5: IsValidForRequest
public override bool IsValidForRequest(ControllerContext controllerContext, System.Reflection.MethodInfo methodInfo)
{
var methodParams = methodInfo.GetParameters();
foreach (var parameterInfo in methodParams)
{
if (parameterInfo.HasDefaultValue)
{
continue;
}
var paramType = parameterInfo.ParameterType;
if (!IsSimpleType(paramType))
{
continue;
}
var value = controllerContext.Controller.ValueProvider.GetValue(parameterInfo.Name);
if (value == null || value.AttemptedValue == null || !CanParse(value.AttemptedValue, paramType, value.Culture))
{
return false;
}
}
return true;
}
示例6: GetArgsString
private StringBuilder GetArgsString(System.Reflection.MethodInfo method)
{
var sb = new StringBuilder();
foreach (var arg in method.GetParameters())
sb.Append(string.Format("{0} {1}, ", arg.ParameterType.Name, arg.Name));
return sb;
}
示例7: CompositionException
public CompositionException(System.Reflection.MethodBase Method,string message, System.Exception innerException):this(String.Format("{0}\r\nAssembly:{1}\r\n{2}:{3}\r\nArgs:\r\n",message,Method.ReflectedType.AssemblyQualifiedName,Method.MemberType.ToString(),Method.Name),innerException)
{
System.Reflection.ParameterInfo[] parameters = Method.GetParameters();
for(int i = 0; i<parameters.Length; i++)
{
_message = String.Format("{0}\t{1}({2})\r\n",_message,parameters[i].Name,parameters[i].ParameterType.ToString());
}
}
示例8: GenerateMethodCall
protected override void GenerateMethodCall(StringBuilder js, System.Reflection.MethodInfo method, string Controller, bool documentate)
{
var jsattribute = method.DeclaringType.GetCustomAttributes(typeof(JsActionAttribute), false).First() as JsActionAttribute;
if (groups.Count(str => string.IsNullOrEmpty(str) == false) > 0 && jsattribute.Groups.Split(',').Intersect(groups).Count() == 0)
return;
var pars = method.GetParameters();
var parameters = string.Join(",", pars.Select(m => m.Name));
if (parameters.Length > 0)
parameters += ',';
js.AppendFormat("{0}:function({1}options)", method.Name, parameters);
pars.FirstOrDefault(m =>
{
if (m.ParameterType.IsGenericType)
ComplexTypeList.Value.Add(m.ParameterType.GetGenericArguments().First());
else if (this.FindIEnumerable(m.ParameterType) == null && m.ParameterType != typeof(DateTime) && m.ParameterType != typeof(DateTimeOffset) && m.ParameterType.IsPrimitive == false)
ComplexTypeList.Value.Add(m.ParameterType);
return false;
});
js.Append('{');
if (documentate)
{
//Method can be empty.
this.DocumentateTheFunction(js, method);
js.Append("},");
return;
}
string url = RouteTable.Routes.GetVirtualPath(this.requestContext, new RouteValueDictionary(new { httproute = "", controller = Controller })).VirtualPath;
StringBuilder jsondata = new StringBuilder();
foreach (var parameter in pars)
{
jsondata.AppendFormat("{0}:{0},", parameter.Name);
}
if (jsondata.Length > 0)
jsondata.Remove(jsondata.Length - 1, 1);
string requestmethod = string.Empty;
if (method.Name.StartsWith("GET", StringComparison.InvariantCultureIgnoreCase))
requestmethod = "GET";
else if (method.Name.StartsWith("POST", StringComparison.InvariantCultureIgnoreCase))
requestmethod = "POST";
else if (method.Name.StartsWith("PUT", StringComparison.InvariantCultureIgnoreCase))
requestmethod = "PUT";
else if (method.Name.StartsWith("DELETE", StringComparison.InvariantCultureIgnoreCase))
requestmethod = "DELETE";
js.AppendFormat("var opts={{success:trd,url:\"{0}\",async:{4},cache:{3},type:\"{1}\",data:$.toDictionary({{{2}}})}};", url, requestmethod, jsondata, jsattribute.CacheRequest == true ? "true" : "false", jsattribute.Async == true ? "true" : "false");
js.Append("jQuery.extend(opts,options);return jQuery.ajax(opts);},");
}
示例9: MethodToString
private static string MethodToString(System.Reflection.MethodInfo method)
{
return (method.ReturnType == null ? "void" : method.ReturnType.Name)
+ " "
+ method.Name
+ "("
+ method.GetParameters()
.GroupConcat(", ", p => (p.IsOut ? "out " : "") + p.ParameterType.Name + " " + p.Name + (p.IsOptional ? " = " + (p.DefaultValue ?? "null").ToString() : ""))
+ ")";
}
示例10: Method
public Method(System.Reflection.MethodInfo theMethod) {
method = theMethod;
var methodArguments = method.GetParameters();
arguments = new Argument[methodArguments.Length];
for (var i = 0; i < methodArguments.Length; ++i) {
arguments[i] = new Argument();
arguments[i].name = methodArguments[i].Name;
arguments[i].type = methodArguments[i].ParameterType;
}
}
示例11: Execute
public Result Execute(ICommunicationObject client, string service, System.Reflection.MethodBase method, params object[] data)
{
RemoteInvokeArgs info = new RemoteInvokeArgs();
info.Interface = service;
int index = method.Name.LastIndexOf('.');
index = index>0?(index+1):0;
info.Method = method.Name.Substring(index, method.Name.Length - index);
info.Parameters = data;
info.CommunicationObject = client;
info.ParameterInfos = method.GetParameters();
foreach (System.Reflection.ParameterInfo pi in method.GetParameters())
{
info.ParameterTypes.Add(pi.ParameterType.Name);
}
return Handler.Execute(info);
}
示例12: SetRefParameters
/// <summary>
/// 设置ParameterCollection值
/// </summary>
/// <param name="method"></param>
/// <param name="collection"></param>
/// <param name="parameters"></param>
public static void SetRefParameters(System.Reflection.MethodInfo method, ParameterCollection collection, object[] parameters)
{
int index = 0;
foreach (var p in method.GetParameters())
{
if (p.ParameterType.IsByRef)
collection[p.Name] = parameters[index];
index++;
}
}
示例13: SetRefParameterValues
/// <summary>
/// 设置参数值
/// </summary>
/// <param name="method"></param>
/// <param name="collection"></param>
/// <param name="parameters"></param>
public static void SetRefParameterValues(System.Reflection.MethodInfo method, ParameterCollection collection, object[] parameters)
{
var index = 0;
foreach (var p in method.GetParameters())
{
//给参数赋值
if (p.ParameterType.IsByRef)
parameters[index] = collection[p.Name];
index++;
}
}
示例14: CompileTimeValidate
public override bool CompileTimeValidate(System.Reflection.MethodBase method)
{
var parameters = method.GetParameters().ToArray();
for (var i = 0; i < parameters.Length; i++)
if (this._arguments[i] != parameters[i].ParameterType)
{
var msg = string.Format(ArgumentValidationAspect._INVALID_ARGUMENT, _paramNames);
throw new ArgumentException(msg, parameters[i].Name);
}
return true;
}
示例15: BuilderMethod
private void BuilderMethod(System.Reflection.MethodInfo method)
{
List<string> ps = new List<string>();
List<string> tps = new List<string>();
ParameterInfo[] pis = method.GetParameters();
foreach (ParameterInfo pi in method.GetParameters())
{
tps.Add(pi.Name);
string pt = "";
if (pi.IsRetval)
pt = "ref";
if (pi.IsOut)
pt = "out";
ps.Add(string.Format(" {0} {1} {2}", pt, GetTypeName(pi.ParameterType), pi.Name));
}
mCode.AppendFormat("public {0} {1}({2})\r\n", method.ReturnType.FullName == "System.Void" ? "void" :GetTypeName( method.ReturnType),
method.Name, ps.Count == 0 ? "" : string.Join(",", ps.ToArray()));
mCode.AppendLine("{");
foreach (ParameterInfo pi in method.GetParameters())
{
if (pi.IsOut)
mCode.AppendFormat("{0}=default({1});\r\n", pi.Name, GetTypeName( pi.ParameterType));
}
mCode.AppendFormat("Result result = ProxyFactory.CursorFactory.Execute(this,\"{1}\",System.Reflection.MethodInfo.GetCurrentMethod(),{0});",
tps.Count == 0 ? "new object[0]" : string.Join(",", tps.ToArray()),mInterfaceType.Name);
for (int i = 0; i < ps.Count; i++)
{
if (ps[i].IndexOf("ref") >= 0 || ps[i].IndexOf("out")>=0)
{
mCode.AppendFormat("{0}=({1})result[\"{0}\"];", tps[i], GetTypeName( pis[i].ParameterType));
}
}
if (method.ReturnType.FullName != "System.Void")
{
mCode.AppendFormat("return ({0})result.Data;\r\n",GetTypeName( method.ReturnType));
}
mCode.AppendLine("}");
}