C# 如何找到我的属性信息类型?

C# 如何找到我的属性信息类型?,c#,.net,reflection,C#,.net,Reflection,我有以下代码: public class EntityBase { public virtual void Freez(EntityBase obj) { //TO DO } 我的示例中的任何类都继承自EntityBase;像这样: public class Person:EntityBase { public Person() { this.PersonAsset = new Asset { Title =

我有以下代码:

 public class EntityBase
{


 public virtual void Freez(EntityBase obj)
 {
    //TO DO

 }
我的示例中的任何类都继承自EntityBase;像这样:

  public class Person:EntityBase
    {
       public Person()
       {
           this.PersonAsset = new Asset { Title = "asset1" };
       }
        public string Name { get; set; }
       public Asset PersonAsset{get;set;}


    }
   public class Asset : EntityBase
   {
       public string Title { get; set; }
   }
如果person的属性是PersonAsset之类的类,我想在调用person.Freez()时调用person.Freez; 我想我必须在EntityBase Freez()方法中使用反射
通过反射,如何提升其Freez()方法?或者如何找到我的propertyinfo是一个类

您所提供的解决方案的设计有问题,您试图在基类中硬编码一种行为,这种行为非常特定于嵌套类实现(它具有PersonAsset属性)。请描述您试图在业务逻辑方面实现的目标。我希望在调用person class Freeze()方法时,myclass中从EntityBase继承的任何属性都能调用其Freez()方法?因为一个Freezable实体可能包含其他Freezable实体,所以您需要防止循环引用,否则您将遇到非终止循环…Tnk you Sjoerd。我想知道我的公共资产PersonAsset{get;set;}是否是公共列表PersonAsset{get;set;}…我可以从列表中的任何项目中执行解决方案吗?我编辑了代码,以在所有集合中循环查找EntityBase对象。
public virtual void Freez()
{
    foreach (var prop in this.GetType().GetProperties())
    {
        if (prop.PropertyType.IsClass && typeof(EntityBase).IsAssignableFrom(prop.PropertyType))
        {
            var value = (EntityBase) prop.GetValue(this, null);
            value.Freez();
        }

        if (typeof(ICollection).IsAssignableFrom(prop.PropertyType))
        {
            var collection = (ICollection)prop.GetValue(this, null);
            if (collection != null)
            {
                foreach (var obj in collection)
                {
                    if (obj is EntityBase)
                    {
                        ((EntityBase)obj).Freez();
                    }
                }
            }
        }
    }
}