Example #1
0
    public static string GetPrivateMethods(GenerationItemModel model, List <PropertyDefinition> properties, string tabs)
    {
        if (!properties.Any())
        {
            return(string.Empty);
        }

        var builder = new System.Text.StringBuilder();
        var newLine = System.Environment.NewLine;

        var singleMethods = GetSingleMapMethods(model, properties, tabs);
        var listMethods   = GetListMapMethods(model, properties, tabs);

        builder.AppendFormat("{0}#region Private Properties{1}{1}", tabs, newLine);

        if (!string.IsNullOrWhiteSpace(singleMethods))
        {
            builder.Append(singleMethods);
        }

        if (!string.IsNullOrWhiteSpace(listMethods))
        {
            builder.Append(listMethods);
        }

        builder.AppendFormat("{0}#endregion{1}{1}", tabs, newLine);
        return(builder.ToString());
    }
Example #2
0
    public static bool ImplementsDomainInterface(GenerationItemModel model)
    {
        var name       = model.Definition.Name;
        var entityName = name.ToString().Replace("View", "");

        return(model.Definitions.Any(x => x.Name == entityName && x.Attributes.Any(a => a.Name == nameof(TableAttribute))));
    }
Example #3
0
    public static string GetSingleMapMethods(GenerationItemModel model, List <PropertyDefinition> properties, string tabs)
    {
        if (!properties.Any())
        {
            return(string.Empty);
        }

        var builder = new System.Text.StringBuilder();

        foreach (var property in properties)
        {
            var isArray           = property.Type.IsArray;
            var type              = isArray ? property.Type.InnerObject : property.Type;
            var typeName          = GetModelName(model, type, false);
            var methodName        = typeName.Replace("View", string.Empty);
            var typeInterfaceName = GetModelName(model, type, true);

            builder.AppendLine($"{tabs}/// <summary>");
            builder.AppendLine($"{tabs}/// Maps the {GetReadableString(typeName)} from a domain interface.");
            builder.AppendLine($"{tabs}/// </summary>");
            builder.AppendLine($"{tabs}private void Map{methodName}({typeName} entity, {typeInterfaceName} model)");
            builder.AppendLine($"{tabs}{{");
            builder.AppendLine($"{tabs}	entity.MapFrom(model);");
            builder.AppendLine($"{tabs}	this.{GetDomainTrackerName(property)}.Edit(entity);");
            builder.AppendLine($"{tabs}}}");
            builder.AppendLine();
        }

        return(builder.ToString());
    }
Example #4
0
    public static string MapProperties(GenerationItemModel model, string objectName, string readerName, bool isAsync = false, bool includeAutoIncrement = false)
    {
        var structDefinition = model.Definition as StructDefinition;

        if (structDefinition == null)
        {
            return(string.Empty);
        }

        var builder    = new System.Text.StringBuilder();
        var properties = GetColumnProperties(structDefinition, includeAutoIncrement);
        var i          = 0;

        builder.AppendLine();

        foreach (var property in properties)
        {
            var asyncPostfix = (isAsync ? "Async" : "");
            var awaitPrefix  = (isAsync ? "await" : "");
            var typeName     = GetModelName(model, property.Type);

            if (IsNullable(property.Type))
            {
                builder.AppendFormat($"\t\t\t{objectName}.{property.Name} = {awaitPrefix} {readerName}.IsDBNull{asyncPostfix}({i}) ? default({typeName}) : {readerName}.{GetMapMethod(property.Type)}({i});\n");
            }
            else
            {
                builder.AppendFormat($"\t\t\t{objectName}.{property.Name} = {readerName}.{GetMapMethod(property.Type)}({i});\n");
            }

            i++;
        }

        return(builder.ToString());
    }
