Exemplo n.º 1
0
        public static ButlerClass Create(string className, string path, JToken jToken)
        {
            ButlerClass bClass = new ButlerClass(className, path);

            bClass.SetAccessibility(ButlerAccessibility.Public);

            foreach (JToken childToken in jToken.Children())
            {
                ButlerProperty bProperty = ButlerPropertyFactory.Create(childToken);
                bProperty.SetAccessibility(ButlerAccessibility.Public);
                bProperty.AddAccessor(ButlerAccessorType.Get, ButlerAccessibility.Public);
                bProperty.AddAccessor(ButlerAccessorType.Set, ButlerAccessibility.Private);
                bProperty.AddAttribute("JsonProperty", $"\"{bProperty.Id}\"");

                bClass.AddProperty(bProperty);
            }

            ButlerConstructor bConstructor = ButlerConstructorFactory.Create(bClass);

            bConstructor.AddPropertyParameterRange(bClass.Properties);
            bConstructor.AddAttribute("JsonConstructor");

            bClass.AddConstructor(bConstructor);

            return(bClass);
        }
Exemplo n.º 2
0
        public void AddPropertyParameter(ButlerProperty bProperty)
        {
            if (!_owner.Properties.Contains(bProperty))
            {
                throw new Exception($"Property with name {bProperty.Name} cannot be set through {_owner.Name} constructor if it hasn't been defined in class.");
            }

            string propertyName  = bProperty.Name;
            string parameterName = propertyName.ToCamelCase();

            ParameterSyntax parameterInfo = SyntaxFactory.Parameter(SyntaxFactory.Identifier(parameterName)).WithType(bProperty.Info.Type);

            Info = Info.AddParameterListParameters(parameterInfo);

            ExpressionSyntax           lhs = SyntaxFactory.IdentifierName(propertyName);
            ExpressionSyntax           rhs = SyntaxFactory.IdentifierName(parameterName);
            AssignmentExpressionSyntax assignmentExpression = SyntaxFactory.AssignmentExpression(SyntaxKind.SimpleAssignmentExpression, lhs, rhs);

            Info = Info.AddBodyStatements(SyntaxFactory.ExpressionStatement(assignmentExpression));
        }
Exemplo n.º 3
0
 public void AddProperty(ButlerProperty bProperty)
 {
     Properties.Add(bProperty);
     Info = Info.AddMembers(bProperty.Info);
     AddDependencyRange(bProperty.Dependencies);
 }