コード例 #1
0
        MethodDeclaration ConvertMethod(IMethod method)
        {
            MethodDeclaration decl = new MethodDeclaration();
            decl.Modifiers = GetMemberModifiers(method);
            if (method.IsAsync && ShowModifiers)
                decl.Modifiers |= Modifiers.Async;
            if (ShowAttributes) {
                decl.Attributes.AddRange (method.Attributes.Select ((a) => new AttributeSection (ConvertAttribute (a))));
                decl.Attributes.AddRange (method.ReturnTypeAttributes.Select ((a) => new AttributeSection (ConvertAttribute (a)) {
                    AttributeTarget = "return"
                }));
            }
            if (AddResolveResultAnnotations) {
                decl.AddAnnotation(new MemberResolveResult(null, method));
            }
            decl.ReturnType = ConvertType(method.ReturnType);
            decl.Name = method.Name;

            if (this.ShowTypeParameters) {
                foreach (ITypeParameter tp in method.TypeParameters) {
                    decl.TypeParameters.Add(ConvertTypeParameter(tp));
                }
            }

            foreach (IParameter p in method.Parameters) {
                decl.Parameters.Add(ConvertParameter(p));
            }
            if (method.IsExtensionMethod && method.ReducedFrom == null && decl.Parameters.Any() && decl.Parameters.First().ParameterModifier == ParameterModifier.None)
                decl.Parameters.First().ParameterModifier = ParameterModifier.This;

            if (this.ShowTypeParameters && this.ShowTypeParameterConstraints && !method.IsOverride && !method.IsExplicitInterfaceImplementation) {
                foreach (ITypeParameter tp in method.TypeParameters) {
                    var constraint = ConvertTypeParameterConstraint(tp);
                    if (constraint != null)
                        decl.Constraints.Add(constraint);
                }
            }
            decl.Body = GenerateBodyBlock();
            decl.PrivateImplementationType = GetExplicitInterfaceType (method);
            return decl;
        }
コード例 #2
0
ファイル: AstBuilder.cs プロジェクト: eldersantos/ILSpy
		MethodDeclaration CreateMethod(MethodDefinition methodDef)
		{
			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.Parameters));
			astMethod.Constraints.AddRange(MakeConstraints(methodDef.GenericParameters));
			if (!methodDef.DeclaringType.IsInterface) {
				if (!methodDef.HasOverrides)
					astMethod.Modifiers = ConvertModifiers(methodDef);
				else
					astMethod.PrivateImplementationType = ConvertType(methodDef.Overrides.First().DeclaringType);
				astMethod.Body = AstMethodBodyBuilder.CreateMethodBody(methodDef, context);
			}
			ConvertAttributes(astMethod, methodDef);
			return astMethod;
		}
コード例 #3
0
        MethodDeclaration ConvertMethod(IMethod method)
        {
            MethodDeclaration decl = new MethodDeclaration();
            decl.Modifiers = GetMemberModifiers(method);
            if (method.IsAsync && ShowModifiers)
                decl.Modifiers |= Modifiers.Async;
            if (ShowAttributes) {
                decl.Attributes.AddRange (method.Attributes.Select ((a) => new AttributeSection (ConvertAttribute (a))));
                decl.Attributes.AddRange (method.ReturnTypeAttributes.Select ((a) => new AttributeSection (ConvertAttribute (a)) {
                    AttributeTarget = "return"
                }));
            }
            if (AddResolveResultAnnotations) {
                decl.AddAnnotation(new MemberResolveResult(null, method));
            }
            decl.ReturnType = ConvertType(method.ReturnType);
            decl.Name = method.Name;

            if (this.ShowTypeParameters) {
                foreach (ITypeParameter tp in method.TypeParameters) {
                    decl.TypeParameters.Add(ConvertTypeParameter(tp));
                }
            }

            foreach (IParameter p in method.Parameters) {
                decl.Parameters.Add(ConvertParameter(p));
            }
            if (method.IsExtensionMethod && method.ReducedFrom == null && decl.Parameters.Any() && decl.Parameters.First().ParameterModifier == ParameterModifier.None)
                decl.Parameters.First().ParameterModifier = ParameterModifier.This;

            if (this.ShowTypeParameters && this.ShowTypeParameterConstraints && !method.IsOverride && !method.IsExplicitInterfaceImplementation) {
                foreach (ITypeParameter tp in method.TypeParameters) {
                    var constraint = ConvertTypeParameterConstraint(tp);
                    if (constraint != null)
                        decl.Constraints.Add(constraint);
                }
            }
            decl.Body = GenerateBodyBlock();
            decl.PrivateImplementationType = GetExplicitInterfaceType (method);
            return decl;
        }