Example #5
0
    public static string GetModelName(GenerationItemModel model, ObjectDefinitionBase objectDefinition, bool isInterface)
    {
        objectDefinition = GetDefinition(objectDefinition, model);

        if (objectDefinition is EnumDefinition)
        {
            isInterface = false;
        }

        var translator = model.GetTranslator(objectDefinition);

        if (translator == null)
        {
            if (objectDefinition.IsArray && objectDefinition.InnerObject != null)
            {
                return(string.Format("List<{0}>", GetModelName(model, objectDefinition.InnerObject, isInterface: isInterface)));
            }

            if (objectDefinition.IsInterface)
            {
                return(objectDefinition.Name.Substring(1, objectDefinition.Name.Length - 1).Replace("View", ""));
            }

            if (objectDefinition is EnumDefinition)
            {
                return(objectDefinition.FullName);
            }

            return(string.Format("{0}{1}", isInterface && !objectDefinition.IsInterface ?  "I" : "", objectDefinition.Name.Replace("View", "")));
        }

        return(translator.Translation);
    }
Example #6
0
    public static string MethodFirm(GenerationItemModel model, MethodDefinition method, bool includeSemicolon)
    {
        var parameters = string.Empty;

        foreach (var parameter in method.Parameters)
        {
            parameters += $"{GetModelName(model, parameter.Type, isInterface: false)} {parameter.Name}, ";
        }

        if (parameters.EndsWith(", "))
        {
            parameters = parameters.Substring(0, parameters.Length - 2);
        }

        var result = GetModelName(model, method.ReturnType, isInterface: false);
        var isVoid = result == "void" || result == "System.Void";

        if (!isVoid)
        {
            result = $"Task<{result}>";
        }
        else
        {
            result = "Task";
        }

        return($"{(includeSemicolon? "" : "async ")}{result} {method.Name}Async({parameters}){(includeSemicolon ? ";" : "")}");
    }
Example #7
0
    public static string MethodBody(GenerationItemModel model, MethodDefinition method, string serviceName)
    {
        var parameters      = string.Empty;
        var callParameters  = string.Empty;
        var data            = string.Empty;
        var verb            = GetMethodVerb(method);
        var controllerRoute = GetControllerTemplate(model);
        var methodRoute     = GetMethodTemplate(method);
        var route           = string.IsNullOrWhiteSpace(methodRoute) ? controllerRoute : $"{controllerRoute}/{methodRoute}";

        foreach (var parameter in method.Parameters)
        {
            if (parameter.Attributes.Any(x => x.Name == "FromBodyAttribute"))
            {
                data = string.Format("{0}", parameter.Name);
            }
            else
            {
                callParameters += string.Format("{0}: {0}, ", parameter.Name);
            }
        }

        if (!string.IsNullOrWhiteSpace(data) && !VerbAllowsBodyData(verb))
        {
            throw new Exception($"The action '{method.Name}' in controller '{serviceName}' does not allow body data due to its verb '{verb}' does not allows message body data.");
        }

        if (callParameters.Any())
        {
            callParameters = string.Format("{{ {0} }}", callParameters.Substring(0, callParameters.Length - 2));
        }

        return($"return this.{verb}<{GetModelName(model, method.ReturnType, isInterface: true)}>('{route}', {(callParameters.Any() ? callParameters : "null")}{(data.Any() ? ", " + data : "")});");
    }
Example #8
0
    public static string GetFileName(GenerationItemModel model, ObjectDefinitionBase objectDefinition, bool isInterface)
    {
        var namingRule = new SeparateWordsNamingRule();
        var name       = GetModelName(model, objectDefinition, isInterface: false);

        if (objectDefinition.IsInterface)
        {
            name = name.Substring(1, name.Length - 1);
        }

        var newName = namingRule.Execute(name, new NamingRuleConfiguration()
        {
            Parameters = new[] { "-" }
        }).ToLowerInvariant();


        if (isInterface && objectDefinition is StructDefinition)
        {
            return(newName + ".interface");
        }

        if (isInterface && objectDefinition is EnumDefinition)
        {
            return(newName + ".enum");
        }

        return(newName);
    }
