本文整理汇总了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();
// " for quotes
// ' 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;
}
示例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);
}