Reflection类,用于获取不返回所有属性的任何对象的所有属性

时间:2016-04-20 14:31:07

标签: c# .net reflection

我必须找出对象中的所有属性,因为我使用方法e.GetType()。GetProperties()

是从IEvent继承的动态类型。 e有多种属性

我面临的问题是propertyInfos集合不包含来自RSummary的ABC.Domain.Contract.Base.DInfo,只有来自REventBase Class的ABC.Comon.Contract.Base.DInfo

我需要这两个类都应该在propertyInfos集合中。

是否有任何我必须提供的特定属性会使所有DInfo无论名称空间是什么

private static void ProcessEvents()
{
    try
    {
        foreach (var e in allEvents)
        {
            try
            {

                PropertyInfo[] propertyInfos;

                //MemberInfo[] info = type.FindMembers(MemberTypes.All, BindingFlags.Instance | BindingFlags.NonPublic, new MemberFilter(searchFilter), "tt");
                //MemberInfo[] info = type.FindMembers(MemberTypes.All, BindingFlags.Default, new MemberFilter(searchFilter), "Submitted");
                propertyInfos = e.GetType().GetProperties(
                    BindingFlags.Public | BindingFlags.NonPublic // Get public and non-public
                    | BindingFlags.Static | BindingFlags.Instance // Get instance + static
                    | BindingFlags.FlattenHierarchy | BindingFlags.ExactBinding);
                foreach (var property in propertyInfos)
                {
                    if (property.PropertyType == typeof(ABC.Domain.Contract.Base.DInfo))
                    {
                        //Do something 
                    }
                    else
                    {
                        //Do something  Do Something Else
                    }
                }
            }
            catch (Exception ea)
            {
            }
        }
    }
    catch (Exception ea)
    {
    }
}


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

public abstract class REventBase : Event
{
    public Guid RId { get; set; }
    public ABC.Comon.Contract.Base.DInfo RDInfo { get; set; }
}

public class RSummary
{
    public Guid ID { get; set; }
    //public FormType Type { get; set; }
    public FRef FRef { get; set; }
    public ABC.Domain.Contract.Base.DInfo Submitted { get; set; }
    public ABC.Domain.Contract.Base.DInfo Saved { get; set; }
    public ABC.Domain.Contract.Base.DInfo Signed { get; set; }
    public bool IsSigned { get; set; }
}



public class DInfo
{
    public bool someThing { get; set; }
}


public class DInfo
{
    public bool someThing { get; set; }
}

0 个答案:

没有答案