Example #9
0
    public static string GetRemoveMethods(GenerationItemModel model, List <PropertyDefinition> properties, string tabs)
    {
        var builder    = new System.Text.StringBuilder();
        var entityName = model.Definition.Name;

        builder.AppendLine();
        builder.AppendLine($"{tabs}#region Private Methods");
        builder.AppendLine();

        foreach (var property in properties)
        {
            var type = (property.Type.IsArray ? property.Type.InnerObject : property.Type);

            builder.AppendLine($"{tabs}/// <summary>");
            builder.AppendLine($"{tabs}/// Removes the specified enumeration of {GetReadableString(type.Name)}.");
            builder.AppendLine($"{tabs}/// </summary>");
            builder.AppendLine($"{tabs}private void Remove(IEnumerable<{GetModelName(model, type, false)}> entities)");
            builder.AppendLine($"{tabs}{{");
            builder.AppendLine($"{tabs}    this.GetRepository<I{type.Name}Repository>().Remove(entities);");
            builder.AppendLine($"{tabs}}}");
            builder.AppendLine();
            builder.AppendLine($"{tabs}/// <summary>");
            builder.AppendLine($"{tabs}/// Removes the specified enumeration of {GetReadableString(type.Name)}.");
            builder.AppendLine($"{tabs}/// </summary>");
            builder.AppendLine($"{tabs}private async FrameworkTask RemoveAsync(IEnumerable<{GetModelName(model, type, false)}> entities)");
            builder.AppendLine($"{tabs}{{");
            builder.AppendLine($"{tabs}    await this.GetRepository<I{type.Name}Repository>().RemoveAsync(entities);");
            builder.AppendLine($"{tabs}}}");
            builder.AppendLine();
        }

        builder.AppendLine($"{tabs}#endregion");
        return(builder.ToString());
    }
Example #10
0
    public static IEnumerable <ObjectDefinitionBase> GetModelRelatedContracts(GenerationItemModel model, ObjectDefinitionBase definition, List <PropertyDefinition> properties)
    {
        var contracts = new Dictionary <string, ObjectDefinitionBase>();

        foreach (var property in properties)
        {
            var objectDefinition = GetDefinition(property.Type, model);

            if (objectDefinition.IsArray)
            {
                objectDefinition = objectDefinition.InnerObject;
            }

            var translator = model.GetTranslator(objectDefinition);

            if (objectDefinition.Name != definition.Name &&
                !contracts.ContainsKey(objectDefinition.Name) &&
                translator == null)
            {
                contracts.Add(objectDefinition.Name, objectDefinition);
            }
        }

        return(contracts.Values.ToList());
    }
Example #11
0
    public static string GetStoredProcedureBaseClass(GenerationItemModel model)
    {
        var procedureType = model.Definition.Attributes.FirstOrDefault(x => x.Name == "StoredProcedureTypeAttribute");
        var name          = model.Definition.Name;
        var parameters    = $"{name}Parameters";

        if (procedureType == null)
        {
            return(string.Empty);
        }

        switch (procedureType.Parameters[0].Value)
        {
        case "Reader":
            return($"ReaderStoredProcedure<{parameters}, {GetStoredProcedureResults(model)}>");

        case "Scalar":
            return($"ScalarStoredProcedure<{parameters}, {GetStoredProcedureResults(model)}>");

        case "NonQuery":
            return($"NonQueryStoredProcedure<{parameters}>");
        }

        return(string.Empty);
    }
Example #12
0
    public static string GetPropertyValidations(GenerationItemModel model, List <PropertyDefinition> properties, string tabs)
    {
        if (!properties.Any())
        {
            return(string.Empty);
        }

        var builder = new System.Text.StringBuilder();

        builder.AppendLine();

        foreach (var property in properties)
        {
            var isArray = property.Type.IsArray;
            if (isArray)
            {
                builder.AppendLine($"{tabs}foreach(var child in this.{GetPrivateName(property)})");
                builder.AppendLine($"{tabs}    child.Validate();");
            }
            else
            {
                builder.AppendLine($"{tabs}this.{GetPrivateName(property)}.Validate();");
            }
        }

        return(builder.ToString());
    }
