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;
            }
        }
Beispiel #3
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("}");
        }
Beispiel #4
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("}");
            }
        }