Exemple #1
0
        private void BuildResources(IStreamSource source)
        {
            string resxMarkup = GetMarkup(source);
            List<ResXItem> resourceItems = ResXParser.ParseResxMarkup(resxMarkup);

            string resourceName = Utility.GetResourceFileName(source.Name);
            Dictionary<string, ResXItem> existingResourceItems = symbols.GetResources(resourceName);

            foreach (ResXItem item in resourceItems) existingResourceItems[item.Name] = item;
        }
Exemple #2
0
        public void GenerateCode(string resourceFileName, string resourceFileContent, string resourceGenerator)
        {
            if (IsLocalizedResourceFile(resourceFileName))
            {
                return;
            }

            List <ResXItem> resourceItems = ResXParser.ParseResxMarkup(resourceFileContent);

            if (resourceItems.Count == 0)
            {
                return;
            }

            string className      = Path.GetFileNameWithoutExtension(resourceFileName);
            string accessModifier = "internal";

            if (string.Compare(resourceGenerator, "PublicResxScriptGenerator", StringComparison.OrdinalIgnoreCase) == 0)
            {
                accessModifier = "public";
            }

            codeBuilder.AppendLine();
            codeBuilder.AppendFormat("    /// <summary>{0} resources class</summary>", className);
            codeBuilder.AppendLine();
            codeBuilder.AppendLine("    [ScriptResources]");
            codeBuilder.AppendFormat("    [GeneratedCodeAttribute(\"{0}\", \"{1}\")]",
                                     this.GetType().Name,
                                     typeof(ResXCodeBuilder).Assembly.GetName().Version.ToString());
            codeBuilder.AppendLine();
            codeBuilder.AppendFormat("    {0} static class {1} {{", accessModifier, className);
            codeBuilder.AppendLine();

            foreach (ResXItem resourceItem in resourceItems)
            {
                codeBuilder.AppendLine();
                if (resourceItem.Comment.Length != 0)
                {
                    codeBuilder.AppendFormat("        /// <summary>{0}</summary>", resourceItem.Comment);
                    codeBuilder.AppendLine();
                }
                codeBuilder.AppendFormat("        public static readonly string {0} = null;", resourceItem.Name);
                codeBuilder.AppendLine();
            }

            codeBuilder.AppendLine("    }");
        }
Exemple #3
0
        public void GenerateCode(string resourceFileName, string resourceFileContent)
        {
            if (IsLocalizedResourceFile(resourceFileName))
            {
                return;
            }

            List <ResXItem> resourceItems = ResXParser.ParseResxMarkup(resourceFileContent);

            if (resourceItems.Count == 0)
            {
                return;
            }

            string className = Path.GetFileNameWithoutExtension(resourceFileName);

            _codeBuilder.AppendLine();
            _codeBuilder.AppendFormat("    /// <summary>{0} resources class</summary>", className);
            _codeBuilder.AppendLine();
            _codeBuilder.AppendLine("    [Resources]");
            _codeBuilder.AppendFormat("    [GeneratedCodeAttribute(\"{0}\", \"{1}\")]",
                                      this.GetType().Name,
                                      typeof(ResXCodeBuilder).Assembly.GetName().Version.ToString());
            _codeBuilder.AppendLine();
            _codeBuilder.AppendFormat("    public static class {0} {{", className);
            _codeBuilder.AppendLine();

            foreach (ResXItem resourceItem in resourceItems)
            {
                _codeBuilder.AppendLine();
                if (resourceItem.Comment.Length != 0)
                {
                    _codeBuilder.AppendFormat("        /// <summary>{0}</summary>", resourceItem.Comment);
                    _codeBuilder.AppendLine();
                }
                _codeBuilder.AppendFormat("        public static readonly string {0} = null;", resourceItem.Name);
                _codeBuilder.AppendLine();
            }

            _codeBuilder.AppendLine("    }");
        }
Exemple #4
0
        public string GenerateCode(string resourceFileName, string resourceFileContent, string namespaceName)
        {
            if (IsLocalizedResourceFile(resourceFileName))
            {
                return(null);
            }

            List <ResXItem> resourceItems = ResXParser.ParseResxMarkup(resourceFileContent);

            if (resourceItems.Count == 0)
            {
                return(null);
            }

            string className = Path.GetFileNameWithoutExtension(resourceFileName);

            StringBuilder codeBuilder = new StringBuilder(2048);

            codeBuilder.AppendLine("//------------------------------------------------------------------------------");
            codeBuilder.AppendLine("// <auto-generated>");
            codeBuilder.Append("// ");
            codeBuilder.Append(className);
            codeBuilder.AppendLine(".cs");
            codeBuilder.AppendLine("//");
            codeBuilder.Append("// Do not edit directly. This file has been generated by ");
            codeBuilder.Append(GetGeneratorName());
            codeBuilder.AppendLine(".");
            codeBuilder.AppendLine("// </auto-generated>");
            codeBuilder.AppendLine("//------------------------------------------------------------------------------");
            codeBuilder.AppendLine();
            codeBuilder.AppendLine("using System;");
            codeBuilder.AppendLine("using System.CodeDom.Compiler;");
            codeBuilder.AppendLine("using System.Runtime.CompilerServices;");
            codeBuilder.AppendLine();
            codeBuilder.Append("namespace ");
            codeBuilder.Append(namespaceName);
            codeBuilder.AppendLine(" {");
            codeBuilder.AppendLine();
            codeBuilder.Append("    /// <summary>");
            codeBuilder.Append(className);
            codeBuilder.AppendLine(" resources class</summary>");
            codeBuilder.Append("    [GeneratedCodeAttribute(\"");
            codeBuilder.Append(this.GetType().Name);
            codeBuilder.Append("\", \"");
            codeBuilder.Append(typeof(ResXScriptGenerator).Assembly.GetName().Version.ToString());
            codeBuilder.AppendLine("\")]");
            codeBuilder.AppendLine("    [Resources]");
            codeBuilder.Append(_publicResources ? "    public" : "    internal");
            codeBuilder.Append(" static class ");
            codeBuilder.Append(className);
            codeBuilder.AppendLine(" {");

            foreach (ResXItem resourceItem in resourceItems)
            {
                codeBuilder.AppendLine();
                if (resourceItem.Comment.Length != 0)
                {
                    codeBuilder.Append("        /// <summary>");
                    codeBuilder.Append(resourceItem.Comment);
                    codeBuilder.AppendLine("</summary>");
                }
                codeBuilder.Append("        public static readonly string ");
                codeBuilder.Append(resourceItem.Name);
                codeBuilder.AppendLine(" = null;");
            }

            codeBuilder.AppendLine("    }");
            codeBuilder.AppendLine("}");

            return(codeBuilder.ToString());
        }