当前位置: 首页>>代码示例>>C#>>正文


C# FieldInfo.Where方法代码示例

本文整理汇总了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);
            }
        }
开发者ID:badamczewski,项目名称:CSpec,代码行数:78,代码来源:CSpecTestRunner.cs

示例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;
 }
开发者ID:wra222,项目名称:testgit,代码行数:10,代码来源:DB.cs


注:本文中的System.Reflection.FieldInfo.Where方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。