Пример #1
0
 public StaticModelTypeProvider(string rootNamespace, string assemblyName, INamingRule namingRule, ISchemaProvider schemaProvider)
 {
     _rootNamespace  = rootNamespace;
     _assemblyName   = assemblyName;
     _namingRule     = namingRule;
     _schemaProvider = schemaProvider;
 }
Пример #2
0
 public StaticModelTypeProvider(string rootNamespace, string assemblyName, INamingRule namingRule, ISchemaProvider schemaProvider)
 {
     _rootNamespace = rootNamespace;
     _assemblyName = assemblyName;
     _namingRule = namingRule;
     _schemaProvider = schemaProvider;
 }
Пример #3
0
 public VeilViewEngine(ICacheProvider cacheProvider,
                       IHelperHandlerFactory helperHandlerFactory,
                       INamingRule namingRule)
 {
     _cacheProvider        = cacheProvider;
     _helperHandlerFactory = helperHandlerFactory;
     _memberLocator        = new MemberLocatorFromNamingRule(namingRule);
 }
Пример #4
0
 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;
		}
Пример #6
0
 public MemberLocatorFromNamingRule(INamingRule namingRule)
 {
     _namingRule = namingRule;
 }
Пример #7
0
 public void Init()
 {
     _namingRule = new NamingRule();
 }
Пример #8
0
		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;
		}
Пример #9
0
		public JsonSchemaCodeGenerator(INamingRule namingRule)
		{
			_namingRule = namingRule;
		}
Пример #10
0
		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;
		}
Пример #11
0
		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");
			}
		}
Пример #12
0
		public void Init()
		{
			_namingRule = new NamingRule();
		}
 public JsonSchemaCodeGenerator(INamingRule namingRule)
 {
     _namingRule = 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);
        }
        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);
        }