public ModuleModel(String model, String controller, String area) { ModelShortName = Regex.Split(model, "(?=[A-Z])").Last(); ModelVarName = ModelShortName.ToLower(); Models = model.Pluralize(false); Model = model; View = $"{Model}View"; ServiceTests = $"{Model}ServiceTests"; IService = $"I{Model}Service"; Service = $"{Model}Service"; ValidatorTests = $"{Model}ValidatorTests"; IValidator = $"I{Model}Validator"; Validator = $"{Model}Validator"; ControllerTestsNamespace = "MvcTemplate.Tests.Unit.Controllers" + (!String.IsNullOrWhiteSpace(area) ? $".{area}" : ""); ControllerNamespace = "MvcTemplate.Controllers" + (!String.IsNullOrWhiteSpace(area) ? $".{area}" : ""); ControllerTests = $"{controller}ControllerTests"; Controller = $"{controller}Controller"; Area = area; AllProperties = typeof(BaseModel) .Assembly .GetTypes() .SingleOrDefault(type => type.Name.Equals(Model, StringComparison.OrdinalIgnoreCase))? .GetProperties(BindingFlags.Public | BindingFlags.Instance) ?? typeof(BaseModel).GetProperties(); Properties = typeof(BaseModel) .Assembly .GetTypes() .SingleOrDefault(type => type.Name.Equals(Model, StringComparison.OrdinalIgnoreCase))? .GetProperties(BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly) ?? new PropertyInfo[0]; }
public ModuleModel(String model, String controller, String?area) { ModelShortName = Regex.Split(model, "(?=[A-Z])").Last(); ModelVarName = ModelShortName.ToLower(); Models = model.Pluralize(false); Model = model; View = $"{Model}View"; ServiceTests = $"{Model}ServiceTests"; IService = $"I{Model}Service"; Service = $"{Model}Service"; ValidatorTests = $"{Model}ValidatorTests"; IValidator = $"I{Model}Validator"; Validator = $"{Model}Validator"; ControllerTestsNamespace = $"MvcTemplate.Controllers.{(!String.IsNullOrWhiteSpace(area) ? $"{area}." : "")}Tests"; ControllerNamespace = $"MvcTemplate.Controllers{(!String.IsNullOrWhiteSpace(area) ? $".{area}" : "")}"; ControllerTests = $"{controller}ControllerTests"; Controller = $"{controller}Controller"; Area = area; Type modelType = typeof(BaseModel).Assembly.GetType($"MvcTemplate.Objects.{Model}") ?? typeof(BaseModel); Type viewType = typeof(BaseView).Assembly.GetType($"MvcTemplate.Objects.{View}") ?? typeof(BaseModel); PropertyInfo[] modelProperties = modelType.GetProperties(); AllModelProperties = modelProperties.Where(property => property.PropertyType.Namespace == "System").ToArray(); ViewProperties = viewType.GetProperties().Where(property => property.DeclaringType?.Name == View).ToArray(); ModelProperties = AllModelProperties.Where(property => property.DeclaringType?.Name == Model).ToArray(); AllViewProperties = viewType.GetProperties(); Indexes = ModelProperties .Where(property => ViewProperties.Any(prop => prop.Name == property.Name) && property.GetCustomAttribute <IndexAttribute>()?.IsUnique == true) .OrderByDescending(property => property.Name.Length) .ThenByDescending(property => property.Name) .ToArray(); Relations = AllViewProperties .ToDictionary( property => property, property => modelProperties.SingleOrDefault(relation => property.Name.EndsWith("Id") && relation.PropertyType.Assembly == modelType.Assembly && relation.Name == property.Name[..^ 2])?.PropertyType.Name); }
public ModuleModel(String model, String controller, String?area) { ModelShortName = Regex.Split(model, "(?=[A-Z])").Last(); ModelVarName = ModelShortName.ToLower(); Models = model.Pluralize(); Model = model; View = $"{Model}View"; ServiceTests = $"{Model}ServiceTests"; IService = $"I{Model}Service"; Service = $"{Model}Service"; ValidatorTests = $"{Model}ValidatorTests"; IValidator = $"I{Model}Validator"; Validator = $"{Model}Validator"; ControllerTestsNamespace = $"MvcTemplate.Controllers.{(String.IsNullOrWhiteSpace(area) ? "" : $".{area}")}Tests";
public ModuleModel(String model, String controller, String area) { ModelShortName = Regex.Split(model, "(?=[A-Z])").Last(); ModelVarName = ModelShortName.ToLower(); Models = model.Pluralize(false); Model = model; View = $"{Model}View"; ServiceTests = $"{Model}ServiceTests"; IService = $"I{Model}Service"; Service = $"{Model}Service"; ValidatorTests = $"{Model}ValidatorTests"; IValidator = $"I{Model}Validator"; Validator = $"{Model}Validator"; ControllerTestsNamespace = $"UpsCoolWeb.Controllers.{(!String.IsNullOrWhiteSpace(area) ? $"{area}." : "")}Tests"; ControllerNamespace = "UpsCoolWeb.Controllers" + (!String.IsNullOrWhiteSpace(area) ? $".{area}" : ""); ControllerTests = $"{controller}ControllerTests"; Controller = $"{controller}Controller"; Area = area; Type type = typeof(BaseModel).Assembly.GetType("UpsCoolWeb.Objects." + model) ?? typeof(BaseModel); PropertyInfo[] properties = type.GetProperties(); AllProperties = properties.Where(property => property.PropertyType.Namespace == "System").ToArray(); Properties = AllProperties.Where(property => property.DeclaringType.Name == model).ToArray(); Relations = Properties .ToDictionary( property => property, property => properties.SingleOrDefault(relation => property.Name.EndsWith("Id") && relation.PropertyType.Assembly == type.Assembly && relation.Name == property.Name.Remove(property.Name.Length - 2))?.PropertyType.Name); }