我对vb.net真的很陌生,我希望减少这些代码的冗余,但我不确定如何
ONE.DisplayLayout.Override.FilterOperandStyle = FilterOperandStyle.FilterUIProvider
ONE.DisplayLayout.Override.FilterUIType = FilterUIType.FilterRow
ONE.DisplayLayout.Override.FilterUIProvider = New SupportDialogs.FilterUIProvider.UltraGridFilterUIProvider()
TWO.DisplayLayout.Override.FilterOperandStyle = FilterOperandStyle.FilterUIProvider
TWO.DisplayLayout.Override.FilterUIType = FilterUIType.FilterRow
TWO.DisplayLayout.Override.FilterUIProvider = New SupportDialogs.FilterUIProvider.UltraGridFilterUIProvider()
THREE.DisplayLayout.Override.FilterOperandStyle = FilterOperandStyle.FilterUIProvider
THREE.DisplayLayout.Override.FilterUIType = FilterUIType.FilterRow
THREE.DisplayLayout.Override.FilterUIProvider = New SupportDialogs.FilterUIProvider.UltraGridFilterUIProvider()
正如您所看到的,唯一的区别是ONE,TWO和THREE。如何在不重复的情况下简化此操作?
谢谢!
答案 0 :(得分:4)
我不知道ONE,TWO和THREE的类型是什么,但你可以制作一个子:
Public Sub DoStuff(Data As YourType)
Data.DisplayLayout.Override.FilterOperandStyle = FilterOperandStyle.FilterUIProvider
Data.DisplayLayout.Override.FilterUIType = FilterUIType.FilterRow
Data.DisplayLayout.Override.FilterUIProvider = New SupportDialogs.FilterUIProvider.UltraGridFilterUIProvider()
End Sub
你可以通过
来称呼它DoStuff(ONE)
DoStuff(TWO)
DoStuff(THREE)
更新(遵循Andrew Morton的评论)
如果你有三个以上的项目,你可以运行一个循环:
For each x In { ONE, TWO, THREE }
DoStuff(x)
Next