mercredi 20 avril 2016

Reflection class to get all properties of any object not returning all properties

I have to find out all the properties within the object for that I am using method e.GetType().GetProperties()

e is dynamic type inheriting from IEvent . e has multiple propertie s

Issue which I am facing is propertyInfos collection does not contain ABC.Domain.Contract.Base.DInfo from RSummary and only it has ABC.Comon.Contract.Base.DInfo from REventBase Class

I need both the classes should come in propertyInfos collection.

Is there any specific property which I have to provide which will bring all DInfo irresppective of there namespaces

namespace MyNamespace
{
 public class Class1
    {

        {
        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
                                }
                            }
                        }


                    }
                }
            }
        }

        public class FSubmitted : RecordEventBase
        {
            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; }
        }

    }
}

namespace ABC.Domain.Contract.Base
{
    public class DInfo
    {
         public bool someThing { get; set; }
    }
}

namespace ABC.Comon.Contract.Base
{
    public class DInfo
    {
         public bool someThing { get; set; }
    }
}





Aucun commentaire:

Enregistrer un commentaire