Return 某些对象上的相同参数(按类型)

Return same Parameter On Some Objects By type

我希望删除我的 if 我能做什么?

我从数据库中检索我的数据,并且在所有类型中它们都有一些字段 名为 IsVerified

无论如何我可以删除 ifs???

private bool CheckDetailsAreVerified(type)
    {
        bool isVerified;

        if (type == sometype1)
        {
            isVerified = this.retrieveFromDB<obj1>()
            .somcondition()
            .All(it => it.IsVerified);
        }
        else if (type == sometype2)
        {
            isVerified = this.retrieveFromDB<obj2>()
            .somcondition()
            .All(it => it.IsVerified);
        }
        else if (type == sometype3)
        {
            isVerified = this.retrieveFromDB<obj3>()
            .somcondition()
            .All(it => it.IsVerified);
        }
        else if (type == sometype4)
        {
            isVerified = this.retrieveFromDB<obj4>()
            .somcondition()
            .All(it => it.IsVerified);
        }

        return isVerified;
    }

使用Reflection。方法名和类型名必须等于

public bool CheckDetailsAreVerified(string typeName)
{
   //"this" == CurrentClass
   var verified = typeof(CurrentClass).GetMethod(typeName).Invoke(null, null);
   return Convert.ToBoolean(verified);
}

private bool Type1()
{
   return isVerified = this.retrieveFromDB<obj1>()
            .somcondition()
            .All(it => it.IsVerified);
}

private bool Type2()
{
   return isVerified = this.retrieveFromDB<obj2>()
            .somcondition()
            .All(it => it.IsVerified);
}
//type3, type4...etc

如果你需要方法的参数:

public bool CheckDetailsAreVerified(string typeName)
{
   //"this" == CurrentClass
   var verified = typeof(CurrentClass).GetMethod(typeName).Invoke(null, 
                                                              new object[] 
                                                              { 
                                                              myIntList
                                                              });
   return Convert.ToBoolean(verified);
}

private bool TypeN(List<int> value)
{
   return isVerified = this.retrieveFromDB<obj1>()
            .somcondition()
            .All(it => it.IsVerified);
}