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


C# Reflector.Eval方法代码示例

本文整理汇总了C#中Reflector.Eval方法的典型用法代码示例。如果您正苦于以下问题:C# Reflector.Eval方法的具体用法?C# Reflector.Eval怎么用?C# Reflector.Eval使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Reflector的用法示例。


在下文中一共展示了Reflector.Eval方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: Run

        public override object Run(object obj, string[] parameters, IPropertyBag bag, IMarkupBase markup)
        {
            if (parameters == null || (parameters.Length < 2 || parameters.Length > 3))
                throw new ImpressionInterpretException("Filter " + Keyword + " expects 2 or 3 parameters.", markup);

            // text field to bind to
            // selected value

            // text field to bind to
            // value field to bind to
            // selected value

            if (obj == null)
                return null;

            if (obj.GetType().GetInterface("IEnumerable") != null) {

                IReflector reflector = new Reflector();

                bool textOnly = parameters.Length == 2;
                string textField = parameters[0];
                string selectedField = textOnly ? parameters[1] : parameters[2];

                StringBuilder optionBuilder = new StringBuilder();
                IEnumerator en = ((IEnumerable) obj).GetEnumerator();

                // &#34; for quotes
                // &#39; for apostrophes

                // lookup the selected value
                object selectedObject = bag == null ? null : reflector.Eval(bag, selectedField);
                string selectedValue = selectedObject != null ? selectedObject.ToString() : null;

                if (textOnly) {
                    while (en.MoveNext()) {
                        object current = en.Current;
                        object textObject = reflector.Eval(current, textField);
                        string textString = textObject != null ? textObject.ToString() : null;
                        string selected = (textString == selectedValue) ? " selected=\"true\"" : "";
                        optionBuilder.AppendFormat("<option{1}>{0}</option>", textString, selected);
                    }
                } else {
                    string valueField = parameters[1];

                    while(en.MoveNext()) {
                        object current = en.Current;
                        object textObject = reflector.Eval(current, textField);
                        string textString = textObject != null ? textObject.ToString() : null;
                        object valueObject = reflector.Eval(current, valueField);
                        string valueString = valueObject != null ? valueObject.ToString() : null;

                        string selected = (valueString == selectedValue) ? " selected=\"true\"" : "";
                        optionBuilder.AppendFormat("<option value=\"{0}\"{2}>{1}</option>", valueString, textString, selected);
                    }
                }
                return optionBuilder.ToString();
            }

            return null;
        }
开发者ID:codesoda,项目名称:Impression,代码行数:60,代码来源:HtmlOptionsFilter.cs

示例2: TestEvalLookup

        public void TestEvalLookup()
        {
            Reflector rf = new Reflector();

            object value = rf.Eval(robj, "IntField");
            Assert.AreEqual(1, value);

            value = rf.Eval(robj, "IntProperty");
            Assert.AreEqual(1, value);

            value = rf.Eval(robj, "StringField");
            Assert.AreEqual("String", value);

            value = rf.Eval(robj, "StringProperty");
            Assert.AreEqual("String", value);

            value = rf.Eval(robj, "NameValues");
            Assert.IsNotNull(value);

            value = rf.Eval(robj, "IntKeyDictionary");
            Assert.IsNotNull(value);

            value = rf.Eval(robj, "UnknownField");
            Assert.IsNull(value);

            value = rf.Eval(robj, "StringProperty.Length");
            Assert.AreEqual(6, value);

            value = rf.Eval(robj, new [] { "StringProperty", "Length"});
            Assert.AreEqual(6, value);

            value = rf.Eval(robj, "IntKeyDictionary.1");
            Assert.AreEqual("Value1", value);

            value = rf.Eval(robj, "IntKeyDictionary.1.Length");
            Assert.AreEqual(6, value);

            value = rf.Eval(robj, "StringKeyDictionary.Key2");
            Assert.AreEqual("Value2", value);

            value = rf.Eval(robj, "StringKeyDictionary.Key3.Length");
            Assert.AreEqual(6, value);
        }
开发者ID:codesoda,项目名称:Impression,代码行数:43,代码来源:ReflectorTests.cs


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