C# 反射派生类条件

C# 反射派生类条件,c#,.net,linq,entity-framework,reflection,C#,.net,Linq,Entity Framework,Reflection,我有一个从IComplexAuditableEntity继承的对象实例,我需要继承ILogableEntity的派生类 我想象下面这样的代码,但我做不到 if (dbObjectEntry is IComplexAuditableEntity) { dbObjectEntry.GetType()...().where(basetype == ILogabbleEntity) } public partial class User : IComplexAuditableEntity {

我有一个从IComplexAuditableEntity继承的对象实例,我需要继承ILogableEntity的派生类

我想象下面这样的代码,但我做不到

if (dbObjectEntry is IComplexAuditableEntity)
{
    dbObjectEntry.GetType()...().where(basetype == ILogabbleEntity)
}

public partial class User : IComplexAuditableEntity
{     
    public int Id { get; set; }
    public string Email { get; set; }
    public string UserPassword { get; set; }
    public string UserName { get; set; }
    public string LastName { get; set; }
    public string FirstName { get; set; }
}

public class UserLog:User,ILogabbleEntity
{
    public int ModifiedBy { get; set; }
    public DateTime Modified { get; set; }
}

public interface IComplexAuditableEntity
{
}

public interface ILogabbleEntity
{
    int ModifiedBy { get; set; }
    DateTime Modified { get; set; }
}

你想在这里做什么?你的问题不清楚。尝试重新表述它。我正在尝试一些东西,比如var logObject=object.GetType().GetDerivedClass()。其中(basetype==Typeof(ilogableEntity)),我不确定您的层次结构试图实现什么。如果
dbObjectEntry
最初是一个
UserLog
,那么您可以将
dbObjectEntry用作ilogableentity
。如果它最初是一个
用户
,那么该对象实例将不会有进一步的派生类型信息。是的,dbObjectEntry最初是一个用户,在我想要创建一个UserLog对象并保存它之后保存的用户对象。