本文整理汇总了C#中System.Reflection.FieldInfo.Where方法的典型用法代码示例。如果您正苦于以下问题:C# FieldInfo.Where方法的具体用法?C# FieldInfo.Where怎么用?C# FieldInfo.Where使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Reflection.FieldInfo
的用法示例。
在下文中一共展示了FieldInfo.Where方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: RunOperation
/// <summary>
/// Runs the operations for a type, that inherit one of the Facade classes.
/// </summary>
/// <param name="testItem">CspecTestItem that describes the status of the running test</param>
/// <param name="fields">class fields</param>
/// <param name="description">the @it operation</param>
/// <param name="obj">object that represents the spec</param>
/// <param name="describedObject">the object that's beeing described</param>
private void RunOperation(CSpecTestItem testItem, FieldInfo[] fields, Action<string> description, object obj, object describedObject)
{
MethodInfo beforeOp = null;
MethodInfo afterOp = null;
ProxyTrace trace = null;
Type objType = obj.GetType();
//Now call the operation methods.
foreach (var field in fields.Where(x => x.FieldType.Name == "DescribeAll"
|| x.FieldType.Name == "Describe"
))
{
Delegate testRunner = (Delegate)field.GetValue(obj);
testItem.Name = field.Name;
if (BeforeOperation != null)
BeforeOperation(testItem);
beforeOp = objType.GetMethod("BeforeOperation", BindingFlags.NonPublic | BindingFlags.Instance);
afterOp = objType.GetMethod("AfterOperation", BindingFlags.NonPublic | BindingFlags.Instance);
if (beforeOp != null)
beforeOp.Invoke(obj, null);
try
{
if (describedObject != null && describedObject.GetType().GetInterfaces().Length != 0)
{
trace = (ProxyTrace)describedObject.GetType().GetField("trace").GetValue(describedObject);
trace = new ProxyTrace();
describedObject.GetType().GetField("trace").SetValue(describedObject, trace);
//put to lookup
//NOTE: when doing multithreaded runners the entire section of this code
//should be locked by monitor
//NOTE: Moved to CSpecFacade constructor, it has much more sence there
//CurrentDescribedObject = describedObject;
}
if (field.FieldType.Name == "DescribeAll")
{
if (describedObject != null)
testRunner.DynamicInvoke(description, describedObject);
else
testRunner.DynamicInvoke(description);
}
else
{
ItAttribute it = (ItAttribute)field.GetCustomAttributes(typeof(ItAttribute), false)[0];
Console.WriteLine(it.Description);
testRunner.DynamicInvoke(null);
}
testItem.Results = "Test Passed!";
testItem.TestSucceed = true;
if (AfterOperation != null)
AfterOperation(testItem);
Passed++;
}
catch (System.Exception ex)
{
HandleRunnerException(ex, testItem, trace);
}
if (afterOp != null)
afterOp.Invoke(obj, null);
}
}
示例2: TransField
private static string TransField(FieldInfo[] fieldInfos, string prop)
{
//FieldInfo fi = type.GetField("fn_" + prop);
FieldInfo fi = fieldInfos.Where(x => x.Name == fn_ + prop).FirstOrDefault();
if (fi != null)
{
return (string)fi.GetValue(null);
}
return string.Empty;
}