English 中文(简体)
将VB6集市改为VB。 净额
原标题:Converting VB6 Collections to VB.Net generics

所有人,

我有一个VB6项目,大约有100个海关收集班,我想改为VB。 净额。 一个典型的例子就是这样。

Class CAccounts
     Private m_Accounts As New Collection

     Public Sub Add(newItem As CAccount)
         m_Accounts.Add newItem, newItem.IdKey
     End Sub
     Public Sub Remove(index As Variant)
         m_Accounts.Remove index
     End Sub
     Public Function Item(index As Variant) As CAccount
         Set Item = Nothing
         On Error Resume Next
         Set Item = m_Accounts.Item(index)
     End Function

     .........

储存的物品

Class CAccount
    Public Id as long
    Public Code as String
    Public Name as string
    Public Sub Init(ByVal Id as Long)
        Me.Id = Id
        Code = ""
        Name = ""
    End Sub
    Public Property Get IdKey() as String
        IdKey = Code
    End Property

    ......

该项目的所有收集课程都采用这一标准方法。 然而,并非实际使用所有收集类别的财产/方法。 大部分收集都用于“每个”休息室。 使用强硬钥匙的关键准入非常常见。 按指数分列的关键接入率远不太常见。

理想的情况是,我要采取标准做法来改变这些阶层。 我并不真的要审查每项收集工作,而是考虑我是否需要清单、理论等。 其中一些藏有10万件物品,有些只藏10件。 然而,另一方面,我不想通过采用一种更为简单的办法来造成业绩问题的结构。

I d appreciate any advice on the best approach. I ve considered the following.

  1. 采用老式收集方法。 因此,改用VB相对比较容易。 但是,我转而转向更现代的结构。

  2. 拥有Caccounts Inherit KeyedCollection(Of String, CAccount)。 幸运的是,收藏品中的大部分课堂都作为课堂的一部分具有关键意义(例如,Caccount)。 页: 1 这似乎行之有效。 然而,相对较少的班级将用数字指数获得col。 因此,如果我只想用强硬的钥匙获得关键准入,这或许是多余的?

  3. 在我不需要数字指数的班级上,有Caccounts Inherit Dictionary(Of String, CAccount)。 我面临的问题是,所有现有的“每个”住所都像“每个账户”一样。 我不想把所有这些发生变成像“每个账户”。 价值”。 尽管我也许可以通过改变违约财产来抓紧?

  4. • 了解我的博爱是我自己收集的Inherit MyCollection(Of String, CAccount)。 这似乎过于艰巨。

我倾向于选择2,使一切都成为关键的孔隙。 然后根据要求作出例外规定(例如非独特钥匙)。 然而,如果关键专业的学习速度要慢得多,那么,我可能将Dictionary作为标准,并公正使用关键专业,而我需要获得数字指数。

所有建议都受到赞赏。

最佳回答
  • Convert all collections to Dictionary(Of String, Whatever) or KeyedCollection, whichever seems more appropriate.
  • See if there are performance problems by running the program.
  • If there are, use a profiler to pinpoint the culprit and change its type to something more appropriate.

但总的来说,我总是建议完全改写,而不是试图将VB6号船运进。 根据我的经验,从我从其他开发商那里听到的情况来看,这总是会耗时较少,至少会耗费时间,用于积极制定守则。 如果你拥有一个密码库永远不会再触动的书面港口,则港口可能更有意义,但我对使用现代藏书并不担心,只是使用相容的类别。

问题回答

You re going to want a KeyedCollection<TKey, TItem> MSDN article here: http://msdn.microsoft.com/en-us/library/ms132438.aspx

Imports System
Imports System.Collections.Generic
Imports System.Collections.ObjectModel

  This class represents a very simple keyed list of OrderItems,
  inheriting most of its behavior from the KeyedCollection and 
  Collection classes. The immediate base class is the constructed
  type KeyedCollection(Of Integer, OrderItem). When you inherit
  from KeyedCollection, the second generic type argument is the 
  type that you want to store in the collection -- in this case
  OrderItem. The first generic argument is the type that you want
  to use as a key. Its values must be calculated from OrderItem; 
  in this case it is the Integer field PartNumber, so SimpleOrder
  inherits KeyedCollection(Of Integer, OrderItem).
 
Public Class SimpleOrder
    Inherits KeyedCollection(Of Integer, OrderItem)

      The parameterless constructor of the base class creates a 
      KeyedCollection with an internal dictionary. For this code 
      example, no other constructors are exposed.
     
    Public Sub New()
        MyBase.New()
    End Sub

      This is the only method that absolutely must be overridden,
      because without it the KeyedCollection cannot extract the
      keys from the items. The input parameter type is the 
      second generic type argument, in this case OrderItem, and 
      the return value type is the first generic type argument,
      in this case Integer.
     
    Protected Overrides Function GetKeyForItem( _
        ByVal item As OrderItem) As Integer

          In this example, the key is the part number.
        Return item.PartNumber   
    End Function

End Class




相关问题
Is Shared ReadOnly lazyloaded?

I was wondering when I write Shared ReadOnly Variable As DataType = New DataType() Or alternatively Shared ReadOnly Variable As New DataType() Is it lazy loaded or as the instance initializes? ...

Entertaining a baby with VB.NET

I would like to write a little application in VB.NET that will detect a baby s cry. How would I get started with such an application?

Choose Enter Rather than Pressing Ok button

I have many fields in the page and the last field is a dropdown with list of values. When I select an item in a dropdown and press Enter, it doesn t do the "Ok". Instead I have to manually click on Ok ...

ALT Key Shortcuts Hidden

I am using VS2008 and creating forms. By default, the underscore of the character in a textbox when using an ampersand is not shown when I run the application. ex. "&Goto Here" is not ...

Set Select command in code

On button Click I want to Set the Select command of a Gridview. I do this and then databind the grid but it doesn t work. What am i doing wrong? protected void bttnView_Click(object sender, ...

Hover tooltip on specific words in rich text box?

I m trying to create something like a tooltip suddenly hoovering over the mouse pointer when specific words in the richt text box is hovered over. How can this be done?

热门标签