简体   繁体   English

如何检查对象中是否具有特定类型的特定方法/属性?

[英]How to check whether an object has certain method/property of particular type within it?

I have DInfo class present in two different namespaces ie ABC.Domain and ABC.Common I am getting xml body as a record from database from which I am deserializing to respective type. 我在两个不同的命名空间(即ABC.DomainABC.Common存在DInfo类。我从数据库ABC.Common xml正文作为记录进行记录,从该记录中我反序列化为相应的类型。 I have to find out all the records which are using properties with name/names of properties of type ABC.Domain.DInfo and just ignore of type ABC.Common.DInfo 我必须找出所有使用属性的名称/名称为ABC.Domain.DInfo类型的属性的ABC.Domain.DInfo而忽略ABC.Common.DInfo类型的ABC.Common.DInfo

As a I am getting record of type IEvent ie may be FSubmitted or GSubmitted 作为我正在获取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; }
}

As long as I understand you, you want to get the namespace of the object and then decide what to do with it. 据我了解,您想要获取对象的名称空间,然后决定如何处理它。 If this is the case, this should help. 如果是这样的话, 应该帮助。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM