本文整理汇总了C#中Args.GetType方法的典型用法代码示例。如果您正苦于以下问题:C# Args.GetType方法的具体用法?C# Args.GetType怎么用?C# Args.GetType使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Args
的用法示例。
在下文中一共展示了Args.GetType方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: ParseExpression
/// <summary>
/// Parses an expression in curlies.
/// </summary>
/// <param name="match"></param>
/// <param name="sender"></param>
/// <param name="e"></param>
/// <returns></returns>
private string ParseExpression(Match match, object sender, object e)
{
string expression = match.Groups["Expression"].Value;
string[] components = expression.Split(new char[] { '.' }, StringSplitOptions.RemoveEmptyEntries);
components = Array.ConvertAll<string, string>(components, delegate(string input)
{
return input.Trim();
});
if (components.Length == 0)
{
return "";
}
// We put this in an object as well so we can evaluate the first "e" or "sender" as a field expression.
object result = new Args(sender, e);
foreach (string component in components)
{
// is this a property?
PropertyInfo propertyInfo = result.GetType().GetProperty(component, ComponentFlags);
if (propertyInfo != null)
{
result = propertyInfo.GetValue(result, null);
}
else
{
// nope, a field?
FieldInfo fieldInfo = result.GetType().GetField(component, ComponentFlags);
if (fieldInfo != null)
{
result = fieldInfo.GetValue(result);
}
else
{
// Oh well :-(
return String.Format("{{Cannot find field or property {0} on object of type {1}}}", component, result.GetType());
}
}
}
return result.ToString();
}