private static string GetDefaultColumnWidth(PropertyInfo propertyInfo) { propertyInfo.CheckArgument(nameof(propertyInfo)); var result = "100%"; var propertyHelper = new ContractPropertyHelper(propertyInfo); if (propertyHelper.Property.Name.Equals("Id")) { result = "60px"; } else if (propertyHelper.Property.Name.EndsWith("Id") && (propertyHelper.Property.PropertyType.Equals(typeof(int)) || propertyHelper.Property.PropertyType.Equals(typeof(int?)))) { result = "60px"; } else if (propertyInfo.PropertyType.IsEnum) { result = "100%"; } else if (propertyInfo.PropertyType.IsNumericType()) { result = "100px"; } else if (propertyInfo.PropertyType.Equals(typeof(string))) { result = "100%"; } return(result); }
/// <summary> /// Diese Methode erstellt den Programmcode einer Eigenschaft (Partial-Full-Property). /// </summary> /// <param name="propertyInfo">Das Eigenschaftsinfo-Objekt.</param> /// <returns>Die Eigenschaft als Text.</returns> internal static IEnumerable <string> CreatePartialProperty(PropertyInfo propertyInfo) { propertyInfo.CheckArgument(nameof(propertyInfo)); var result = new List <string>(); var contractPropertyHelper = new ContractPropertyHelper(propertyInfo); var defaultValue = contractPropertyHelper.DefaultValue; var fieldType = contractPropertyHelper.PropertyFieldType; var fieldName = contractPropertyHelper.PropertyFieldName; var paramName = contractPropertyHelper.PropertyFieldName; result.Add(string.Empty); SetPropertyAttributes(propertyInfo.DeclaringType, propertyInfo, result); result.Add($"public {fieldType} {propertyInfo.Name}"); result.Add("{"); result.AddRange(CreatePartialGetProperty(propertyInfo)); result.AddRange(CreatePartialSetProperty(propertyInfo)); result.Add("}"); GetPropertyDefaultValue(propertyInfo.DeclaringType, propertyInfo, ref defaultValue); result.Add(string.IsNullOrEmpty(defaultValue) ? $"private {fieldType} {fieldName};" : $"private {fieldType} {fieldName} = {defaultValue};"); result.Add($"partial void On{propertyInfo.Name}Reading();"); result.Add($"partial void On{propertyInfo.Name}Changing(ref bool handled, ref {fieldType} {paramName});"); result.Add($"partial void On{propertyInfo.Name}Changed();"); return(result); }
public static bool IsPropertyCreatable(PropertyInfo propertyInfo) { propertyInfo.CheckArgument(nameof(propertyInfo)); var propertyHelper = new ContractPropertyHelper(propertyInfo); return(propertyHelper.HasImplementation == false); }
/// <summary> /// Diese Methode erstellt den Programmcode einer Eigenschaft (Auto-Property oder Partial-Full-Property). /// </summary> /// <param name="propertyInfo">Das Eigenschaftsinfo-Objekt.</param> /// <returns>Die Eigenschaft als Text.</returns> internal static IEnumerable <string> CreateProperty(PropertyInfo propertyInfo) { propertyInfo.CheckArgument(nameof(propertyInfo)); IEnumerable <string> result; var contractPropertyHelper = new ContractPropertyHelper(propertyInfo); if (contractPropertyHelper.IsAutoProperty) { result = CreateAutoProperty(propertyInfo); } else { result = CreatePartialProperty(propertyInfo); } return(result); }
/// <summary> /// Diese Methode erstellt den Programmcode einer Eigenschaft (Auto-Property). /// </summary> /// <param name="propertyInfo">Das Eigenschaftsinfo-Objekt.</param> /// <returns>Die Eigenschaft als Text.</returns> internal static IEnumerable <string> CreateAutoProperty(PropertyInfo propertyInfo) { propertyInfo.CheckArgument(nameof(propertyInfo)); var result = new List <string>(); var contractPropertyHelper = new ContractPropertyHelper(propertyInfo); var defaultValue = contractPropertyHelper.DefaultValue; var fieldType = contractPropertyHelper.PropertyFieldType; result.Add(string.Empty); SetPropertyAttributes(propertyInfo.DeclaringType, propertyInfo, result); result.Add($"public {fieldType} {propertyInfo.Name}"); result.Add(string.IsNullOrEmpty(defaultValue) ? "{ get; set; }" : "{ get; set; }" + $" = {defaultValue};"); GetPropertyDefaultValue(propertyInfo.DeclaringType, propertyInfo, ref defaultValue); return(result); }
public static RazorBuilder CreateGridColumn(PropertyInfo propertyInfo) { var result = default(RazorBuilder); var handled = false; BeginCreateGridColumn(propertyInfo, ref result, ref handled); if (handled == false) { var propertyHelper = new ContractPropertyHelper(propertyInfo); if (propertyHelper.Property.Name.Equals("Id")) { result = CreateIdGridColumn(propertyInfo); } else if (propertyHelper.Property.Name.EndsWith("Id") && (propertyHelper.Property.PropertyType.Equals(typeof(int)) || propertyHelper.Property.PropertyType.Equals(typeof(int?)))) { result = CreateIdGridColumn(propertyInfo); } else if (propertyInfo.PropertyType.IsEnum) { result = CreateEnumGridColumn(propertyInfo); } else if (propertyInfo.PropertyType.IsNumericType()) { result = CreateNumericGridColumn(propertyInfo); } else if (propertyInfo.PropertyType.Equals(typeof(DateTime)) || propertyInfo.PropertyType.Equals(typeof(DateTime?))) { result = CreateDateTimeGridColumn(propertyInfo); } else if (propertyInfo.PropertyType.Equals(typeof(string))) { result = CreateTextGridColumn(propertyInfo); } } EndCreateGridColumn(propertyInfo, result); return(result); }
/// <summary> /// Diese Methode erstellt den Programmcode der Beziehungen zwischen den Entitaeten aus den Schnittstellen-Typen. /// </summary> /// <param name="type">Der Schnittstellen-Typ.</param> /// <param name="types">Die Schnittstellen-Typen.</param> /// <param name="mapPropertyName">Ein Lambda-Ausdruck zum konvertieren des Eigenschaftsnamen.</param> /// <returns>Die Entitaet als Text.</returns> private Contracts.IGeneratedItem CreateEntityToEntityFromContracts(Type type, IEnumerable <Type> types) { type.CheckArgument(nameof(type)); types.CheckArgument(nameof(types)); var typeName = CreateEntityNameFromInterface(type); var result = new Models.GeneratedItem(Common.UnitType.Logic, Common.ItemType.PersistenceEntity) { FullName = CreateEntityFullNameFromInterface(type), FileExtension = StaticLiterals.CSharpFileExtension, }; result.SubFilePath = $"{result.FullName}PartB{result.FileExtension}"; result.Add($"partial class {typeName}"); result.Add("{"); foreach (var other in types) { var otherHelper = new ContractHelper(other); if (otherHelper.ContextType != CommonBase.Attributes.ContextType.View) { var otherName = GeneratorObject.CreateEntityNameFromInterface(other); foreach (var pi in other.GetProperties()) { if (pi.Name.Equals($"{typeName}Id")) { var otherFullName = GeneratorObject.CreateEntityFullNameFromInterface(other); var navigationName = $"{otherName}s"; result.Add(($"public System.Collections.Generic.ICollection<{otherFullName}> {navigationName} " + "{ get; set; }")); } } } } var interfaces = new List <Type>(); var typeInterface = GetTypeInterface(type); interfaces.Add(type); foreach (var item in GeneratorObject.GetInterfaces(type) .Where(t => t != typeInterface)) { interfaces.Add(item); } foreach (var item in interfaces) { foreach (var pi in item.GetProperties()) { foreach (var other in types) { var otherHelper = new ContractHelper(other); if (otherHelper.ContextType != CommonBase.Attributes.ContextType.View) { var otherName = GeneratorObject.CreateEntityNameFromInterface(other); if (pi.Name.Equals($"{otherName}Id")) { var propHelper = new ContractPropertyHelper(pi); var otherFullName = GeneratorObject.CreateEntityFullNameFromInterface(other); var navigationName = propHelper.NavigationName.GetValueOrDefault(otherName); result.Add(($"[System.ComponentModel.DataAnnotations.Schema.ForeignKey(\"{pi.Name}\")]")); result.Add(($"public {otherFullName} {navigationName} " + "{ get; set; }")); } else if (pi.Name.StartsWith($"{otherName}Id_")) { var data = pi.Name.Split("_"); if (data.Length == 2) { var otherFullName = GeneratorObject.CreateEntityFullNameFromInterface(other); result.Add(($"[System.ComponentModel.DataAnnotations.Schema.ForeignKey(\"{pi.Name}\")]")); result.Add(($"public {otherFullName} {data[1]} " + "{ get; set; }")); } } } } } } result.Add("}"); result.EnvelopeWithANamespace(CreateNameSpace(type)); result.FormatCSharpCode(); return(result); }
private IEnumerable <string> CreateTypeProperties(string separator, IEnumerable <Type> types) { types.CheckArgument(nameof(types)); var result = new List <string>(); foreach (var type in types) { var entityName = CreateEntityNameFromInterface(type); var categoryKey = $"{SolutionProperties.SolutionName}{separator}{entityName}"; if (result.Any(e => e.StartsWith(categoryKey)) == false) { var dialogOptions = new DialogOptions() { ShowTitle = true, ShowClose = true, Left = string.Empty, Top = string.Empty, Bottom = string.Empty, Width = "800px", Height = string.Empty, }; var modelSetting = new ModelSetting(); var dataGridSetting = new DataGridSetting(); var dataGridHandlerSetting = new DataGridHandlerSetting(); result.Add($"{categoryKey}{separator}Setting{separator}{separator}{JsonSerializer.Serialize<ModelSetting>(modelSetting)}"); result.Add($"{categoryKey}DataGrid{separator}Setting{separator}{separator}{JsonSerializer.Serialize<DataGridSetting>(dataGridSetting)}"); result.Add($"{categoryKey}DataGrid{separator}HandlerSetting{separator}{separator}{JsonSerializer.Serialize<DataGridHandlerSetting>(dataGridHandlerSetting)}"); result.Add($"{categoryKey}DataGrid{separator}EditOptions{separator}{separator}{JsonSerializer.Serialize<DialogOptions>(dialogOptions)}"); result.Add($"{categoryKey}DataGrid{separator}DeleteOptions{separator}{separator}{JsonSerializer.Serialize<DialogOptions>(dialogOptions)}"); var contractHelper = new ContractHelper(type); var relations = contractHelper.GetDetailTypes(types); if (relations.Any()) { foreach (var relation in relations) { var detailEntityName = CreateEntityNameFromInterface(relation.To); //result.Add($"{categoryKey}{detailEntityName}DataGrid{separator}Setting{separator}{separator}{JsonSerializer.Serialize<DataGridSetting>(dataGridSetting)}"); } } } foreach (var pi in type.GetAllPropertyInfos()) { var fullKey = $"{categoryKey}{separator}{pi.Name}{separator}"; if (result.Any(e => e.StartsWith(fullKey)) == false) { var propertyHelper = new ContractPropertyHelper(pi); var displaySetting = new DisplaySetting() { ScaffoldItem = true, IsModelItem = false, ReadonlyMode = GetReadonlyMode(propertyHelper), VisibilityMode = GetVisibilityMode(propertyHelper), ListSortable = true, ListFilterable = true, ListWidth = GetListWitdh(propertyHelper), FormatValue = GetFormatValue(propertyHelper), Order = 10_000, }; result.Add($"{fullKey}{separator}{JsonSerializer.Serialize<DisplaySetting>(displaySetting)}"); } } } return(result); }
internal static IEnumerable <string> CreateCopyProperties(Type type, string copyType) { type.CheckArgument(nameof(type)); copyType.CheckArgument(nameof(copyType)); var result = new List <string> { $"public void CopyProperties({copyType} other)", "{", "if (other == null)", "{", "throw new System.ArgumentNullException(nameof(other));", "}", string.Empty, "bool handled = false;", "BeforeCopyProperties(other, ref handled);", "if (handled == false)", "{" }; foreach (var item in ContractHelper.GetAllProperties(type)) { var contractPropertyHelper = new ContractPropertyHelper(item); if (contractPropertyHelper.HasImplementation == false) { if (item.Name.Equals(StaticLiterals.ConnectorItemName) && item.DeclaringType.Name.Equals(StaticLiterals.ICompositeName)) { result.Add($"{StaticLiterals.ConnectorItemName}.CopyProperties(other.{StaticLiterals.ConnectorItemName});"); } else if (item.Name.Equals(StaticLiterals.OneItemName) && item.DeclaringType.Name.Equals(StaticLiterals.ICompositeName)) { result.Add($"{StaticLiterals.OneItemName}.CopyProperties(other.{StaticLiterals.OneItemName});"); } else if (item.Name.Equals(StaticLiterals.AnotherItemName) && item.DeclaringType.Name.Equals(StaticLiterals.ICompositeName)) { result.Add($"{StaticLiterals.AnotherItemName}.CopyProperties(other.{StaticLiterals.AnotherItemName});"); } else if (item.Name.Equals(StaticLiterals.OneItemName) && item.DeclaringType.Name.Equals(StaticLiterals.IOneToAnotherName)) { result.Add($"{StaticLiterals.OneItemName}.CopyProperties(other.{StaticLiterals.OneItemName});"); } else if (item.Name.Equals(StaticLiterals.AnotherItemName) && item.DeclaringType.Name.Equals(StaticLiterals.IOneToAnotherName)) { result.Add($"{StaticLiterals.AnotherItemName}.CopyProperties(other.{StaticLiterals.AnotherItemName});"); } else if (item.Name.Equals(StaticLiterals.OneItemName) && item.DeclaringType.Name.Equals(StaticLiterals.IOneToManyName)) { result.Add($"{StaticLiterals.OneItemName}.CopyProperties(other.{StaticLiterals.OneItemName});"); } else if (item.Name.Equals(StaticLiterals.ManyItemsName) && item.DeclaringType.Name.Equals(StaticLiterals.IOneToManyName)) { result.Add($"Clear{StaticLiterals.ManyItemsName}();"); result.Add($"foreach (var item in other.{StaticLiterals.ManyItemsName})"); result.Add("{"); result.Add($"Add{StaticLiterals.ManyItemName}(item);"); result.Add("}"); } else if (item.CanRead) { result.Add($"{item.Name} = other.{item.Name};"); } } } result.Add("}"); result.Add("AfterCopyProperties(other);"); result.Add("}"); result.Add($"partial void BeforeCopyProperties({copyType} other, ref bool handled);"); result.Add($"partial void AfterCopyProperties({copyType} other);"); return(result); }