private IEnumerable <ParameterSyntax> getParameters(TypeNameResolver typeNameResolver, params ParameterInfo[] parameters) { foreach (var parameterInfo in parameters) { var parameterSyntax = Parameter(Identifier(parameterInfo.Name)) .WithType(typeNameResolver.ResolveTypeName(parameterInfo.ParameterType)); if (parameterInfo.IsOut) { parameterSyntax = parameterSyntax.AddModifiers(Token(SyntaxKind.OutKeyword)); } else if (parameterInfo.IsIn) { parameterSyntax = parameterSyntax.AddModifiers(Token(SyntaxKind.RefKeyword)); } else if (parameterInfo.IsOptional) { // TODO: Handle optional parameters. (Daniel Potter, 11/8/2017) } else if (parameterInfo.GetCustomAttribute(typeof(ParamArrayAttribute)) != null) { parameterSyntax = parameterSyntax.AddModifiers(Token(SyntaxKind.ParamKeyword)); } yield return(parameterSyntax); } }
private EventFieldDeclarationSyntax getEvent(EventInfo eventInfo, TypeNameResolver typeNameResolver) { return(EventFieldDeclaration(VariableDeclaration( type: typeNameResolver.ResolveTypeName(eventInfo.EventHandlerType), variables: SingletonSeparatedList(VariableDeclarator(eventInfo.Name)) ))); }
private MethodDeclarationSyntax getMethod(MethodInfo methodInfo, TypeNameResolver typeNameResolver) { MethodDeclarationSyntax methodDeclaration = MethodDeclaration(typeNameResolver.ResolveTypeName(methodInfo.ReturnType), methodInfo.Name) .WithParameterList(ParameterList(SeparatedList(getParameters(typeNameResolver, methodInfo.GetParameters())))) .WithSemicolonToken(Token(SyntaxKind.SemicolonToken)); if (methodInfo.IsGenericMethod) { methodDeclaration = methodDeclaration .WithConstraintClauses(List(getTypeConstraints(methodInfo))) .WithTypeParameterList(TypeParameterList(SeparatedList(getTypeParameters(methodInfo)))); } return(methodDeclaration); }
private PropertyDeclarationSyntax getProperty(PropertyInfo propertyInfo, TypeNameResolver typeNameResolver) { IEnumerable <AccessorDeclarationSyntax> getAccessors() { if (propertyInfo.CanRead) { yield return(AccessorDeclaration(SyntaxKind.GetAccessorDeclaration) .WithSemicolonToken(Token(SyntaxKind.SemicolonToken))); } if (propertyInfo.CanWrite) { yield return(AccessorDeclaration(SyntaxKind.SetAccessorDeclaration) .WithSemicolonToken(Token(SyntaxKind.SemicolonToken))); } } return(PropertyDeclaration(typeNameResolver.ResolveTypeName(propertyInfo.PropertyType), propertyInfo.Name) .WithAccessorList(AccessorList(List(getAccessors())))); }
private IndexerDeclarationSyntax getIndexer(PropertyInfo propertyInfo, TypeNameResolver typeNameResolver) { IEnumerable <AccessorDeclarationSyntax> getAccessors() { if (propertyInfo.CanRead) { yield return(AccessorDeclaration(SyntaxKind.GetAccessorDeclaration) .WithSemicolonToken(Token(SyntaxKind.SemicolonToken))); } if (propertyInfo.CanWrite) { yield return(AccessorDeclaration(SyntaxKind.SetAccessorDeclaration) .WithSemicolonToken(Token(SyntaxKind.SemicolonToken))); } } return(IndexerDeclaration(typeNameResolver.ResolveTypeName(propertyInfo.PropertyType)) .WithAccessorList(AccessorList(List(getAccessors()))) .WithParameterList(BracketedParameterList(SeparatedList(getParameters(typeNameResolver, propertyInfo.GetIndexParameters()))))); }