Exemplo n.º 1
0
		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;
		}
Exemplo n.º 2
0
		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;
		}