你也可能抱怨我上面的百分数计算太不科学,要算也应该拿全部来算,那就不妙了,好吧,看来也只能拿十分“老的““成熟“的来开刀了,下面便是削减代码二期工程,我们的目标是让成熟变干练,太过成熟的确不合某些同志的胃口。对应于AB两文件的类clsA/B,分别至少有30和15个属性,还好,也不过就一二百行代码就搞定,更简单点就用自己写的代码生成器,一次性生成所有属性,并不会很麻烦。不过还是有更好(准确使更精简)的解决办法,用一个通用类,十分之一的代码(实际应用中会更少)就可以做到。
Public Class clsCommon Inherits System.Collections.DictionaryBase Public Sub AddField(ByVal FieldName As String, ByVal value As Object) Dictionary.Add(FieldName, value) End Sub Default Public Property Item(ByVal key As String) As Object Get Return Dictionary.Item(key) End Get Set(ByVal value As Object) Dictionary.Item(key) = value End Set End Property End Class |
Public Class clscolCommon Inherits System.Collections.CollectionBase Public Function GenerateAson() As clsCommon End Function Public Sub AddSon(ByVal objSon As clsCommon) End Sub Public Sub Sort() End Sub '默认Item属性以及更多Method从略 End Class |
With xmlGetList(NodeName, strPath) For i As Integer = 0 To .Count - 1 Dim st As Object = objFather.GenerateAson With DirectCast(.Item(i), XmlElement) For Each ch As XmlNode In .ChildNodes St.AddField(ch.Name,ch.InnerText) Next End With objFather.AddSon(st) Next End With |
欢迎访问最专业的网吧论坛,无盘论坛,网吧经营,网咖管理,网吧专业论坛
https://bbs.txwb.com
关注天下网吧微信/下载天下网吧APP/天下网吧小程序,一起来超精彩
|