Exemple #1
0
        static void Rebuild(string text, FileInfo fileInfo)
        {
            var dsl       = text;
            var generator = new TemplatedGenerator
            {
                GenerateInterfaceForEntityWithModifiers = "?",
                TemplateForInterfaceName   = "public interface I{0}Aggregate",
                TemplateForInterfaceMember = "void When({0} c);",
                ClassNameTemplate          = @"[DataContract(Namespace = {1})]
public partial record {0}",
                MemberTemplate             = "[DataMember(Order = {0})] public {1} {2} {{ get; init; }}",
            };

            File.WriteAllText(Path.ChangeExtension(fileInfo.FullName, "cs"), GeneratorUtil.Build(dsl, generator));

            File.WriteAllText(
                Path.Combine(fileInfo.DirectoryName, "IsExternalInit.cs"),
                @"// Zie https://stackoverflow.com/a/64749403 voor uitleg waarom IsExternalInit noodzakelijk is.
#if NETFRAMEWORK || NETSTANDARD
namespace System.Runtime.CompilerServices
{
    internal static class IsExternalInit {}
}
#endif");
        }
 void WriteAssignments(Message message, CodeWriter writer)
 {
     foreach (var member in message.Members)
     {
         writer.WriteLine("{0} = {1};", GeneratorUtil.MemberCase(member.Name), GeneratorUtil.ParameterCase(member.Name));
     }
 }
        void WriteMembers(Message message, CodeWriter writer)
        {
            var idx = 1;

            foreach (var member in message.Members)
            {
                writer.WriteLine(MemberTemplate, idx, member.Type, GeneratorUtil.MemberCase(member.Name));


                idx += 1;
            }
        }
Exemple #4
0
        static void Rebuild(string text, string fullPath)
        {
            var dsl       = text;
            var generator = new TemplatedGenerator
            {
                GenerateInterfaceForEntityWithModifiers = "?",
                TemplateForInterfaceName   = "public interface I{0}Aggregate",
                TemplateForInterfaceMember = "void When({0} c);",
                ClassNameTemplate          = @"[DataContract(Namespace = {1})]
public partial class {0}",
                MemberTemplate             = "[DataMember(Order = {0})] public {1} {2} {{ get; private set; }}",
            };


            File.WriteAllText(Path.ChangeExtension(fullPath, "cs"), GeneratorUtil.Build(dsl, generator));
        }
        void WriteParameters(Message message, CodeWriter writer)
        {
            var first = true;

            foreach (var member in message.Members)
            {
                if (first)
                {
                    first = false;
                }
                else
                {
                    writer.Write(", ");
                }
                writer.Write("{0} {1}", member.Type, GeneratorUtil.ParameterCase(member.Name));
            }
        }
Exemple #6
0
        static void WriteToString(CodeWriter writer, Message contract)
        {
            if (string.IsNullOrWhiteSpace(contract.StringRepresentation))
            {
                return;
            }

            writer.WriteLine();
            writer.WriteLine("public override string ToString()");
            writer.WriteLine("{");
            writer.Indent += 1;

            var text   = contract.StringRepresentation;
            var active = new List <string>();

            foreach (var member in contract.Members)
            {
                text = ReplaceAdd(text, "{" + member.DslName + ":", "{" + active.Count + ":", active, member);
                text = ReplaceAdd(text, "{" + member.DslName + "}", "{" + active.Count + "}", active, member);


                if (member.DslName != member.Name)
                {
                    text = ReplaceAdd(text, "{" + member.Name + ":", "{" + active.Count + ":", active, member);
                    text = ReplaceAdd(text, "{" + member.Name + "}", "{" + active.Count + "}", active, member);
                }
            }

            writer.Write("return string.Format(@{0}", text);

            foreach (var variable in active)
            {
                writer.Write(", " + GeneratorUtil.MemberCase(variable));
            }
            writer.WriteLine(");");
            writer.Indent -= 1;
            writer.WriteLine("}");
        }
Exemple #7
0
        static void WritePrivateCtor(CodeWriter writer, Message contract)
        {
            var arrays = contract.Members.Where(p => p.Type.EndsWith("[]")).ToArray();

            if (!arrays.Any())
            {
                writer.WriteLine(@"private {0} () {{}}", contract.Name);
            }
            else
            {
                writer.WriteLine(@"{0} () 
{{", contract.Name);
                writer.Indent += 1;
                foreach (var array in arrays)
                {
                    writer.WriteLine("{0} = new {1};",
                                     GeneratorUtil.MemberCase(array.Name),
                                     array.Type.Replace("[]", "[0]")
                                     );
                }
                writer.Indent -= 1;
                writer.WriteLine("}");
            }
        }