Example #13
0
    public static string GetMapPropertyList(GenerationItemModel model, List <PropertyDefinition> properties, string tabs)
    {
        if (!properties.Any())
        {
            return("// No properties to map.");
        }

        var builder = new System.Text.StringBuilder();

        builder.AppendLine();

        foreach (var property in properties)
        {
            var isArray   = property.Type.IsArray;
            var type      = isArray ? property.Type.InnerObject : property.Type;
            var typeName  = isArray ? property.Name : GetModelName(model, type, false).Replace("View", string.Empty);
            var parameter = isArray ? string.Empty : $"this.{GetPrivateName(property)}, ";

            builder.AppendFormat("{0}this.Map{1}({2}model.{3});", tabs, typeName, parameter, property.Name);
            builder.AppendLine();
        }

        var text = builder.ToString();

        return(string.IsNullOrEmpty(text) ? "// No properties to map." : text);
    }
Example #14
0
    public static string GetPublicPropertyList(GenerationItemModel model, List <PropertyDefinition> properties, string tabs)
    {
        var builder = new System.Text.StringBuilder();
        var newLine = System.Environment.NewLine;

        builder.AppendFormat("{0}#region Public Properties{1}{1}", tabs, newLine);

        foreach (var property in properties)
        {
            var isSimple           = property.Attributes.All(x => x.Name != "NavigationAttribute");
            var modelNameInterface = GetModelName(model, property.Type, true);
            var modelName          = GetModelName(model, property.Type, false);

            if (isSimple)
            {
                builder.AppendLine($"{tabs}/// <summary>");
                builder.AppendLine($"{tabs}/// Gets or sets the {GetReadableString(property.Name)}.");
                builder.AppendLine($"{tabs}/// </summary>");
                builder.AppendLine($"{tabs}[DataMember]");
                builder.AppendLine($"{tabs}public {modelNameInterface} {property.Name} {{ get; set; }}");
            }
            else
            {
                var privateName = GetPrivateName(property);

                builder.AppendLine($"{tabs}/// <summary>");
                builder.AppendLine($"{tabs}/// Gets or sets the {GetReadableString(property.Name)}.");
                builder.AppendLine($"{tabs}/// </summary>");
                builder.AppendLine($"{tabs}[DataMember]");

                foreach (var navigation in property.Attributes.Where(x => x.Name == "NavigationAttribute"))
                {
                    var referencedType     = navigation.Parameters[0].Value;
                    var sourceProperty     = navigation.Parameters[1].Value;
                    var referencedProperty = navigation.Parameters[2].Value;

                    builder.AppendLine($"{tabs}[Navigation(typeof({referencedType}), \"{sourceProperty}\", \"{referencedProperty}\")]");
                }

                builder.AppendLine((!property.Type.IsArray)
                    ? $"{tabs}public {modelNameInterface} {property.Name} {{ get => this.{privateName}; private set => this.{privateName} = value as {modelName}; }}"
                    : $"{tabs}public {modelNameInterface} {property.Name} => this.{privateName};");

                builder.AppendLine();
                builder.AppendLine($"{tabs}/// <summary>");
                builder.AppendLine($"{tabs}/// The {GetReadableString(GetDomainTrackerName(property))}.");
                builder.AppendLine($"{tabs}/// </summary>");
                builder.AppendLine($"{tabs}[IgnoreDataMember]");
                builder.AppendLine($"{tabs}public {GetDomainTracker(property)} {GetDomainTrackerName(property)} {{ get; }}");
            }

            builder.AppendLine();
        }

        builder.AppendFormat("{0}#endregion{1}{1}", tabs, newLine);
        return(builder.ToString());
    }
