public override string PrivateConstructor()
        {
            var code = new CSharpBuilder(Options.LanguageVersion);

            code.Indent(1).Append($"private {TypeName}(string name");
            if (Options.DbValue)
            {
                code.Append(", string dbValue");
            }
            if (Options.UnderlyingValue)
            {
                code.Append($", {UnderlyingTypeName} value");
            }
            code.AppendLine(")");
            code.Indent(1).AppendLine("{");
            code.Indent(2).AppendLine("_name = name;");
            if (Options.DbValue)
            {
                code.Indent(2).AppendLine("_dbValue = dbValue;");
            }
            if (Options.UnderlyingValue)
            {
                code.Indent(2).AppendLine("_value = value;");
            }
            code.Indent(1).AppendLine("}");

            return(code.ToString());
        }
Esempio n. 2
0
        public override string StartClassDefinition()
        {
            var code = new CSharpBuilder(Options.LanguageVersion);

            var superClasses = new List <string>();

            if (Options.ImplementComparable)
            {
                superClasses.Add($"IComparable<{TypeName}>");
            }

            code.Append($"internal class {TypeName}");
            if (superClasses.Any())
            {
                code.Append(" : ").Append(string.Join(", ", superClasses));
            }
            code.AppendLine();
            code.AppendLine("{");

            return(code.ToString());
        }
        public override string StaticMembers()
        {
            var code = new CSharpBuilder(Options.LanguageVersion);

            foreach (var member in Members)
            {
                var memberValue = Convert.ChangeType(member.GetValue(null), UnderlyingType);
                code.Indent(1).Append($"public static readonly {TypeName} {member.Name}");
                code.Append($" = new {TypeName}(");
                code.Append($"{NameOf(member.Name)}");
                if (Options.DbValue)
                {
                    code.Append($", \"{DbValue(member.Name)}\"");
                }
                if (Options.UnderlyingValue)
                {
                    code.Append($", {memberValue}");
                }
                code.AppendLine(");");
            }

            return(code.ToString());
        }