本文整理汇总了C#中ICSharpCode.NRefactory.Ast.MemberReferenceExpression类的典型用法代码示例。如果您正苦于以下问题:C# MemberReferenceExpression类的具体用法?C# MemberReferenceExpression怎么用?C# MemberReferenceExpression使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
MemberReferenceExpression类属于ICSharpCode.NRefactory.Ast命名空间,在下文中一共展示了MemberReferenceExpression类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: add_Invocation
//, AstExpression expression)
public static InvocationExpression add_Invocation(this BlockStatement blockStatement, string typeName, string methodName, params object[] parameters)
{
if (methodName.valid().isFalse())
return null;
Expression memberExpression = null;
if (typeName.valid())
memberExpression = new MemberReferenceExpression(new IdentifierExpression(typeName), methodName);
else
memberExpression = new IdentifierExpression(methodName);
var memberReference = new InvocationExpression(memberExpression);
if (parameters != null)
{
var arguments = new List<Expression>();
foreach (var parameter in parameters)
if (parameter is Expression)
arguments.add(parameter as Expression);
else
arguments.add(new PrimitiveExpression(parameter, parameter.str()));
memberReference.Arguments = arguments;
}
blockStatement.append(memberReference.expressionStatement());
return memberReference;
}
示例2: GenerateCode
public override void GenerateCode(List<AbstractNode> nodes, IList items)
{
TypeReference stringReference = new TypeReference("System.String", true);
MethodDeclaration method = new MethodDeclaration {
Name = "ToString",
Modifier = Modifiers.Public | Modifiers.Override,
TypeReference = stringReference,
};
method.Body = new BlockStatement();
Expression target = new MemberReferenceExpression(new TypeReferenceExpression(stringReference),
"Format");
InvocationExpression methodCall = new InvocationExpression(target);
StringBuilder formatString = new StringBuilder();
formatString.Append('[');
formatString.Append(currentClass.Name);
for (int i = 0; i < items.Count; i++) {
formatString.Append(' ');
formatString.Append(codeGen.GetPropertyName(((FieldWrapper)items[i]).Field.Name));
formatString.Append("={");
formatString.Append(i);
formatString.Append('}');
}
formatString.Append(']');
methodCall.Arguments.Add(new PrimitiveExpression(formatString.ToString(), formatString.ToString()));
foreach (FieldWrapper w in items) {
methodCall.Arguments.Add(new MemberReferenceExpression(new ThisReferenceExpression(), w.Field.Name));
}
method.Body.AddChild(new ReturnStatement(methodCall));
nodes.Add(method);
}
示例3: add_MemberReference
//, AstExpression expression)
public static MemberReferenceExpression add_MemberReference(this BlockStatement blockStatement, string memberName, string className)
{
var identifier = new IdentifierExpression(memberName);
var memberReference = new MemberReferenceExpression(identifier, className);
blockStatement.append(memberReference.expressionStatement());
return memberReference;
}
示例4: VisitTypeDeclaration
public override object VisitTypeDeclaration(TypeDeclaration typeDeclaration, object data)
{
base.VisitTypeDeclaration(typeDeclaration, data); // visit methods
typeDeclaration.Attributes.Clear();
typeDeclaration.BaseTypes.Clear();
// add constructor accepting the wrapped object and the field holding the object
FieldDeclaration fd = new FieldDeclaration(null, // no attributes
new TypeReference(typeDeclaration.Name),
Modifiers.Private);
fd.Fields.Add(new VariableDeclaration("wrappedObject"));
typeDeclaration.AddChild(fd);
typeDeclaration.Name += "Wrapper";
if (typeDeclaration.Type == ClassType.Interface) {
typeDeclaration.Type = ClassType.Class;
typeDeclaration.Name = typeDeclaration.Name.Substring(1);
}
ConstructorDeclaration cd = new ConstructorDeclaration(typeDeclaration.Name,
Modifiers.Public,
new List<ParameterDeclarationExpression>(),
null);
cd.Parameters.Add(new ParameterDeclarationExpression(fd.TypeReference,
"wrappedObject"));
// this.wrappedObject = wrappedObject;
Expression fieldReference = new MemberReferenceExpression(new ThisReferenceExpression(),
"wrappedObject");
Expression assignment = new AssignmentExpression(fieldReference,
AssignmentOperatorType.Assign,
new IdentifierExpression("wrappedObject"));
cd.Body = new BlockStatement();
cd.Body.AddChild(new ExpressionStatement(assignment));
typeDeclaration.AddChild(cd);
for (int i = 0; i < typeDeclaration.Children.Count; i++) {
object child = typeDeclaration.Children[i];
if (child is MethodDeclaration) {
MethodDeclaration method = (MethodDeclaration)child;
if (method.Parameters.Count == 0 &&
(method.Name.StartsWith("Is") || method.Name.StartsWith("Get")))
{
// replace the method with a property
PropertyDeclaration prop = new PropertyDeclaration(method.Modifier,
method.Attributes,
method.Name,
null);
prop.TypeReference = method.TypeReference;
prop.GetRegion = new PropertyGetRegion(method.Body, null);
typeDeclaration.Children[i] = prop;
}
}
}
return null;
}
示例5: MethodOnThisReferenceInvocation
public void MethodOnThisReferenceInvocation()
{
// InitializeComponents();
MemberReferenceExpression field = new MemberReferenceExpression(new ThisReferenceExpression(), "InitializeComponents");
InvocationExpression invocation = new InvocationExpression(field, new List<Expression>());
object output = invocation.AcceptVisitor(new CodeDomVisitor(), null);
Assert.IsTrue(output is CodeMethodInvokeExpression);
CodeMethodInvokeExpression mie = (CodeMethodInvokeExpression)output;
Assert.AreEqual("InitializeComponents", mie.Method.MethodName);
Assert.IsTrue(mie.Method.TargetObject is CodeThisReferenceExpression);
}
示例6: VisitMemberReferenceExpression
public override object VisitMemberReferenceExpression(MemberReferenceExpression memberReferenceExpression, object data)
{
if (memberReferenceExpression.TargetObject is IdentifierExpression)
{
var identifier = (IdentifierExpression) memberReferenceExpression.TargetObject;
if (identifier.Identifier == "array" && memberReferenceExpression.MemberName == "Length")
UnlockWith(memberReferenceExpression);
}
return base.VisitMemberReferenceExpression(memberReferenceExpression, data);
}
示例7: InvocationOfStaticMethod
public void InvocationOfStaticMethod()
{
// System.Drawing.Color.FromArgb();
MemberReferenceExpression field = new MemberReferenceExpression(new IdentifierExpression("System"), "Drawing");
field = new MemberReferenceExpression(field, "Color");
field = new MemberReferenceExpression(field, "FromArgb");
InvocationExpression invocation = new InvocationExpression(field, new List<Expression>());
object output = invocation.AcceptVisitor(new CodeDomVisitor(), null);
Assert.IsTrue(output is CodeMethodInvokeExpression);
CodeMethodInvokeExpression mie = (CodeMethodInvokeExpression)output;
Assert.AreEqual("FromArgb", mie.Method.MethodName);
Assert.IsTrue(mie.Method.TargetObject is CodeTypeReferenceExpression);
Assert.AreEqual("System.Drawing.Color", (mie.Method.TargetObject as CodeTypeReferenceExpression).Type.BaseType);
}
示例8: ModifyLambdaForSelect
private static INode ModifyLambdaForSelect(ParenthesizedExpression parenthesizedlambdaExpression,
MemberReferenceExpression target)
{
var parentInvocation = target.TargetObject as InvocationExpression;
if(parentInvocation != null)
{
var parentTarget = parentInvocation.TargetObject as MemberReferenceExpression;
if(parentTarget != null && parentTarget.MemberName == "GroupBy")
{
return new CastExpression(new TypeReference("Func<IGrouping<dynamic,dynamic>, dynamic>"), parenthesizedlambdaExpression, CastType.Cast);
}
}
return new CastExpression(new TypeReference("Func<dynamic, dynamic>"), parenthesizedlambdaExpression, CastType.Cast);
}
示例9: VisitMemberReferenceExpression
public override object VisitMemberReferenceExpression(MemberReferenceExpression memberReferenceExpression, object data)
{
foreach (var forbidden in Members.Where(x => x.Names.Contains(memberReferenceExpression.MemberName)))
{
var identifierExpression = GetTarget(memberReferenceExpression);
if(forbidden.TypeAliases.Contains(identifierExpression) == false)
continue;
var text = QueryParsingUtils.ToText(memberReferenceExpression);
throw new InvalidOperationException(string.Format(forbidden.Error, text));
}
return base.VisitMemberReferenceExpression(memberReferenceExpression, data);
}
示例10: VisitMemberReferenceExpression
public override object VisitMemberReferenceExpression(MemberReferenceExpression memberReferenceExpression, object data)
{
var identifierExpression = memberReferenceExpression.TargetObject as IdentifierExpression;
if (identifierExpression == null || identifierExpression.Identifier != identifier)
return base.VisitMemberReferenceExpression(memberReferenceExpression, data);
var indexerExpression = new IndexerExpression(
memberReferenceExpression.TargetObject,
new List<Expression> { new PrimitiveExpression(memberReferenceExpression.MemberName, memberReferenceExpression.MemberName) });
ReplaceCurrentNode(indexerExpression);
indexerExpression.Parent = memberReferenceExpression.Parent;
return indexerExpression;
}
示例11: GenerateCode
public override void GenerateCode(List<AbstractNode> nodes, IList items)
{
ConstructorDeclaration ctor = new ConstructorDeclaration(currentClass.Name, Modifiers.Public, null, null);
ctor.Body = new BlockStatement();
foreach (FieldWrapper w in items) {
string parameterName = codeGen.GetParameterName(w.Field.Name);
ctor.Parameters.Add(new ParameterDeclarationExpression(ConvertType(w.Field.ReturnType),
parameterName));
Expression left = new MemberReferenceExpression(new ThisReferenceExpression(), w.Field.Name);
Expression right = new IdentifierExpression(parameterName);
Expression expr = new AssignmentExpression(left, AssignmentOperatorType.Assign, right);
ctor.Body.AddChild(new ExpressionStatement(expr));
}
nodes.Add(ctor);
}
示例12: VisitMemberReferenceExpression
public override object VisitMemberReferenceExpression(MemberReferenceExpression memberReferenceExpression, object data)
{
if (memberReferenceExpression.MemberName == "Abort")
{
if (memberReferenceExpression.TargetObject is IdentifierExpression)
{
var id = (IdentifierExpression)memberReferenceExpression.TargetObject;
if (threadVars.Contains(id.Identifier))
{
UnlockWith(memberReferenceExpression);
}
}
}
return base.VisitMemberReferenceExpression(memberReferenceExpression, data);
}
示例13: VisitMemberReferenceExpression
public override object VisitMemberReferenceExpression(MemberReferenceExpression fieldReferenceExpression, object data)
{
ResolveResult fieldRR = base.VisitMemberReferenceExpression(fieldReferenceExpression, data) as ResolveResult;
if (vbMyFormsClass != null && IsReferenceToInstanceMember(fieldRR)) {
TypeResolveResult trr = Resolve(fieldReferenceExpression.TargetObject) as TypeResolveResult;
if (trr != null && trr.ResolvedClass != null) {
foreach (IProperty p in vbMyFormsClass.Properties) {
if (p.ReturnType.FullyQualifiedName == trr.ResolvedClass.FullyQualifiedName) {
fieldReferenceExpression.TargetObject = MakeFieldReferenceExpression("My.MyProject.Forms." + p.Name);
}
}
}
}
return null;
}
示例14: VisitMemberReferenceExpression
public override object VisitMemberReferenceExpression(MemberReferenceExpression memberReferenceExpression, object data)
{
IdentifierExpression id = memberReferenceExpression.TargetObject as IdentifierExpression;
if (id != null) {
if (id.Identifier == "System" || id.Identifier == currentClass) {
ReplaceCurrentNode(new IdentifierExpression(memberReferenceExpression.MemberName));
return null;
}
if (id.Identifier.StartsWith("System.")) {
id.Identifier = id.Identifier.Replace("System.", "");
return null;
}
}
// we can't always remove "this", the field name might conflict with a parameter/local variable
// if (memberReferenceExpression.TargetObject is ThisReferenceExpression) {
// ReplaceCurrentNode(new IdentifierExpression(memberReferenceExpression.MemberName));
// return null;
// }
return base.VisitMemberReferenceExpression(memberReferenceExpression, data);
}
示例15: SimpleNonInvocationExpression
//.........这里部分代码省略.........
#line 1676 "VBNET.ATG"
pexpr = new TypeReferenceExpression(new TypeReference(val, true));
break;
}
case 139: {
lexer.NextToken();
#line 1677 "VBNET.ATG"
pexpr = new ThisReferenceExpression();
break;
}
case 144: case 145: {
#line 1678 "VBNET.ATG"
Expression retExpr = null;
if (la.kind == 144) {
lexer.NextToken();
#line 1679 "VBNET.ATG"
retExpr = new BaseReferenceExpression();
} else if (la.kind == 145) {
lexer.NextToken();
#line 1680 "VBNET.ATG"
retExpr = new ClassReferenceExpression();
} else SynErr(258);
Expect(16);
IdentifierOrKeyword(
#line 1682 "VBNET.ATG"
out name);
#line 1682 "VBNET.ATG"
pexpr = new MemberReferenceExpression(retExpr, name);
break;
}
case 117: {
lexer.NextToken();
Expect(16);
Identifier();
#line 1684 "VBNET.ATG"
type = new TypeReference(t.val ?? "");
#line 1686 "VBNET.ATG"
type.IsGlobal = true;
#line 1687 "VBNET.ATG"
pexpr = new TypeReferenceExpression(type);
break;
}
case 148: {
ObjectCreateExpression(
#line 1688 "VBNET.ATG"
out expr);
#line 1688 "VBNET.ATG"
pexpr = expr;
break;
}
case 81: case 93: case 204: {
#line 1690 "VBNET.ATG"
CastType castType = CastType.Cast;
if (la.kind == 93) {
lexer.NextToken();