Example #15
0
    public static string GetInheritance(GenerationItemModel model)
    {
        var name       = model.Definition.Name;
        var entityName = name.ToString().Replace("View", "");
        var tableName  = $"I{name}Table";

        return(ImplementsDomainInterface(model)
            ? $"DomainBase<I{entityName}, {name}>, I{entityName}, {tableName}"
            : $"DomainBase, {tableName}");
    }
Example #16
0
    public static string GetCrudMethods(GenerationItemModel model, List <PropertyDefinition> properties, string tabs)
    {
        if (!properties.Any())
        {
            return(string.Empty);
        }

        var newLineLength = System.Environment.NewLine.Length;
        var builder       = new System.Text.StringBuilder();

        builder.AppendLine();

        foreach (var property in properties)
        {
            var isArray    = property.Type.IsArray;
            var type       = isArray ? property.Type.InnerObject : property.Type;
            var typeName   = GetModelName(model, type, false);
            var methodName = typeName.Replace("View", string.Empty);

            ////////////////////////////////////////////////////
            // Add Method
            ////////////////////////////////////////////////////
            builder.AppendLine($"{tabs}/// <summary>");
            builder.AppendLine($"{tabs}/// Adds a new {GetReadableString(typeName)}.");
            builder.AppendLine($"{tabs}/// </summary>");
            builder.AppendLine($"{tabs}public void Add{methodName}({typeName} entity)");
            builder.AppendLine($"{tabs}{{");
            builder.AppendLine(isArray
                                ? $"{tabs}	this.{GetPrivateName(property)}.Add(entity);"
                                : $"{tabs}	this.{GetPrivateName(property)} = entity;");
            builder.AppendLine($"{tabs}	this.{GetDomainTrackerName(property)}.Add(entity);");
            builder.AppendLine($"{tabs}}}");
            builder.AppendLine();

            ////////////////////////////////////////////////////
            // Remove Method
            ////////////////////////////////////////////////////
            builder.AppendLine($"{tabs}/// <summary>");
            builder.AppendLine($"{tabs}/// Removes the {GetReadableString(typeName)}.");
            builder.AppendLine($"{tabs}/// </summary>");
            builder.AppendLine($"{tabs}public void Remove{methodName}({typeName} entity)");
            builder.AppendLine($"{tabs}{{");
            builder.AppendLine(isArray
                                ? $"{tabs}	this.{GetPrivateName(property)}.Remove(entity);"
                                : $"{tabs}	this.{GetPrivateName(property)} = null;");
            builder.AppendLine($"{tabs}	this.{GetDomainTrackerName(property)}.Remove(entity);");
            builder.AppendLine($"{tabs}}}");
            builder.AppendLine();
        }

        return(builder.Remove(builder.Length - newLineLength, newLineLength).ToString());
    }
Example #17
0
    public static string GetTableName(GenerationItemModel model)
    {
        var structDefinition = model.Definition as StructDefinition;

        if (structDefinition == null)
        {
            return(string.Empty);
        }

        var tableAttribute = structDefinition.Attributes.FirstOrDefault(x => x.Name == "TableAttribute");

        return(tableAttribute == null ? structDefinition.Name : tableAttribute.Parameters[0].Value);
    }
Example #18
0
    public static string GetMultiEditRemoval(GenerationItemModel model, List <PropertyDefinition> properties, string tabs, string prefix = "", string postfix = "")
    {
        var builder       = new System.Text.StringBuilder();
        var newLineLength = System.Environment.NewLine.Length;

        builder.AppendLine();

        foreach (var property in properties)
        {
            builder.AppendLine($"{tabs}{prefix}this.Remove{postfix}(entityList.SelectMany(x => x.{GetDomainTrackerName(property)}.Removed));");
        }

        return(builder.Remove(builder.Length - newLineLength, newLineLength).ToString());
    }
