如何限制或描述对象的可能性

时间:2018-07-09 08:41:23

标签: c# xml serialization dll

我有一个非常特殊的问题。 我有一个xsd模式,并从中生成类。就像Microsoft的xsd.exe一样。现在,我想将此生成的文件用作dll。到目前为止,一切都很好。

示例代码:

    public enum UnnamedChoice115 {
         UNDEFINIERT, 
         nur_Zustandsanzeige, 
         Zustandsanzeige_und_Steuerstelle, 
         Zustandsanzeige_und_Steuerstelle_AUTO, 
    }

    [System.SerializableAttribute()]
    [System.Diagnostics.DebuggerStepThroughAttribute()]
    [System.ComponentModel.DesignerCategoryAttribute("code")]
    public class ctyp_PLS_Anbindung_InOutByte
    {
       private object objgenField;
       [System.Xml.Serialization.XmlElementAttribute("nur_Zustandsanzeige", typeof(ctyp_PLS_A), Form=System.Xml.Schema.XmlSchemaForm.Unqualified)]
       [System.Xml.Serialization.XmlElementAttribute("Zustandsanzeige_und_Steuerstelle", typeof(ctyp_PLS_B), Form=System.Xml.Schema.XmlSchemaForm.Unqualified)]
       [System.Xml.Serialization.XmlElementAttribute("Zustandsanzeige_und_Steuerstelle_AUTO", typeof(ctyp_PLS_C), Form=System.Xml.Schema.XmlSchemaForm.Unqualified)]
       [System.Xml.Serialization.XmlChoiceIdentifierAttribute("objIdentifier")]
       public object objGen
       {
          get { return objgenField; }
          set { objgenField = value;}
       }

       private UnnamedChoice115 objidentifierField;
       [System.Xml.Serialization.XmlIgnoreAttribute()]
       public UnnamedChoice115 objIdentifier
       {
          get { return objidentifierField; }
          set { objidentifierField = value; }
       }
    }

您将看到objGen属性是对象的类型,但是序列化允许三种不同的类型'ctyp_PLS_A','ctyp_PLS_B'或'ctyp_PLS_C'。 如何获得此信息给已编译的dll的用户? 为此确实很难实现基类型,因此我想在dll中进行一个简单的描述,即“嘿,程序员,您只能将这些类型与该属性一起使用”。更像是集成的使用信息。最好的事情是对编译器的支持,但是...如果我不知道怎么做。

0 个答案:

没有答案