Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/282.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# 使用具有不同XmlElementAttribute的自动生成的项对象_C# - Fatal编程技术网

C# 使用具有不同XmlElementAttribute的自动生成的项对象

C# 使用具有不同XmlElementAttribute的自动生成的项对象,c#,C#,仅当对象项的类型为Company时,我才需要获取该对象项。 下面是从相应的xsd自动生成的代码: private object itemField; [System.Xml.Serialization.XmlElementAttribute("Company", typeof(Company), Order=1)] [System.Xml.Serialization.XmlElementAttribute("Customer", typeof(Customer)

仅当对象项的类型为Company时,我才需要获取该对象项。 下面是从相应的xsd自动生成的代码:

        private object itemField;

    [System.Xml.Serialization.XmlElementAttribute("Company", typeof(Company), Order=1)]
    [System.Xml.Serialization.XmlElementAttribute("Customer", typeof(Customer), Order=1)]
    public object Item {
        get {
            return this.itemField;
        }
        set {
            this.itemField = value;
            this.RaisePropertyChanged("Item");
        }
    }
公司类别如下:

public partial class Company : object, System.ComponentModel.INotifyPropertyChanged {

    private string companyNameField;

    private CompanyCompanyType companyTypeField;

    private string companyIDField;

    private string commissionCodeField;

    /// <remarks/>
    [System.Xml.Serialization.XmlElementAttribute(Order=0)]
    public string CompanyName {
        get {
            return this.companyNameField;
        }
        set {
            this.companyNameField = value;
            this.RaisePropertyChanged("CompanyName");
        }
    }
但是,当Item对象的类型为Customer。。。
你能帮我个忙吗?

我想你指的是
((公司)项目)。公司名称
,是吗<代码>项目
的类型为
对象
,它没有
公司名称的定义
。为什么不简单地检查
项目
的类型是否为
公司
?如果是这样,请进行转换,否则将转换为
客户
。谢谢您,布朗比尔:)
(Company)Item.CompanyName