Example #19
0
    public static IEnumerable <ObjectDefinitionBase> GetServiceRelatedContracts(GenerationItemModel model, ObjectDefinitionBase definition)
    {
        var contracts       = new Dictionary <string, ObjectDefinitionBase>();
        var classDefinition = definition as StructDefinition;

        if (classDefinition == null)
        {
            return(contracts.Values);
        }

        foreach (var method in classDefinition.Methods)
        {
            var objectDefinition = GetDefinition(method.ReturnType, model);

            if (objectDefinition.IsArray)
            {
                objectDefinition = objectDefinition.InnerObject;
            }

            var translator = model.GetTranslator(objectDefinition);

            if (!contracts.ContainsKey(objectDefinition.Name) &&
                translator == null)
            {
                contracts.Add(objectDefinition.Name, objectDefinition);
            }

            foreach (var parameter in method.Parameters)
            {
                objectDefinition = GetDefinition(parameter.Type, model);

                if (objectDefinition.IsArray)
                {
                    objectDefinition = objectDefinition.InnerObject;
                }

                translator = model.GetTranslator(objectDefinition);

                if (!contracts.ContainsKey(objectDefinition.Name) &&
                    translator == null)
                {
                    contracts.Add(objectDefinition.Name, objectDefinition);
                }
            }
        }

        return(contracts.Values.ToList());
    }
Example #20
0
    public static string MethodFirm(GenerationItemModel model, MethodDefinition method, bool includeSemicolon)
    {
        var parameters = string.Empty;

        foreach (var parameter in method.Parameters)
        {
            parameters += parameter.Name + ": " + GetModelName(model, parameter.Type, isInterface: true) + ", ";
        }

        if (parameters.EndsWith(", "))
        {
            parameters = parameters.Substring(0, parameters.Length - 2);
        }

        return(string.Format("{0}({1}): IHttpPromise<{2}>{3}", ToCamelCase(method.Name), parameters, GetModelName(model, method.ReturnType, isInterface: true), includeSemicolon ? ";" : ""));
    }
Example #21
0
    public static string GetSingleEditRemoval(GenerationItemModel model, List <PropertyDefinition> properties, string tabs, string prefix = "", string postfix = "")
    {
        var builder       = new System.Text.StringBuilder();
        var newLineLength = System.Environment.NewLine.Length;

        builder.AppendLine();

        foreach (var property in properties)
        {
            builder.AppendLine($"{tabs}{prefix}this.Remove{postfix}(entity.{GetDomainTrackerName(property)}.Removed);");
        }

        var text = builder.Remove(builder.Length - newLineLength, newLineLength).ToString();

        return(string.IsNullOrEmpty(text)? "// There are no properties to remove." : text);
    }
Example #22
0
    public static string GetModelName(GenerationItemModel model, ObjectDefinitionBase objectDefinition, bool isInterface = false)
    {
        if (objectDefinition is EnumDefinition)
        {
            isInterface = false;
        }

        var translator = model.GetTranslator(objectDefinition);

        if (translator == null)
        {
            return(objectDefinition.IsArray && objectDefinition.InnerObject != null
                    ? $"{(isInterface ? "IReadOnlyCollection" : "List")}<{GetModelName(model, objectDefinition.InnerObject, isInterface: isInterface)}>"
                    : $"{(isInterface ? "I" : "")}{(isInterface ? objectDefinition.Name.Replace("View", string.Empty) : objectDefinition.Name)}");
        }

        return(translator.Translation);
    }
Example #23
0
    public static string GetPrivateFieldList(GenerationItemModel model, List <PropertyDefinition> properties, string tabs)
    {
        var builder = new System.Text.StringBuilder();
        var newLine = System.Environment.NewLine;

        builder.AppendFormat("{0}#region Private Fields{1}{1}", tabs, newLine);

        foreach (var property in properties)
        {
            builder.AppendLine($"{tabs}/// <summary>");
            builder.AppendLine($"{tabs}/// The {GetReadableString(property.Name)}.");
            builder.AppendLine($"{tabs}/// </summary>");
            builder.AppendFormat("{0}private {1}{2} {3};{4}{4}", tabs, property.Type.IsArray ? "readonly " : "", GetModelName(model, property.Type, false), GetPrivateName(property), newLine);
        }

        builder.AppendFormat("{0}#endregion{1}{1}", tabs, newLine);
        return(builder.ToString());
    }
