【问题标题】:How to check whether an object has certain method/property of particular type within it?如何检查对象是否具有特定类型的某些方法/属性?
【发布时间】:2016-04-20 11:36:05
【问题描述】:

我的 DInfo 类存在于两个不同的命名空间中,即ABC.DomainABC.Common 我从数据库中获取 xml 正文作为记录,我从中反序列化为相应的类型。 我必须找出所有使用属性名称/名称为ABC.Domain.DInfo 类型的属性的记录,而忽略ABC.Common.DInfo 类型的属性

作为我正在获取 IEvent 类型的记录,即可能是 FSubmittedGSubmitted

namespace ABC.Domain
{
    public class DInfo
    {
        public DateTime? Date { get; set; }
        public URef User { get; set; }
        public Decimal? L1 { get; set; }
        public Decimal? L2 { get; set; }
    }
}
namespace ABC.Common
{
    public class DInfo
    {
        public DateTime? Date { get; set; }
        public URef User { get; set; }
        public Decimal? L1 { get; set; }
        public Decimal? L2 { get; set; }
    }
}

public class Event : IEvent
{

    public Guid Id { get; set; }

    public Event() { }

    public int Number { get; set; }
}

public interface IEvent : IRBase
{
    Guid Id { get; set; }

    int Number { get; set; }

}
public interface IRBase
{
    string RUser { get; set; }
    string Sub { get; set; }
}

public abstract class REventBase : Event
{
    public Guid Id { get; set; }
}


public class FSubmitted : REventBase
{
    public RSummary NewForm { get; set; }
}
public class GSubmitted : REventBase
{
    public FRef NewForm { get; set; }
}

public class RSummary
{
    public Guid ID { get; set; }

    public FRef FRef { get; set; }

    public ABC.Common.DInfo Submitted { get; set; }

    public ABC.Common.DInfo Saved { get; set; }

    public ABC.Domain.DInfo Signed { get; set; }
}


public class FRef : NIdentifier<Guid>
{
    public FormType Type { get; set; }
    public Version Version { get; set; }
    public ABC.Common.DInfo Submitted { get; set; }
    public ABC.Domain.DInfo Saved { get; set; }
}

【问题讨论】:

标签: c# serialization reflection deserialization datacontractserializer


【解决方案1】:

只要我理解你,你想获取对象的命名空间,然后决定如何处理它。如果是这种情况,this 应该会有所帮助。

【讨论】:

    猜你喜欢
    • 2011-07-04
    • 1970-01-01
    • 2021-03-12
    • 2012-04-16
    • 1970-01-01
    • 1970-01-01
    • 2017-10-09
    • 1970-01-01
    相关资源
    最近更新 更多