private StringsContent CreateStringsData(string className, Dictionary <string, string> stringDict)
        {
            StringsContent stringsData = new StringsContent();

            stringsData.ClassName = className;
            stringsData.Strings   = new List <StringsContent.String>();
            stringsData.Namespace = this.Namespace;

            foreach (var pair in stringDict)
            {
                StringsContent.String d = new StringsContent.String();

                d.Name  = pair.Key;
                d.Value = pair.Value;

                // Count the args in the string
                int n = 0;

                for (int i = 0; i < d.Value.Length - 1; i++)
                {
                    if (d.Value[i] == '{' && d.Value[i + 1] != '{')
                    {
                        n++;
                    }
                }

                d.ArgCount = n;

                stringsData.Strings.Add(d);
            }

            return(stringsData);
        }
        private void WriteCsOutput(TextWriter textWriter, StringsContent stringsData)
        {
            CSharpStreamWriter writer = new CSharpStreamWriter(textWriter);

            writer.WriteLine("//");
            writer.WriteLine("// This file was generated on {{0}}.", DateTime.Now);
            writer.WriteLine("//");
            writer.WriteLine();
            writer.WriteLine("using System;");
            writer.WriteLine();
            writer.WriteLine("namespace {{0}}", stringsData.Namespace);
            writer.WriteLine("{");
            writer.WriteLine("public class {{0}}", stringsData.ClassName);
            writer.WriteLine("{");
            writer.WriteLine("private string[] strings;");
            writer.WriteLine();
            writer.WriteLine("public {{0}}(string[] strings)", stringsData.ClassName);
            writer.WriteLine("{");
            writer.WriteLine("this.strings = strings;");
            writer.WriteLine("}");
            writer.WriteLine();

            for (int i = 0; i < stringsData.Strings.Count; i++)
            {
                StringsContent.String s = stringsData.Strings[i];

                if (s.ArgCount == 0)
                {
                    writer.WriteLine("public string {{0}} { get { return strings[{{1}}]; } }",
                                     s.Name, i);
                }
                else
                {
                    StringBuilder sb1 = new StringBuilder();
                    StringBuilder sb2 = new StringBuilder();

                    for (int j = 0; j < s.ArgCount; j++)
                    {
                        sb1.Append("arg" + j.ToString());
                        sb2.Append("object arg" + j.ToString());

                        if (j < s.ArgCount - 1)
                        {
                            sb1.Append(", ");
                            sb2.Append(", ");
                        }
                    }

                    writer.WriteLine("public string {{0}}({{1}}) { return String.Format(strings[{{2}}], {{3}}); }",
                                     s.Name, sb2.ToString(), i, sb1.ToString());
                }
            }

            writer.WriteLine("}");
            writer.WriteLine("}");
        }
Beispiel #3
0
        private StringsContent CreateStringsData(string className, StringsFileV1 stringsFile)
        {
            StringsContent stringsData = new StringsContent();

            stringsData.ClassName = className;
            stringsData.Strings   = new List <StringsContent.String>();

            string namespaceName;

            Target.Properties.GetRequiredValue("Namespace", out namespaceName);

            stringsData.Namespace = namespaceName;

            foreach (var s in stringsFile.Strings)
            {
                StringsContent.String d = new StringsContent.String();

                d.Name  = s.Name;
                d.Value = s.Value;

                // Count the args in the string
                int n = 0;

                for (int i = 0; i < d.Value.Length - 1; i++)
                {
                    if (d.Value[i] == '{' && d.Value[i + 1] != '{')
                    {
                        n++;
                    }
                }

                d.ArgCount = n;

                stringsData.Strings.Add(d);
            }

            return(stringsData);
        }
        private StringsContent CreateStringsData(string className, Dictionary<string, string> stringDict)
        {
            StringsContent stringsData = new StringsContent();

            stringsData.ClassName = className;
            stringsData.Strings = new List<StringsContent.String>();
            stringsData.Namespace = this.Namespace;

            foreach (var pair in stringDict)
            {
                StringsContent.String d = new StringsContent.String();

                d.Name = pair.Key;
                d.Value = pair.Value;

                // Count the args in the string
                int n = 0;

                for (int i = 0; i < d.Value.Length - 1; i++)
                {
                    if (d.Value[i] == '{' && d.Value[i + 1] != '{')
                    {
                        n++;
                    }
                }

                d.ArgCount = n;

                stringsData.Strings.Add(d);
            }

            return stringsData;
        }
        private StringsContent CreateStringsData(string className, StringsFileV1 stringsFile)
        {
            StringsContent stringsData = new StringsContent();

            stringsData.ClassName = className;
            stringsData.Strings = new List<StringsContent.String>();

            string namespaceName;

            Target.Properties.GetRequiredValue("Namespace", out namespaceName);

            stringsData.Namespace = namespaceName;

            foreach (var s in stringsFile.Strings)
            {
                StringsContent.String d = new StringsContent.String();

                d.Name = s.Name;
                d.Value = s.Value;

                // Count the args in the string
                int n = 0;

                for (int i = 0; i < d.Value.Length - 1; i++)
                {
                    if (d.Value[i] == '{' && d.Value[i + 1] != '{')
                    {
                        n++;
                    }
                }

                d.ArgCount = n;

                stringsData.Strings.Add(d);
            }

            return stringsData;
        }