private static void BuildArrayProperty(StringBuilder sb, FilePropertyModel fileProperty, string className) { string nameOfMapVar = Helpers.ToCamelCase(fileProperty.PropertyName, true); if (fileProperty.PropertyType == PropertyType.ClassType) { sb.AppendLine( $"\tconst mapped{fileProperty.PropertyName} = data.{nameOfMapVar}.map(s => new {fileProperty.PropertyTypeName}(s));"); sb.AppendLine( $"\tthis.{nameOfMapVar} = ko.observableArray(mapped{fileProperty.PropertyName});"); } else { sb.AppendLine( $"\tthis.{nameOfMapVar} = ko.observableArray(data.{nameOfMapVar});"); } }
private static void BuildPrimitiveProperty(StringBuilder sb, FilePropertyModel fileProperty) { string nameOfMapVar = Helpers.ToCamelCase(fileProperty.PropertyName, true); if (fileProperty.PropertyType == PropertyType.PrimitiveType) { sb.AppendLine($"\tthis.{nameOfMapVar} = data.{nameOfMapVar};"); } if (fileProperty.PropertyType == PropertyType.ClassType) { sb.AppendLine($"\tthis.{nameOfMapVar} = new {fileProperty.PropertyTypeName}(data.{nameOfMapVar});"); } if (fileProperty.PropertyType == PropertyType.Undefined) { sb.AppendLine($"\t // there is property here called: {nameOfMapVar}. We are unable to parse it for some reason."); } }
public static JSBuilderModel GetBuilderModel(List <FileLinesOverviewModel> listOfProperties) { JSBuilderModel retModel = new JSBuilderModel { FileClasses = new List <FileClassModel>() }; // Get all unique class names var uniqeClassNamesList = listOfProperties .DistinctBy(s => s.ClassName) .Select(s => s.ClassName) .ToList(); foreach (var cName in uniqeClassNamesList) { // Insert first class name var tempFileClassModel = new FileClassModel { ClassName = cName, FileProperties = new List <FilePropertyModel>() }; // Find their properties var listOfClassProperties = listOfProperties .Where(s => s.ClassName.ToLower().Trim().Contains(cName.ToLower().Trim())).ToList(); // Then insert their properties foreach (var property in listOfClassProperties) { FilePropertyModel tempFilePropertyModel = new FilePropertyModel { PropertyType = property.LineType.PropertyType, IsArray = property.LineType.IsArray, PropertyName = property.PropertyName, PropertyTypeName = property.LineType.PropertyTypeName }; tempFileClassModel.FileProperties.Add(tempFilePropertyModel); } retModel.FileClasses.Add(tempFileClassModel); } return(retModel); }