public class CompareParameter<T>
{
public string FieldName { get; set; }
public T FieldValue { get; set; }
public CompareType CompareType { get; set; }
}
接口
public interface IMongoConnectionFactory
{
int GetCountWithFilter<T>(params object[] param) where T:EntityBase;
}
接口實現
public class MongoConnectionFactory : IMongoConnectionFactory
{
public int GetCountWithFilter<T>(params object[] param) where T : RedBusPlusEntities.EntityBase
{
throw new NotImplementationException();
}
}
商業行爲準則
public int GetCustomerCount(int operatorId, int day)
{
Customer c = new Customer();
CompareParameter<int> OpId = new CompareParameter<int>();
OpId.FieldName=GetMemberName.GetName(() => c.OpId);
OpId.FieldValue=operatorId;
OpId.CompareType=CompareType.EQ;
CompareParameter<long> Day = new CompareParameter<long>();
Day.FieldName=GetMemberName.GetName(() => c.Doil);
Day.FieldValue=GetStartDateOfIssue(day);
Day.CompareType = CompareType.GTE;
return _fac.GetCountWithFilter<Customer>(OpId, Day);
}
所以在這裏,我傳遞了兩個不同類型的兩個PARAM從商業到DAL。所以我把它從object
傳入。現在我該如何構建在接口實現中傳遞的相同類型。嘗試了一些與Convert.ChangeType
的方法,但失敗了。有人可以幫助我嗎?
這將有助於瞭解你INT GetCountWithFilter(params對象[] PARAM)內做什麼,因爲它可能比[對象] –
我想其他的東西來傳遞通過傳遞參數對象來創建一個mongo過濾器查詢。 mongo查詢看起來像'var filter = builder.Eq(「cuisine」,「Italian」)&builder。公式(「拉鍊」,10075);'傳遞的對象包含用於創建過濾器 – user3132179
的必要的信息和類型,因此你能不能改變你的接口爲: 公共接口IMongoConnectionFactory { INT GetCountWithFilter(PARAMS CompareParameter [] PARAM)其中T:EntityBase; } –