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


C# MethodDeclaration.WithAnnotation方法代码示例

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


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

示例1: CreateMethod

		AttributedNode CreateMethod(MethodDefinition methodDef)
		{
			// Create mapping - used in debugger
			MemberMapping methodMapping = methodDef.CreateCodeMapping(this.CodeMappings);
			
			MethodDeclaration astMethod = new MethodDeclaration();
			astMethod.AddAnnotation(methodDef);
			astMethod.ReturnType = ConvertType(methodDef.ReturnType, methodDef.MethodReturnType);
			astMethod.Name = CleanName(methodDef.Name);
			astMethod.TypeParameters.AddRange(MakeTypeParameters(methodDef.GenericParameters));
			astMethod.Parameters.AddRange(MakeParameters(methodDef));
			// constraints for override and explicit interface implementation methods are inherited from the base method, so they cannot be specified directly
			if (!methodDef.IsVirtual || (methodDef.IsNewSlot && !methodDef.IsPrivate)) astMethod.Constraints.AddRange(MakeConstraints(methodDef.GenericParameters));
			if (!methodDef.DeclaringType.IsInterface) {
				if (!methodDef.HasOverrides) {
					astMethod.Modifiers = ConvertModifiers(methodDef);
					if (methodDef.IsVirtual ^ !methodDef.IsNewSlot) {
						try {
							if (TypesHierarchyHelpers.FindBaseMethods(methodDef).Any())
								astMethod.Modifiers |= Modifiers.New;
						} catch (ReferenceResolvingException) {
							// TODO: add some kind of notification (a comment?) about possible problems with decompiled code due to unresolved references.
						}
					}
				} else {
					astMethod.PrivateImplementationType = ConvertType(methodDef.Overrides.First().DeclaringType);
				}
				astMethod.Body = CreateMethodBody(methodDef, astMethod.Parameters);
			}
			ConvertAttributes(astMethod, methodDef);
			if (methodDef.HasCustomAttributes && astMethod.Parameters.Count > 0) {
				foreach (CustomAttribute ca in methodDef.CustomAttributes) {
					if (ca.AttributeType.Name == "ExtensionAttribute" && ca.AttributeType.Namespace == "System.Runtime.CompilerServices") {
						astMethod.Parameters.First().ParameterModifier = ParameterModifier.This;
					}
				}
			}
			
			// Convert MethodDeclaration to OperatorDeclaration if possible
			if (methodDef.IsSpecialName && !methodDef.HasGenericParameters) {
				OperatorType? opType = OperatorDeclaration.GetOperatorType(methodDef.Name);
				if (opType.HasValue) {
					OperatorDeclaration op = new OperatorDeclaration();
					op.CopyAnnotationsFrom(astMethod);
					op.ReturnType = astMethod.ReturnType.Detach();
					op.OperatorType = opType.Value;
					op.Modifiers = astMethod.Modifiers;
					astMethod.Parameters.MoveTo(op.Parameters);
					astMethod.Attributes.MoveTo(op.Attributes);
					op.Body = astMethod.Body.Detach();
					return op;
				}
			}
			astMethod.WithAnnotation(methodMapping);
			return astMethod;
		}
开发者ID:ThomasZitzler,项目名称:ILSpy,代码行数:56,代码来源:AstBuilder.cs


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