private static AccessorDeclarationSyntax GenerateGetter(CsField csElement, PropertyValueGetTransform valueTransformation) { ExpressionSyntax valueExpression = ParseName(csElement.IntermediateMarshalName); return(AccessorDeclaration(SyntaxKind.GetAccessorDeclaration) .WithExpressionBody( ArrowExpressionClause( valueTransformation != null ? valueTransformation(GeneratorHelpers.WrapInParentheses(valueExpression)) : valueExpression ) ) .WithSemicolonToken(Token(SyntaxKind.SemicolonToken))); }
private static PropertyValueGetTransform Compose(PropertyValueGetTransform second, PropertyValueGetTransform first) { if (second == null) { return(first); } if (first == null) { return(second); } return(x => { var value = first(x); return second(GeneratorHelpers.WrapInParentheses(value)); }); }
private PropertyDeclarationSyntax GenerateProperty(CsField csElement, TypeSyntax propertyType, PropertyValueGetTransform getterTransform, PropertyValueSetTransform setterTransform) => AddDocumentationTrivia( PropertyDeclaration(propertyType, csElement.Name) .WithAccessorList( AccessorList( List( new[] { GenerateGetter(csElement, getterTransform), GenerateSetter(csElement, setterTransform) } ) ) ) .WithModifiers(csElement.VisibilityTokenList), csElement );