當前位置: 首頁>>代碼示例>>C#>>正文


C# MethodDefinition.CreateCodeMapping方法代碼示例

本文整理匯總了C#中Mono.Cecil.MethodDefinition.CreateCodeMapping方法的典型用法代碼示例。如果您正苦於以下問題:C# MethodDefinition.CreateCodeMapping方法的具體用法?C# MethodDefinition.CreateCodeMapping怎麽用?C# MethodDefinition.CreateCodeMapping使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在Mono.Cecil.MethodDefinition的用法示例。


在下文中一共展示了MethodDefinition.CreateCodeMapping方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的C#代碼示例。

示例1: CreateConstructor

		ConstructorDeclaration CreateConstructor(MethodDefinition methodDef)
		{
			// Create mapping - used in debugger
			MemberMapping methodMapping = methodDef.CreateCodeMapping(this.CodeMappings);
			
			ConstructorDeclaration astMethod = new ConstructorDeclaration();
			astMethod.AddAnnotation(methodDef);
			astMethod.Modifiers = ConvertModifiers(methodDef);
			if (methodDef.IsStatic) {
				// don't show visibility for static ctors
				astMethod.Modifiers &= ~Modifiers.VisibilityMask;
			}
			astMethod.Name = CleanName(methodDef.DeclaringType.Name);
			astMethod.Parameters.AddRange(MakeParameters(methodDef));
			astMethod.Body = CreateMethodBody(methodDef, astMethod.Parameters);
			ConvertAttributes(astMethod, methodDef);
			astMethod.WithAnnotation(methodMapping);
			return astMethod;
		}
開發者ID:ThomasZitzler,項目名稱:ILSpy,代碼行數:19,代碼來源:AstBuilder.cs

示例2: 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


注:本文中的Mono.Cecil.MethodDefinition.CreateCodeMapping方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。