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


C# BaseReferenceExpression.AddAnnotation方法代码示例

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


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

示例1: TransformCall

		AstNode TransformCall(bool isVirtual, ILExpression byteCode, List<Ast.Expression> args)
		{
			IMethod cecilMethod = (IMethod)byteCode.Operand;
			MethodDef cecilMethodDef = cecilMethod.Resolve();
			Ast.Expression target;
			List<Ast.Expression> methodArgs = new List<Ast.Expression>(args);
			if (cecilMethod.MethodSig != null && cecilMethod.MethodSig.HasThis) {
				target = methodArgs[0];
				methodArgs.RemoveAt(0);
				
				// Unpack any DirectionExpression that is used as target for the call
				// (calling methods on value types implicitly passes the first argument by reference)
				target = UnpackDirectionExpression(target);
				
				if (cecilMethodDef != null) {
					// convert null.ToLower() to ((string)null).ToLower()
					if (target is NullReferenceExpression)
						target = target.CastTo(AstBuilder.ConvertType(cecilMethod.DeclaringType));
					
					if (cecilMethodDef.DeclaringType.IsInterface) {
						TypeSig tr = byteCode.Arguments[0].InferredType;
						if (tr != null) {
							TypeDef td = tr.Resolve();
							if (td != null && !td.IsInterface) {
								// Calling an interface method on a non-interface object:
								// we need to introduce an explicit cast
								target = target.CastTo(AstBuilder.ConvertType(cecilMethod.DeclaringType));
							}
						}
					}
				}
			} else {
				target = new TypeReferenceExpression { Type = AstBuilder.ConvertType(cecilMethod.DeclaringType) };
			}
			if (target is ThisReferenceExpression && !isVirtual) {
				// a non-virtual call on "this" might be a "base"-call.
				if (cecilMethod.DeclaringType != null && cecilMethod.DeclaringType.ScopeType.ResolveTypeDef() != this.methodDef.DeclaringType) {
					// If we're not calling a method in the current class; we must be calling one in the base class.
					target = new BaseReferenceExpression();
					target.AddAnnotation(cecilMethod.DeclaringType);
				}
			}
			
			if (cecilMethod.Name == ".ctor" && DnlibExtensions.IsValueType(cecilMethod.DeclaringType)) {
				// On value types, the constructor can be called.
				// This is equivalent to 'target = new ValueType(args);'.
				ObjectCreateExpression oce = new ObjectCreateExpression();
				oce.Type = AstBuilder.ConvertType(cecilMethod.DeclaringType);
				oce.AddAnnotation(cecilMethod);
				AdjustArgumentsForMethodCall(cecilMethod, methodArgs);
				oce.Arguments.AddRange(methodArgs);
				return new AssignmentExpression(target, oce);
			}
			
			if (cecilMethod.Name == "Get" && (cecilMethod.DeclaringType.TryGetArraySig() != null || cecilMethod.DeclaringType.TryGetSZArraySig() != null) && methodArgs.Count > 1) {
				return target.Indexer(methodArgs);
			} else if (cecilMethod.Name == "Set" && (cecilMethod.DeclaringType.TryGetArraySig() != null || cecilMethod.DeclaringType.TryGetSZArraySig() != null) && methodArgs.Count > 2) {
				return new AssignmentExpression(target.Indexer(methodArgs.GetRange(0, methodArgs.Count - 1)), methodArgs.Last());
			}
			
			// Test whether the method is an accessor:
			if (cecilMethodDef != null) {
				if (methodArgs.Count == 0 && cecilMethodDef.IsGetter) {
					foreach (var prop in cecilMethodDef.DeclaringType.Properties) {
						if (prop.GetMethod == cecilMethodDef)
							return target.Member(prop.Name, prop).WithAnnotation(prop).WithAnnotation(cecilMethod);
					}
				} else if (cecilMethodDef.IsGetter) { // with parameters
					PropertyDef indexer = GetIndexer(cecilMethodDef);
					if (indexer != null)
						return target.Indexer(methodArgs).WithAnnotation(indexer).WithAnnotation(cecilMethod);
				} else if (methodArgs.Count == 1 && cecilMethodDef.IsSetter) {
					foreach (var prop in cecilMethodDef.DeclaringType.Properties) {
						if (prop.SetMethod == cecilMethodDef)
							return new Ast.AssignmentExpression(target.Member(prop.Name, prop).WithAnnotation(prop).WithAnnotation(cecilMethod), methodArgs[0]);
					}
				} else if (methodArgs.Count > 1 && cecilMethodDef.IsSetter) {
					PropertyDef indexer = GetIndexer(cecilMethodDef);
					if (indexer != null)
						return new AssignmentExpression(
							target.Indexer(methodArgs.GetRange(0, methodArgs.Count - 1)).WithAnnotation(indexer).WithAnnotation(cecilMethod),
							methodArgs[methodArgs.Count - 1]
						);
				} else if (methodArgs.Count == 1 && cecilMethodDef.IsAddOn) {
					foreach (var ev in cecilMethodDef.DeclaringType.Events) {
						if (ev.AddMethod == cecilMethodDef) {
							return new Ast.AssignmentExpression {
								Left = target.Member(ev.Name, ev).WithAnnotation(ev).WithAnnotation(cecilMethod),
								Operator = AssignmentOperatorType.Add,
								Right = methodArgs[0]
							};
						}
					}
				} else if (methodArgs.Count == 1 && cecilMethodDef.IsRemoveOn) {
					foreach (var ev in cecilMethodDef.DeclaringType.Events) {
						if (ev.RemoveMethod == cecilMethodDef) {
							return new Ast.AssignmentExpression {
								Left = target.Member(ev.Name, ev).WithAnnotation(ev).WithAnnotation(cecilMethod),
								Operator = AssignmentOperatorType.Subtract,
								Right = methodArgs[0]
//.........这里部分代码省略.........
开发者ID:nakijun,项目名称:dnSpy,代码行数:101,代码来源:AstMethodBodyBuilder.cs


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