Is There A Concept Of "Generic Structure" Similar To Generic Collections, Generic Classes
Dec 16, 2009
We have migrated our Vb6 application to VB.NET using a third party tool. Now we are in a process of Refactoring and introducing object oriented concepts in the application.
In VB6, we were using structures in many places. As a part of introducing object oriented programming,
1. is it a good idea of changing all Structures to Classes? or Is there a concept of "Generic Structure" similar to Generic collections, Generic classes?
2. Can some one guide me any source containing guide lines or best practices for applications that are migrated to VB.NET from VB6 and implementing object oriented programmaing.
View 3 Replies
ADVERTISEMENT
Apr 13, 2012
Consider:
Public MustInherit Class Column
Public ReadOnly Property ReturnSomethingUseful() As Object
Get
'return something useful
[code]....
But this gives the following error:
Public Overrides Function ParseValue(sValue As String) As Boolean'
cannot override 'Public Overridable Function ParseValue(sValue As String) As Object'
because they differ by their return types.
I accept that you can't do this, but I'd like to be able to preserve the semantics of what I'm. trying to do, which is to have an untyped version that deals with Object, but a typed version in derived classes that knows about the specific type T.
View 2 Replies
Aug 14, 2010
I have a Journal that records entries for different types: Journal(Of ParentT)
[Code]....
View 2 Replies
Nov 25, 2011
I am trying to construct a generic interface class with generic functions. My goal was to use this to implement multiple worker classes for database interaction that have the same basic functionality. Each class will deal with different object for example, category, product or supplier but unless the the functions in the interface are generic that this won't work.This is the interface code that I have but I don't know if I have done it correctly. [code]
View 2 Replies
Jun 30, 2011
I am trying to create a list of a generic type in vb.net 2.0 framework.
This is the generic type definition:
Public Class GenericParamMap(Of T)
Public Sub New(ByVal pParamName As String, ByVal pPropValue As T)
mParamName = pParamName
[Code]....
The compiler does not allow a "T" in the method's parameter because it's not defined, but I'm not sure how or where to define it. I thought it was okay to have a generic method definition.
View 2 Replies
Feb 8, 2012
I am trying to write a generic method, to avoid code duplication, which will create or activate a Form as an MDI children, based on its type. But I have to lines in error (see comments).
[Code]...
View 4 Replies
Aug 24, 2009
I have a parent class and many children class, right now it look like this:
Public Class Parent
Public Property ID as String
End Class
[Code].....
What I need is a strongly type list List(Of Child) that Inherits from ListOfParent (I need the FindByID method) but I can't find the right syntax.
View 10 Replies
Aug 18, 2011
There are a lot of different generic collections available, so the wisdom in creating a new one may be questionable right from the start.However, I often find myself wanting the same features from my custom generic lists, but cannot quite find all of those features in an existing object; namely, I would like to have a generic collection which works like a List or Dictionary (much like the System.Collections. ObjectModel. Keyed Collection(Of TKey, TValue)), but also works like a BindingSource does when it is bound to an ADO object (that is, it supports full sorting and filtering as well as currency).A feature I almost never need however, is transactional adds (the BindingSource's ability to 'cancel add-new').Again, with so many existing collections out there, I should take a moment to go over the reasons why none of them quite meet my needs.There is the System. ComponentModel. BindingList(Of T) which would provide some of the functionality of a BindingSource, but has strict requirements about the type {T} implementing IComparable in order to support sorting, and does not provide filtering (it is not an IBindingListView).It also only maintains a base item list by index, so does not provide keyed access.We could use simple databinding with a custom list inheriting from System.Collections. ObjectModel. Keyed Collection(Of TKey, TValue) bound to a BindingSource, but again TValue would have to implement IComparable to support sorting and we would still not have filter support.So to get all the features I was after, I decided that the best thing would be to create a new generic collection object which implemented IList, IDictionary, IBindingList, and IBindingListView (along with a few others) and would be capable of serving as a simple list, or as a binding source while providing full sorting and filtering over any newable object type.
To that end, I've created the KeyedObjectModel which contains the KeyedBindingList(Of TKey, T) generic collection/binding source. This collection can be used as a typical list, or as a binding source (you do not need an additional BindingSource component between the collection and UI controls, although you could certainly have one).Various constructors are provided in order to initialize an instance of the collection as either an enhanced list-dictionary, or as a complete BindingSource.Any object that has a public constructor which takes no arguments can be used at type {T}, providing that the object has a property of type {TKey} which will contain unique values for each entity in a given collection.If the object implements System.ComponentModel.NotifyPropertyChanged then the collection will also bubble up property changes on the current item to the collection's CurrentItemChanged event.An implementation of IComparable on type {T} is irrelevant because sorting and filtering are performed on the property values of {T} based on the type of the specified property.The current design of KeyedBindingList(Of TKey, T) is in an 'alpha' stage.The class is mostly complete from a feature implementation standpoint, however, the code has not yet been optimized and the base collections of values, keys, and view are being maintianed in generic lists of their own, rather than raw arrays.However, even without performance tuning, the collection appears to be performing quite well, up to a few thousand entries, given the amount of flexibility and funcitonality it provides.At this stage, I would really love to get some peers to try using the compiled DLL and beat up the collection a bit.Once the code has been proven and optimized, I will publish it as an example.It is a fairly complex class though (currently made up of eleven or so partial classes) so I don't really want to post the code until it has been optimized. [code]
View 4 Replies
Nov 29, 2010
Is there an exhaustive list of all of the "base" (not used in an object-oriented sense but more in a common sense) generic types in the 4.0 .NET Framework? I have found this list that I often send newer/mid-level devs to so they can understand how non-generic types map to generic types, but this is by no means exhaustive. I'm looking for something that also includes things such as KeyValuePair<>, Tuple<>, and other basic generics that may not be very-well known. Interfaces such as IObservable<> would be nice but not necessarily required.
View 6 Replies
Jun 19, 2012
If i have an object that implements an interface (and don't know the exact object) i can call a sub (DoSomething) by going:
vb
Dim iObj = trycast(something, iInterface)
if iObj isnot nothing then
iObj.DoSomething()
end if
How can I do this for a Generic? such as...
vb
Public Class TestClass(of T)
Public sub DoSomething()
....
end class
View 2 Replies
Oct 29, 2009
I've hit a problem with the way I am using generics and I suspect that my design isn't quite right. I have a base class
AbstractBaseClass
inherited by
InheritingOneClass
[code]....
I have a generic list IList(of T as AbstractBaseClass) which I am populating with instances of the various inheriting classes. Now I can cycle through the list BUT depending on which subtype the item is, I want to pass the item to various functions (or instantiate various classes) which access properties/methods of the inheriting Class. I don't really want to have to use a Select Case and list all the potential types of the Inheriting classes. Is there a mechanism I can put in place to automate this?
View 13 Replies
Mar 25, 2011
I am new to VB.NET, just landed a job fresh out of school (well still in school), but I am having trouble with VB...alot of it is getting used to the IDE itsself (we use VB 2010).t does alot of the work for you which is cool but I am having some trouble understanding some concepts.Here are my questions: How to call classes named an initialized on a DSS skeleton to a new page. And the functionalities of building a collection. (also the differences of a generic
View 5 Replies
Jan 27, 2010
imagine i want to add an extension method to System.Collections.Generic.List(Of T)
let's say i want to give it .GetUBound which returns Count-1
View 7 Replies
Jan 3, 2012
given the following class structures:[code]I add the following property to MyList, trying to answer questions like "find out the number of elements with specified type, say Derived1, inside MyList?"[code]
View 1 Replies
Feb 2, 2012
I have a lists of different custom classes and each must be sorted severals times before the algorithm is complete. For each sort I wrote a comparer. Sofar so good. Everything works. But: By now I have abou a dozen different comparers in more than one class and it is still getting more. I wonder if there is a way to limit the number by writing a new general function that can be used to sort all lists without the need for a specific comparer.Below is what I've got so far. But it does not work.
"System.Collections.Generic.List(Of ClassA)" can not be converted into "System.Collections.Generic.List(Of Object)."
[code].....
View 2 Replies
May 20, 2011
If i wish to put items into a System.Collections.Generic.Dictionary, I can either Add or set the Item.I know if you do Add it helps you check if the key already exists and if not it throws an exception.Now I'm curious, so if I'm adding a ton of items, should I prefer setting Item instead of Add since Add does unnecessary checks that may actually slow things down?
View 3 Replies
Sep 21, 2011
I'm having a problem with this code in the highlighted line(*); getting the error in the heading.
Dim htmlarraylist As New List(Of iTextSharp.text.IElement)
htmlarraylist = *HTMLWorker.ParseToList(New StreamReader(tempFile), New StyleSheet())*
[Code].....
View 2 Replies
Jun 10, 2012
I am trying to pass a System.Collections.Generic.List to another class. The collection is created in class2 and then passed into class1
[code]...
However I get a 'Null Reference Exception error' when I run the program. It seems f_str in the line 'For Each s As String In f_str' is null.
View 3 Replies
Sep 21, 2011
I am planning to use a List in my application but when I was searching for System.Collections.Generic, it only has System.Collections. I tried to look it up in the "add reference" and its not there.
View 2 Replies
Feb 15, 2009
how to find a value in the System.Collections.Generic.List.I have:
Private ids As New List(Of Byte())
ids.add(New Byte(){&HA8,&H0F})
ids.add(New Byte(){&HFF,&H03})
ids.add(New Byte(){&H10,&H00})
I would like to find for example: &H10,&H00 in that list and if there isn't the stuff I wan't to find then how do I know that?
View 3 Replies
Sep 14, 2011
I'm wondering if it's possible in VB.NET to make similar properties call one generic one?A sentence doesn't explain it well so here's a code example.I have a bit field defined like this:
<Flags()> _
Enum E_Operation As Integer
Upload = 1
[code]....
View 1 Replies
Apr 10, 2012
I need to be able to tell if a property is of type List(of T)but am currently unable to. if i do
TypeOf (UpdateTo.GetType.GetProperty(node.Name)) Is System.Collections.Generic.List(Of Object)
I get the following error
TypeOf (UpdateTo.GetType.GetProperty(node.Name)) Is
System.Collections.Generic.List(Of Object) Expression of type
'System.Reflection.PropertyInfo' can never be of type[code]......
View 1 Replies
Mar 12, 2009
I want to write a generic file saving routine where the routine is passed data in the form of a collection and it sets a containsStructure flag. I wanted to be able to save the data from the collection, but if it is a collection of structures I want to be able to extract the data from the structure to write to the file.
The only trouble is, that I cannot do something like:
For Each s As dataStructure In data
Next
Since the compiler complains that dataStructure is not defined. Is there a way to code around this?
View 3 Replies
May 20, 2011
in what situation will an item in System.Collections.Generic.List not be removed successfully?url...The way they phrase it makes me think that it is possible that a Remove operation on an item found in the List(Of T) could actually fail.
View 4 Replies
Oct 7, 2010
I have been using a pretty slick generic invoke method for UI updating from background threads. I forget where I copied it from (converted it to VB.NET from C#), but here it is: Public Sub InvokeControl(Of T As Control)(ByVal Control As t, ByVal Action As Action(Of t))
[Code]....
View 1 Replies
Feb 5, 2011
[code]...
What's really the point in using the former?It's hard to use linq if I used the former. I have to convert that to an array first which is difficult because there is no (asarray) function.I think I would change all of my code that's using System.
Collections.Specialized.StringCollection to System.Collections.Generic.List(Of String)
View 2 Replies
Mar 20, 2009
I need another (dozen) pair of eyes on this. The following code:
Interface iRuleEntity
Function GetRuleViolations() As List(Of RuleViolation)
End Interface
Partial Public Class Feedback
[code]....
is giving me this error:'Feedback' must implement 'Function GetRuleViolations() As System.Collections.Generic.List(Of RuleViolation)' for interface 'iRuleEntity'.
View 2 Replies
Jul 28, 2010
This is the code I'm trying to develop:
Public Structure Statistic(Of t)
Dim maxStat As t
Dim curStat As t
[Code].....
View 2 Replies
Mar 21, 2012
I have a generic function in VB.Net. I also have two classes called A and B. Is it possible to allow the generic constraints on my function to allow the Type to be either class A or B? Class A and B do not share any base classes except for object.
View 1 Replies
Apr 1, 2009
I am attempting to create a generic function that the students in my introductory VB .NET course can use to search a single dimension array of a structure.[code]...
My question is: Is there a way to reference the individual structure fields in the array from inside the function? I was trying to make it generic so that the student could simply pass their array into the function - their structure may be named differently than mine and the field names may be different.
I suspect there are other ways to deal with this situation, but I was trying to keep it to just a simple single-dimension array of a structure. I don't think it is possible to do what I want, but I wondered what others thought.
View 5 Replies