本文整理汇总了C#中InvocationExpression.AddAnnotation方法的典型用法代码示例。如果您正苦于以下问题:C# InvocationExpression.AddAnnotation方法的具体用法?C# InvocationExpression.AddAnnotation怎么用?C# InvocationExpression.AddAnnotation使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类InvocationExpression
的用法示例。
在下文中一共展示了InvocationExpression.AddAnnotation方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: VisitBinaryOperatorExpression
public override void VisitBinaryOperatorExpression (BinaryOperatorExpression binaryOperatorExpression)
{
base.VisitBinaryOperatorExpression (binaryOperatorExpression);
var leftT = GetTypeDef (binaryOperatorExpression.Left);
if (leftT != null && !(leftT.IsPrimitive || leftT.FullName=="System.String")) {
var name = "";
switch (binaryOperatorExpression.Operator) {
case BinaryOperatorType.Add:
name = "op_Addition";
break;
case BinaryOperatorType.Subtract:
name = "op_Subtraction";
break;
case BinaryOperatorType.Multiply:
name = "op_Multiply";
break;
case BinaryOperatorType.Divide:
name = "op_Division";
break;
case BinaryOperatorType.Equality:
name = "op_Equality";
break;
case BinaryOperatorType.InEquality:
name = "op_Inequality";
break;
case BinaryOperatorType.LessThan:
name = "op_LessThan";
break;
case BinaryOperatorType.LessThanOrEqual:
name = "op_LessThanOrEqual";
break;
case BinaryOperatorType.GreaterThan:
name = "op_GreaterThan";
break;
case BinaryOperatorType.GreaterThanOrEqual:
name = "op_GreaterThanOrEqual";
break;
}
var m = FindMethod (leftT, name);
if (m != null && m.DeclaringType.FullName != "System.MulticastDelegate") {
var left = binaryOperatorExpression.Left;
var right = binaryOperatorExpression.Right;
left.Remove ();
right.Remove ();
var n = new InvocationExpression (
new MemberReferenceExpression (new IdentifierExpression (leftT.Name), name),
left, right);
n.AddAnnotation (m.ReturnType);
binaryOperatorExpression.ReplaceWith (n);
}
}
}
示例2: VisitInvocationExpression
public override void VisitInvocationExpression (InvocationExpression invocationExpression)
{
base.VisitInvocationExpression (invocationExpression);
var memberReferenceExpression = invocationExpression.Target as MemberReferenceExpression;
if (memberReferenceExpression == null)
return;
var t = GetTypeRef (memberReferenceExpression.Target);
if (t == null)
return;
HashSet<string> repls = null;
string newTypeName = null;
if (t.FullName == "System.Object") {
repls = objectRepls;
newTypeName = "NObject";
} else if (t.FullName == "System.String") {
repls = stringRepls;
newTypeName = "NString";
} else if (t.FullName == "System.Boolean") {
repls = boolRepls;
newTypeName = "NBoolean";
} else if (t != null && t.IsPrimitive) {
repls = numberRepls;
newTypeName = "NNumber";
}
if (repls != null && repls.Contains (memberReferenceExpression.MemberName)) {
if (memberReferenceExpression.MemberName == "Equals") {
var left = memberReferenceExpression.Target;
var right = invocationExpression.Arguments.First ();
left.Remove ();
right.Remove ();
invocationExpression.ReplaceWith (new BinaryOperatorExpression (left, BinaryOperatorType.Equality, right));
} else {
var newName = memberReferenceExpression.MemberName;
if (newTypeName == "NObject") {
newName = "Generic" + newName;
}
var n = new InvocationExpression (
new MemberReferenceExpression (
new TypeReferenceExpression (new SimpleType (newTypeName)),
newName),
new Expression[] { memberReferenceExpression.Target.Clone () }
.Concat (invocationExpression.Arguments.Select (x => x.Clone ())));
var td = t.Resolve ();
var meth = td.Methods.First (x => x.Name == memberReferenceExpression.MemberName);
n.AddAnnotation (meth.ReturnType);
invocationExpression.ReplaceWith (n);
}
}
}