public StaticModelTypeProvider(string rootNamespace, string assemblyName, INamingRule namingRule, ISchemaProvider schemaProvider) { _rootNamespace = rootNamespace; _assemblyName = assemblyName; _namingRule = namingRule; _schemaProvider = schemaProvider; }
public VeilViewEngine(ICacheProvider cacheProvider, IHelperHandlerFactory helperHandlerFactory, INamingRule namingRule) { _cacheProvider = cacheProvider; _helperHandlerFactory = helperHandlerFactory; _memberLocator = new MemberLocatorFromNamingRule(namingRule); }
public HttpComponentInfo(string propertyName, HttpComponentAttribute attribute, INamingRule namingRule) { Name = string.IsNullOrWhiteSpace(attribute.Alias) ? namingRule?.Naming(propertyName) ?? propertyName : attribute.Alias; Attribute = attribute; }
public MemberLocatorFromNamingRule(INamingRule namingRule) { _namingRule = namingRule; }
public void Init() { _namingRule = new NamingRule(); }
public static string GenerateClass(JSchema schema, Dictionary<string, MemberDeclarationSyntax> typeContext, string propertyName, INamingRule namingRule) { if (schema.Type == JSchemaType.Object) { var className = namingRule.GetClassName(schema, propertyName); if (typeContext.ContainsKey(className)) return className; if (string.IsNullOrEmpty(className)) throw new Exception("Title not set"); var classDeclaration = Syntax.ClassDeclaration( Syntax.Identifier(className)) .WithModifiers(new SyntaxTokenList().Add(Syntax.Token(SyntaxKind.PublicKeyword))) .WithKeyword( Syntax.Token(SyntaxKind.ClassKeyword, Syntax.TriviaList(Syntax.Space))) .WithOpenBraceToken( Syntax.Token(SyntaxKind.OpenBraceToken)) .WithMembers(new SyntaxList<MemberDeclarationSyntax>().AddProperties(schema, typeContext, namingRule)) .WithCloseBraceToken( Syntax.Token(SyntaxKind.CloseBraceToken)); typeContext.Add(className, classDeclaration); return className; } return null; }
public JsonSchemaCodeGenerator(INamingRule namingRule) { _namingRule = namingRule; }
public static SyntaxList<MemberDeclarationSyntax> AddProperties(this SyntaxList<MemberDeclarationSyntax> memberList, JSchema schema, Dictionary<string, MemberDeclarationSyntax> typeContext, INamingRule namingRule) { var result = memberList; if (schema.Properties != null) { foreach (var property in schema.Properties) { var propertyName = namingRule.GetPropertyName(property.Key); result = result.Add(Syntax.PropertyDeclaration( GetPropertyType(property.Value, typeContext, propertyName, namingRule).WithTrailingTrivia(Syntax.Space), propertyName) .WithModifiers(new SyntaxTokenList().Add(Syntax.Token(SyntaxKind.PublicKeyword))) .WithAccessorList(Syntax.AccessorList(Syntax.List( Syntax.AccessorDeclaration(SyntaxKind.GetAccessorDeclaration) .WithSemicolonToken(Syntax.Token(SyntaxKind.SemicolonToken)), Syntax.AccessorDeclaration(SyntaxKind.SetAccessorDeclaration) .WithSemicolonToken(Syntax.Token(SyntaxKind.SemicolonToken)) )))); } } return result; }
private static TypeSyntax GetPropertyType(JSchema value, Dictionary<string, MemberDeclarationSyntax> typeContext, string propertyName, INamingRule namingRule) { switch (value.Type) { case JSchemaType.String: return Syntax.ParseTypeName("string"); case JSchemaType.Integer: return Syntax.ParseTypeName("int"); case JSchemaType.Number: return Syntax.ParseTypeName("double"); case JSchemaType.Boolean: return Syntax.ParseTypeName("bool"); case JSchemaType.Array: var valueType = value.Items.FirstOrDefault(); var name = namingRule.GetClassNameFromArrayItem(value, propertyName); var genericType = GetPropertyType(valueType, typeContext, name, namingRule); return Syntax.QualifiedName(GetQualifiedName("System", "Collections", "Generic"), Syntax.GenericName(Syntax.Identifier("IList"), Syntax.TypeArgumentList(Syntax.SeparatedList(genericType)))); case JSchemaType.Object: var className = GenerateClass(value, typeContext, propertyName, namingRule); return Syntax.IdentifierName(className); default: return Syntax.ParseTypeName("object"); } }
public static string GenerateClass(JSchema schema, Dictionary <string, MemberDeclarationSyntax> typeContext, string propertyName, INamingRule namingRule) { if (schema.Type == JSchemaType.Object) { var className = namingRule.GetClassName(schema, propertyName); if (typeContext.ContainsKey(className)) { return(className); } if (string.IsNullOrEmpty(className)) { throw new Exception("Title not set"); } var classDeclaration = Syntax.ClassDeclaration( Syntax.Identifier(className)) .WithModifiers(new SyntaxTokenList().Add(Syntax.Token(SyntaxKind.PublicKeyword))) .WithKeyword( Syntax.Token(SyntaxKind.ClassKeyword, Syntax.TriviaList(Syntax.Space))) .WithOpenBraceToken( Syntax.Token(SyntaxKind.OpenBraceToken)) .WithMembers(new SyntaxList <MemberDeclarationSyntax>().AddProperties(schema, typeContext, namingRule)) .WithCloseBraceToken( Syntax.Token(SyntaxKind.CloseBraceToken)); typeContext.Add(className, classDeclaration); return(className); } return(null); }
private static TypeSyntax GetPropertyType(JSchema value, Dictionary <string, MemberDeclarationSyntax> typeContext, string propertyName, INamingRule namingRule) { switch (value.Type) { case JSchemaType.String: return(Syntax.ParseTypeName("string")); case JSchemaType.Integer: return(Syntax.ParseTypeName("int")); case JSchemaType.Number: return(Syntax.ParseTypeName("double")); case JSchemaType.Boolean: return(Syntax.ParseTypeName("bool")); case JSchemaType.Array: var valueType = value.Items.FirstOrDefault(); var name = namingRule.GetClassNameFromArrayItem(value, propertyName); var genericType = GetPropertyType(valueType, typeContext, name, namingRule); return(Syntax.QualifiedName(GetQualifiedName("System", "Collections", "Generic"), Syntax.GenericName(Syntax.Identifier("IList"), Syntax.TypeArgumentList(Syntax.SeparatedList(genericType))))); case JSchemaType.Object: var className = GenerateClass(value, typeContext, propertyName, namingRule); return(Syntax.IdentifierName(className)); default: return(Syntax.ParseTypeName("object")); } }
public static SyntaxList <MemberDeclarationSyntax> AddProperties(this SyntaxList <MemberDeclarationSyntax> memberList, JSchema schema, Dictionary <string, MemberDeclarationSyntax> typeContext, INamingRule namingRule) { var result = memberList; if (schema.Properties != null) { foreach (var property in schema.Properties) { var propertyName = namingRule.GetPropertyName(property.Key); result = result.Add(Syntax.PropertyDeclaration( GetPropertyType(property.Value, typeContext, propertyName, namingRule).WithTrailingTrivia(Syntax.Space), propertyName) .WithModifiers(new SyntaxTokenList().Add(Syntax.Token(SyntaxKind.PublicKeyword))) .WithAccessorList(Syntax.AccessorList(Syntax.List( Syntax.AccessorDeclaration(SyntaxKind.GetAccessorDeclaration) .WithSemicolonToken(Syntax.Token(SyntaxKind.SemicolonToken)), Syntax.AccessorDeclaration(SyntaxKind.SetAccessorDeclaration) .WithSemicolonToken(Syntax.Token(SyntaxKind.SemicolonToken)) )))); } } return(result); }