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); }
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)); }
public void AddProperty(ButlerProperty bProperty) { Properties.Add(bProperty); Info = Info.AddMembers(bProperty.Info); AddDependencyRange(bProperty.Dependencies); }