Click here to Skip to main content
15,896,154 members
Articles / Web Development / ASP.NET

Customize the Code Generated by the Resources Designer

Rate me:
Please Sign up or sign in to vote.
3.83/5 (6 votes)
19 Dec 2008CPOL8 min read 47.2K   970   38  
Customize the code generated by the resources designer
// -------------------------------------------------------
// Automatically generated with Kodeo's Reegenerator
// Generator: RgenTemplate (internal)
// Generation date: 2008-12-10 03:43
// Generated by: KODEO1\radusib
// -------------------------------------------------------
namespace CustomizeDesigners
{
    using System;
    using Kodeo.Reegenerator;
    using Kodeo.Reegenerator.Wrappers;
    
    
    public partial class XsdRenderers : Kodeo.Reegenerator.Generators.CodeRenderer
    {
        
        /// <summary>
        ///Renders the code as defined in the source script file.
        ///</summary>
        ///<returns></returns>
        public override Kodeo.Reegenerator.Generators.RenderResults Render()
        {
            base.Output.Write("// -------------------------------------------------------\r\n// Automatically gene" +
                    "rated with Kodeo\'s Reegenerator\r\n// Generator: XsdRenderers\r\n// Generation date:" +
                    " ");
            base.Output.Write(System.DateTime.Now.ToString("yyyy-MM-dd hh:mm"));
            base.Output.Write("\r\n// Generated by: ");
            base.Output.Write(System.Security.Principal.WindowsIdentity.GetCurrent().Name);
            base.Output.Write("\r\n// -------------------------------------------------------\r\n\r\n");
            base.Output.Write(this.RenderSchema("C#"));
            base.Output.Write("\r\n\r\nnamespace ");
            base.Output.Write(this._xmlSchema.CodeNamespace);
            base.Output.Write("\r\n{\r\n\tusing System;\r\n\tusing System.IO;\r\n\tusing System.Xml;\r\n\tusing System.Xml.Sch" +
                    "ema;\r\n\tusing System.Xml.Serialization;\r\n\tusing System.Text;\r\n\r\n\t/// <summary>\r\n\t" +
                    "/// Factory class for classes defined in the ");
            base.Output.Write(this._xmlSchema.Id);
            base.Output.Write(" xml schema.\r\n\t/// </summary>\r\n\tpublic class ");
            base.Output.Write(this._xmlSchema.Id);
            base.Output.Write("Factory\r\n\t{\r\n\t\t/// <summary>\r\n\t\t/// The contents of the ");
            base.Output.Write(this._xmlSchema.Id);
            base.Output.Write(" xml schema.\r\n\t\t/// It is used to check the validity of xml files against the xml" +
                    " schema.\r\n\t\t/// </summary>\r\n\t\tpublic static string SchemaXml = \r\n@\"");
            base.Output.Write(this.XmlSchemaContent.Replace("\"", "\"\""));
            base.Output.Write("\";\r\n        \r\n        /// <summary>\r\n        /// Gets a compiled schema set that " +
                    "contains a schema object created from <see cref=\"SchemaXml\"/>\r\n        /// </sum" +
                    "mary>\r\n        public static XmlSchemaSet CompiledSchemaSet\r\n        {\r\n        " +
                    "    get\r\n            {\r\n                if (_xmlSchemaSet == null)\r\n            " +
                    "    {\r\n                    XmlSchemaSet xmlSchemaSet = new XmlSchemaSet();\r\n    " +
                    "                XmlSchema xmlSchema;\r\n                    using (StringReader sr" +
                    " = new StringReader(SchemaXml))\r\n                    {\r\n                        " +
                    "using (XmlReader reader = XmlReader.Create(sr))\r\n                        {\r\n    " +
                    "                        xmlSchema = XmlSchema.Read(reader, null);\r\n             " +
                    "           }\r\n                    }\r\n                    xmlSchemaSet.Add(xmlSch" +
                    "ema);\r\n                    xmlSchemaSet.Compile();\r\n                    _xmlSche" +
                    "maSet = xmlSchemaSet;\r\n                }\r\n                return _xmlSchemaSet;\r" +
                    "\n            }\r\n        } private static XmlSchemaSet _xmlSchemaSet = null;\r\n\r\n\t" +
                    "\t/// <summary>\r\n\t\t/// Creates an object by deserializing the content of an xml d" +
                    "ocument\r\n\t\t/// into an instance of the <typeparamref name=\"T\"/>.\r\n\t\t/// <typepar" +
                    "amref name=\"T\"/> must implement <see cref=\"XsdRenderers.IInitializable\"/> to\r\n\t\t" +
                    "/// be initialized post creation.\r\n\t\t/// </summary>\r\n\t\t/// <typeparam name=\"T\">T" +
                    "he type of the instance to be created from the <paramref name=\"projectItem\"/>.</" +
                    "typeparam>\r\n\t\t/// <param name=\"projectItem\">The XML file project item.</param>\r\n" +
                    "\t\t/// <returns>An instance of type <typeparamref name=\"T\"/>.</returns>\r\n\t\tpublic" +
                    " static T Create<T>(Kodeo.Reegenerator.Wrappers.ProjectItem projectItem)  \r\n\t\t{\r" +
                    "\n\t\t\tif (projectItem == null)\r\n\t\t\t\tthrow new ArgumentNullException(\"projectItem\")" +
                    ";\r\n\t\t\t\t\r\n\t\t\tXmlReaderSettings xmlReaderSettings = new XmlReaderSettings();\r\n\t\t\tx" +
                    "mlReaderSettings.ValidationType = ValidationType.Schema;\r\n\t\t\txmlReaderSettings.S" +
                    "chemas = CompiledSchemaSet;\r\n\t\t\txmlReaderSettings.ValidationEventHandler += new " +
                    "ValidationEventHandler(ValidationCallBack);\r\n\t\t\t\t\r\n\t\t\tXmlSerializer xmlSerialize" +
                    "r = new XmlSerializer(typeof(T));\r\n\t\t\tT result;\r\n\t\t\tusing (XmlReader reader = Xm" +
                    "lReader.Create(projectItem.FullPath, xmlReaderSettings))\r\n\t\t\t{\r\n\t\t\t\tresult = (T)" +
                    "xmlSerializer.Deserialize(reader);\r\n\t\t\t}\r\n\t\t\tstring error = sb.ToString();\r\n\t\t\ti" +
                    "f (error.Length > 0)\r\n\t\t\t\tthrow new XmlException(error);\r\n\t\t\t\r\n\t\t\tXsdRenderers.I" +
                    "Initializable init = result as XsdRenderers.IInitializable;\r\n\t\t\tif (init != null" +
                    ")\r\n\t\t\t{\r\n\t\t\t    init.Init(projectItem);\r\n\t\t\t}\r\n\t\t\treturn result;\r\n\t\t} static Str" +
                    "ingBuilder sb = new StringBuilder();\r\n\t\t\r\n\t\tprivate static void ValidationCallBa" +
                    "ck(object sender, ValidationEventArgs e)\r\n\t\t{\r\n\t\t\tif (sb.Length > 0)\r\n\t\t\t\tsb.App" +
                    "endLine();\r\n\t\t\tsb.AppendFormat(\"Xml Validation Error ({0}, {1}): {2}\", e.Excepti" +
                    "on.LineNumber, e.Exception.LinePosition, e.Message);\r\n\t\t}\r\n\t}\r\n}");
            return new Kodeo.Reegenerator.Generators.RenderResults(base.Output.ToString());
        }
    }
}

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
Architect
New Zealand New Zealand
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.

Comments and Discussions