
Iquery ISelect (inherits Iquery) IUpdate (inherits Iquery) etc
在课堂上我有
queryBase (implements Iquery) Selectquery (implements ISelect) Updatequery (implements IUpdate) etc
显然,例如,Update类和Select类共享一个WHERE子句,但只有一个Select具有GROUP BY功能,所以理想情况下,如果正在创建更新查询,则流畅的接口将不会提供对GROUP BY功能的访问,但是如果Selectquery是被创造.
例如,用流利的界面术语
var/Dim select = New Selectquery() <- returns ISelect explicit .AddColumn(....) <- returns ISelect explicit .AdDWhere(....) <- returns ISelect inferred .AddGroupBy(....) <- returns ISelect explicit var/Dim update = New Updatequery() <- returns IUpdate explicit .AddSet(....) <- returns IUpdate explicit .AdDWhere(....) <- returns IUpdate inferred
我不确定如何实现AdDWhere功能.
以前我已经在Iquery接口中声明了AdDWhere函数
Function AdDWhere(ByVal condition As ICriterion) As IqueryIquery AdDWhere(ICriterion condition)
但是因为它返回了一个Iquery,我正在失去类型推断的好处,所以一旦流畅的接口转换为Iquery,如果它是一个Select查询被创建,我将不再有权访问,AddGroupBy方法.
所以我试图将它作为带有泛型的扩展方法来实现
<Extension>Public Function AdDWhere(Of T As Iquery)(Byval this as T,Byval condition as Condition) as T this.SetWhere(condition) Return MeEnd Functionpublic T AdDWhere<T>(T @this,Condition condition) where T : Iquery{ @this.SetWhere(condition); return this;} 在queryBase上使用FrIEnd(内部)方法SetWhere允许我更新WHERE子句.但是因为泛型受限于Iquery,所以它不会找到SetWhere.但是,如果我约束为queryBase,那么显然,编译器会抛出wobblIEs,说ISelect无法找到AdDWhere方法.
我认为我还没有完全正确的继承链或接口实现,我想要实现的目标.
(我希望很清楚!!)
如果有人可以建议我在扩展方法实现方面出错,或者我应该如何更好地构建我的类/接口层次结构,我将不胜感激.
解决方法Public Interface Iquery Function AdDWhere() As IqueryEnd InterfacePublic Interface IUpdate : inherits Iquery Overloads Function AdDWhere() As IUpdateEnd InterfacePublic Interface ISelect : inherits Iquery Overloads Function AdDWhere() As ISelect Function AddGroupBy() As ISelectEnd InterfacePublic Class queryBase : Implements Iquery Public Function AdDWhere() As Iquery Implements Iquery.AdDWhere ''... Return Me End FunctionEnd ClassPublic Class Updatequery : inherits queryBase : Implements IUpdate Public Shadows Function AdDWhere() As IUpdate Implements IUpdate.AdDWhere MyBase.AdDWhere() Return Me End FunctionEnd ClassPublic Class Selectquery : inherits queryBase : Implements ISelect Public Shadows Function AdDWhere() As ISelect Implements ISelect.AdDWhere MyBase.AdDWhere() Return Me End Function Public Function AddGroupBy() As ISelect Implements ISelect.AddGroupBy ''... Return Me End FunctionEnd Class总结
以上是内存溢出为你收集整理的c# – 使用具有流畅接口的类型推断全部内容,希望文章能够帮你解决c# – 使用具有流畅接口的类型推断所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
微信扫一扫
支付宝扫一扫
评论列表(0条)