本文整理汇总了C#中System.CodeDom.CodeExpression.Property方法的典型用法代码示例。如果您正苦于以下问题:C# CodeExpression.Property方法的具体用法?C# CodeExpression.Property怎么用?C# CodeExpression.Property使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.CodeDom.CodeExpression
的用法示例。
在下文中一共展示了CodeExpression.Property方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: AddVisitCode
static bool AddVisitCode(EasyMethod m, FieldInfo field, CodeExpression var, List<CodeStatement> assertions, bool transformer)
{
CodeExpression prop = var.Property(GetPropertyName(field.Name));
CodeExpression nodeStack = Easy.Var("nodeStack");
if (field.FieldType.FullName.StartsWith("System.Collections.Generic.List")) {
Type elType = field.FieldType.GetGenericArguments()[0];
if (!typeof(INode).IsAssignableFrom(elType))
return false;
assertions.Add(AssertIsNotNull(prop));
string code;
if (transformer) {
code = CreateTransformerLoop(GetCode(prop), ConvertType(elType).BaseType);
} else {
code =
"\t\t\tforeach (" + ConvertType(elType).BaseType + " o in " + GetCode(prop) + ") {\n" +
"\t\t\t\tDebug.Assert(o != null);\n" +
"\t\t\t\to.AcceptVisitor(this, data);\n" +
"\t\t\t}";
}
m.Statements.Add(new CodeSnippetStatement(code));
return true;
}
if (!typeof(INode).IsAssignableFrom(field.FieldType))
return false;
assertions.Add(AssertIsNotNull(prop));
if (transformer) {
m.Statements.Add(nodeStack.InvokeMethod("Push", prop));
}
m.Statements.Add(prop.InvokeMethod("AcceptVisitor",
Easy.This,
Easy.Var("data")));
if (transformer) {
m.Body.Assign(prop, nodeStack.InvokeMethod("Pop").CastTo(ConvertType(field.FieldType)));
}
return true;
}
示例2: AddVisitCode
static bool AddVisitCode(EasyMethod m, FieldInfo field, CodeExpression var, List<CodeStatement> assertions, bool transformer)
{
CodeExpression prop = var.Property(GetPropertyName(field.Name));
CodeExpression nodeStack = Easy.Var("nodeStack");
if (field.FieldType.FullName.StartsWith("System.Collections.Generic.List")) {
Type elType = field.FieldType.GetGenericArguments()[0];
if (!typeof(INode).IsAssignableFrom(elType))
return false;
assertions.Add(IfNullSetFailure(prop));
string code;
string propertyName = GetCode(prop);
if (transformer) {
code = CreateTransformerLoop(propertyName, ConvertType(elType).BaseType);
} else {
code =
"\t\t\tif (" + propertyName + ".Count == data." + GetPropertyName(field.Name) + ".Count) {\n" +
"\t\t\tfor (int i=0; i<" + propertyName + ".Count;i++) {\n" +
"\t\t\t\t" + ConvertType(elType).BaseType + " o = " + propertyName + "[i];\n" +
"\t\t\t\tif(o == null){return SetFailure();}\n" + "\t\t\t\tif((bool)o.AcceptVisitor(this, data." + GetPropertyName(field.Name) + "[i]) == false) return SetFailure();\n" +
"\t\t\t}" +
"\t\t\t}" +
"\t\t\telse { return SetFailure(); }";
}
m.Statements.Add(new CodeSnippetStatement(code));
return true;
}
if (!typeof(INode).IsAssignableFrom(field.FieldType))
return false;
assertions.Add(IfNullSetFailure(prop));
if (transformer) {
m.Statements.Add(nodeStack.InvokeMethod("Push", prop));
}
m.Statements.Add(prop.InvokeMethod("AcceptVisitor",
Easy.This,
Easy.Var("data." + var.Property(GetPropertyName(field.Name)).PropertyName)));
if (transformer) {
m.Body.Assign(prop, nodeStack.InvokeMethod("Pop").CastTo(ConvertType(field.FieldType)));
}
return true;
}