コード例 #4
0
ファイル: AstBuilder.cs プロジェクト: petr-k/ILSpy
 MethodDeclaration CreateMethod(MethodDefinition methodDef)
 {
     MethodDeclaration astMethod = new MethodDeclaration();
     astMethod.AddAnnotation(methodDef);
     astMethod.ReturnType = ConvertType(methodDef.ReturnType, methodDef.MethodReturnType);
     astMethod.Name = methodDef.Name;
     astMethod.TypeParameters.AddRange(MakeTypeParameters(methodDef.GenericParameters));
     astMethod.Parameters.AddRange(MakeParameters(methodDef.Parameters));
     astMethod.Constraints.AddRange(MakeConstraints(methodDef.GenericParameters));
     if (!methodDef.DeclaringType.IsInterface) {
         astMethod.Modifiers = ConvertModifiers(methodDef);
         astMethod.Body = AstMethodBodyBuilder.CreateMethodBody(methodDef, context);
     }
     return astMethod;
 }
コード例 #5
0
ファイル: CsToTs.cs プロジェクト: RReverser/Netjs
			public override void VisitPropertyDeclaration (PropertyDeclaration p)
			{
				if (p.Getter != null && p.Getter.Body.IsNull && p.Setter != null && p.Setter.Body.IsNull) {

					var f = new FieldDeclaration {
						Modifiers = p.Modifiers,
						ReturnType = p.ReturnType.Clone (),
					};
					f.Variables.Add (new VariableInitializer (p.Name));
					p.ReplaceWith (f);
				} else {

					foreach (var a in p.Children.OfType<Accessor> ()) {
//						a.Body.Remove ();

						var getter = a.Role == PropertyDeclaration.GetterRole;

						var fun = new MethodDeclaration {
							Body = (BlockStatement)a.Body.Clone(),
							Name = (getter ? "get " : "set ") + p.Name,
							Modifiers = p.Modifiers,
						};
						fun.AddAnnotation (a);

						if (getter) {
							fun.ReturnType = p.ReturnType.Clone ();
						}
						else {
							fun.ReturnType = new PrimitiveType ("void");
							fun.Parameters.Add (new ParameterDeclaration {
								Name = "value",
								Type = p.ReturnType.Clone (),
							});
						}

						p.Parent.InsertChildAfter (p, fun, Roles.TypeMemberRole);
					}

					p.Remove ();

				}
			}
コード例 #6
0
ファイル: AstBuilder.cs プロジェクト: ThomasZitzler/ILSpy
		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;
		}
コード例 #7
0
ファイル: AstBuilder.cs プロジェクト: liquidboy/ILSpy
		MethodDeclaration CreateMethod(MethodDefinition methodDef)
		{
			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.Parameters));
			astMethod.Constraints.AddRange(MakeConstraints(methodDef.GenericParameters));
			if (!methodDef.DeclaringType.IsInterface) {
				if (!methodDef.HasOverrides)
					astMethod.Modifiers = ConvertModifiers(methodDef);
				else
					astMethod.PrivateImplementationType = ConvertType(methodDef.Overrides.First().DeclaringType);
				astMethod.Body = AstMethodBodyBuilder.CreateMethodBody(methodDef, context, 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;
					}
				}
			}
			return astMethod;
		}