Example #24
0
    public static string GetIgnorePropertyList(GenerationItemModel model, List <PropertyDefinition> properties, string tabs)
    {
        if (!properties.Any())
        {
            return(string.Empty);
        }

        var builder = new System.Text.StringBuilder();

        builder.AppendLine();

        foreach (var property in properties)
        {
            builder.AppendFormat("{0}configuration.Ignore(x => x.{1});", tabs, property.Name);
            builder.AppendLine();
        }

        return(builder.ToString());
    }
Example #25
0
    public static string GetColumnNames(GenerationItemModel model, bool includeAutoIncrement = true)
    {
        var structDefinition = model.Definition as StructDefinition;
        var newLineLength    = System.Environment.NewLine.Length;

        if (structDefinition == null)
        {
            return(string.Empty);
        }

        var builder    = new System.Text.StringBuilder();
        var properties = GetColumnProperties(structDefinition, includeAutoIncrement);

        foreach (var property in properties)
        {
            var attribute = property.Attributes.First(x => x.Name == "ColumnAttribute");
            builder.AppendFormat("`{0}`, ", attribute.Parameters[0].Value);
        }

        return(builder.Remove(builder.Length - newLineLength, newLineLength).ToString());
    }
Example #26
0
    public static string GetConstructorList(GenerationItemModel model, List <PropertyDefinition> properties, string tabs)
    {
        var builder       = new System.Text.StringBuilder();
        var newLineLength = System.Environment.NewLine.Length;

        builder.AppendLine();

        foreach (var property in properties)
        {
            builder.AppendFormat("{0}this.{1} = new {2}();", tabs, GetPrivateName(property), GetModelName(model, property.Type, false));
            builder.AppendLine();
        }

        foreach (var property in properties)
        {
            builder.AppendFormat("{0}this.{1} = new {2}();", tabs, GetDomainTrackerName(property), GetDomainTracker(property));
            builder.AppendLine();
        }

        return(builder.Remove(builder.Length - newLineLength, newLineLength).ToString());
    }
Example #27
0
    public static string GetPrimaryKeyForRepositories(GenerationItemModel model)
    {
        var structDefinition = model.Definition as StructDefinition;

        if (structDefinition == null)
        {
            return(string.Empty);
        }

        var primaryKeys = GetPrimaryKeys(structDefinition);

        if (!primaryKeys.Any())
        {
            return(string.Empty);
        }

        if (primaryKeys.Count == 1)
        {
            return(GetModelName(model, primaryKeys.First().Type, true));
        }

        return($"Tuple<{string.Join(", ", primaryKeys.Select(x => GetModelName(model, x.Type, true)))}>");
    }
Example #28
0
 public static string GetStoredProcedureMapperNames(GenerationItemModel model)
 {
     return(string.Join(",", model.Definition.Attributes.Where(x => x.Name == "RoutineResultAttribute").Select((x, i) => $"mapper{i + 1}")));
 }
Example #29
0
 public static string GetStoredProcedureMapperDefinition(GenerationItemModel model)
 {
     return(string.Join(",", model.Definition.Attributes.Where(x => x.Name == "RoutineResultAttribute").Select((x, i) => $"I{x.Parameters[0].Value}DatabaseReaderMapper mapper{i + 1}")));
 }
Example #30
0
 public static string GetStoredProcedureResults(GenerationItemModel model)
 {
     return(string.Join(",", model.Definition.Attributes.Where(x => x.Name == "RoutineResultAttribute").Select(x => x.Parameters[0].Value)));
 }