Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/xml/14.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
添加到继承的C#类XML元素_C#_Xml_Inheritance_Serialization - Fatal编程技术网

添加到继承的C#类XML元素

添加到继承的C#类XML元素,c#,xml,inheritance,serialization,C#,Xml,Inheritance,Serialization,是否有任何方法可以添加到继承类中的子类?我有一个巨大的类文件,通过XSD到类文件生成器运行。我不希望每次对XSD文件进行更新时都必须手动编辑生成的文件。是否有任何方法可以继承生成文件的所有成员并添加到其子类 示例:如果我想添加字符串Child\u String2,我该怎么做 File1.cs namespace test { class AutoGenerated { string Parent_string { ge

是否有任何方法可以添加到继承类中的子类?我有一个巨大的类文件,通过XSD到类文件生成器运行。我不希望每次对XSD文件进行更新时都必须手动编辑生成的文件。是否有任何方法可以继承生成文件的所有成员并添加到其子类

示例:如果我想添加字符串Child\u String2,我该怎么做

   File1.cs
    namespace test
    {
        class AutoGenerated
        {
            string Parent_string { get; set; }
            public class Child
            {
                string child_string1 { get; set; }
                //I want to add string Child_String2 {get;set;} at this level in to ModifiedParent from file "MyAttempt.cs"
            }
        }
    }

   MyAttempt.cs
   namespace test
   {
       class ModifiedParent: Parent
       {
        Child.string child_string2{get;set;} 
       }
   }
这显然不起作用,但目的是将child_string2添加到Parent内部的子类中

有没有办法完成这样的事情

这个问题的最初原因是因为我需要序列化/反序列化到我要添加到的类。如果我只是从“Child”继承,我可以在“Parent”的内部分配修改过的“Child”,但是序列化程序会出现问题,因为它不需要Child\u string2

任何提示,建议,甚至链接到解决这个我将不胜感激

编辑:
因此,在与同事讨论并在网上搜索之后,我们似乎还没有找到任何直接的解决方案。不幸的是,听起来最好的方法就是编辑生成的CS文件。我确实可以访问生成器,所以我决定最好的方法是在生成器中添加几行代码,以便在每次生成时进行适当的更改。

这可能是一个愚蠢的问题,但child_string2是在哪里生成的?创建您自己的模式补充您已有的模式。child_string2我希望同时添加级别为child_string1。因此ModifiedParent的最后一个对象将包含父字符串和子元素。然后,Child元素将包含Child_string1和Child_string2。因此,在与同事讨论并在线搜索之后,我们似乎还没有找到任何直接的解决方案。不幸的是,听起来最好的方法就是编辑生成的CS文件。不过,我确实可以访问生成器,所以我决定最好的方法是在生成器中添加几行代码以进行适当的更改。这可能是一个愚蠢的问题,但child_string2是在哪里生成的?创建您自己的架构补充您已有的架构。child_string2我希望添加的级别与孩子们。因此ModifiedParent的最后一个对象将包含父字符串和子元素。然后,Child元素将包含Child_string1和Child_string2。因此,在与同事讨论并在线搜索之后,我们似乎还没有找到任何直接的解决方案。不幸的是,听起来最好的方法就是编辑生成的CS文件。但是,我确实可以访问生成器,所以我决定最好的方法是在生成器中添加几行代码,以进行适当的更改。