Overload Operator In Generic Class With Generic Interface Of Super Class And Inherit Class?
Jan 21, 2010I can do this without problem.
Class A
End Class
Class B : Inherit A
End Class
Dim Obj1 As A = New B
I can do this without problem.
Class A
End Class
Class B : Inherit A
End Class
Dim Obj1 As A = New B
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 RepliesI have the following sample code in a VB.NET console application. It compiles and works, but feels like a hack. Is there a way to define EmptyChild so that it inherits from Intermediate(Of T As Class) without using the dummy EmptyClass?
Module Module1
Sub Main()
Dim Child1 = New RealChild()[code].....
The other way to do this would be to move the generic code out of the Base class and then create 2 Intermediate classes like this [code]...
Then RealChild would inherit from the generic Intermediate and EmptyChild would inherit from the non-generic Intermediate. My problem with that solution is that the Base class is in a separate assembly and I need to keep the code that handles the generic type in that assembly. And there is functionality in the Intermediate class that does not belong in the assembly with the Base class.
I want to define a generic interface which will be implemented by an abstract Generic Class. Basically this generic class is a collection class of any class. Interfaces are in a separate project saved as FileReconciliation. Here are the interface definitions
Interfaces
Imports System.Collections
Public Interface ICollectionCommon(Of T As Class)
Inherits IEnumerable
Function Exists(ByVal oKey As Object) As Boolean
[Code] .....
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.
class inherit from another class and implement an interface?
View 4 RepliesI am working on a general helper class to sort ListView SubItems. I wrote a base class that has much of the code I need. It includes a MustOverride for the Compare method so that the various inherited classes can implment their own comparisons based upon their type. For the value types, I end up with very similar code such as the following, where x and y are ListViewItems: Public Overloads Overrides Function Compare(ByVal x As Object, ByVal y As Object, ByVal sortColumnIndex As Integer, ByVal sortOrder As System.Windows.Forms.SortOrder) As Integer [code]
View 3 RepliesI have a Journal that records entries for different types: Journal(Of ParentT)
[Code]....
This is another one of my "I think it's not possible but I need confirmation" questions.I have a base class for a bunch of child classes. Right now, this base class has a few common properties the children use, like Name. The base is an abstract class (MustInherit)Technically, this means that everytime a child class is instantiated, it lugs around, in memory, its own copy of Name. The thing is, Name is going to be a fixed value for all instances of a given child. I.e., Child1.Name will return "child_object1", and Child2.Name will return "child_object2".
View 1 RepliesI need to have a dynamic URL preferably from a Test Classformatting this design pattern to handle dynamic links from tests. instead of a constant HomePageURL.
Namespace TestDesign
Public Class HomePage
Inherits IE
[code].....
How can I recognize (.NET 2) a generic class?
Class A(Of T)
End Class
' not work '
If TypeOf myObject Is A Then
I created two classes. One class is StudentClass and the other is HomeroomClass. The HomeroomClass contains a readonly property as a generic list of the StudentClass. [code]...
View 6 RepliesI am really trying to follow the DRY principle. I have a sub that looks like this?
Private Sub DoSupplyModel
OutputLine("ITEM SUMMARIES")
Dim ItemSumms As New SupplyModel.ItemSummaries(_currentSupplyModel, _excelRows)
ItemSumms.FillRows()
[Code]...
Here are essential excerpts for the code creating the class and the page using it:
Imports System.Collections.ObjectModel
Public Class Test (Of T as xyz)
Inherits Collection (Of T)
[code].....
i've got a Class like this public Class Cart(Of Item) Public Sub New(ByVal a As Integer, ByVal ParamArray items As Item())but i do not see how to create an instance of it: Dim block_names As New Cart(Of String, 5I)i get something like "type expected" o.O
View 2 RepliesWe are developing an application for our shop floor. This program will be tracking material through the shop and we need to capture any errors the program generates, but we don't need to stop the program for all errors. I have some code to do a screen capture and put it in a database with exception.tostring data for debugging.
What we would like to do, is create an exception from the base class, but provide additional properties to allow us to set a severity and a user friendly error message. I would like to encapsulate this in a class that we would call in the catch of a try/catch, set the properties on the class, have the class record the data to the database, then raise the exception to the main program to display only the user friendly message and severity. The main program would then determine the severity and based on the severity stop the program or just display a discreet msg and continue to process.
Does anyone have an example of a custom exception class derived from exception that does something similar, or if I heading in the wrong direction, does anyone have a better solution?
I'm having trouble with the definition of an inherited generic class. I have two base classes that are defined like this:[code]
View 2 Replieshow Inheriting List(of T) should work.It seems like what I have below should work but at runtime I get the error:[code..]
If I want to cast a List(of x) to the class xlist, how should I do that?[code...]
ok this is the thing I have right now which is working quite well beside its a bit slow:
Public Function GetList() As List(Of SalesOrder)
Try
Dim list As New List(Of SalesOrder)
Dim ds As DataSet
ds = cls.GetSalesOrderList 'CLS is the data access class
[Code]...
I am trying to create a class implementing the generic IComparer of my own class "Stellungen" (which translates to positions, like on a chess or checkers board).
This is what I got:
Private Class comparer(Of Stellung)
Implements System.Collections.Generic.IComparer(Of Stellung)
Public Function Compare(x As Stellung, y As Stellung) As Integer Implements System.Collections.Generic.IComparer(Of Stellung).Compare
End Function
End Class
Problem is: inside the function I have no access to any fields of my class. If I start off with x. Intellisense will only give me .Equals, .GetHashCode - the methods you get on a type but not on an instance. Visual Studio 10 also highlights this, in the definition of the function the bits "x as Stellung" and "y as Stellung" are written in light blue, meaning it is a type and not an actual object. How do I access the things I want to compare inside my class?
I am creating a generic class that is Implementing IList(Of T) which requires that I implement the GetEnumorator of both IEnumerable(Of T) and IEnumerable. When looking at the members of IList(Of T) I see only one GetEnumorator function, yet it implements IEnumerable(Of T) and IEnumerable. How can I use one function to implement both interfaces when the function definitions only vary by return type?
View 8 RepliesPublic Function GetList() As List(Of SalesOrder)
Try
Dim list As New List(Of SalesOrder)
Dim ds As DataSet
[code]....
Now once I start retrieving more than 10000 records from the table, the loop takes long time to load values into generic class. Is there any way that I can get rid of loop? Can I do something like the following with the generic class?
txtSearch.AutoCompleteCustomSource.AddRange(Array. ConvertAll(Of DataRow, String)(BusinessLogic.ToDataTable.ConvertTo(WorkOr derList).Select(), Function(row As DataRow) row("TradeContactName")))
I am trying to serialize a class that contains a generic list, and I am finding it all works with the exception of the generic list property. That is to say the other properties are serialized fine and no error is produced.
I have in the past serialized an arraylist - but I thought it was possible to do a generic list in the same way.
Am I missing something or is it not possible to serialize/deserialize a generic list - I have read mixed comments on this..
The relevant parts of the class that gets serialized is defined as..
<XmlInclude(GetType(cConfigUser)), _
Serializable(), XmlRoot(ElementName:="Config")> _
Public Class cConfig
[Code].....
I have created a Interface and a couple classes that implement this Interface. I am in the process of developing a Shared Class that utilizes the functions that each of the individual classes have, due to the interface implementation.What i need to know is how do i develop this Shared Class so that way each of the methods within it are restricted to a single data type. This single data type needs to be restricted to any class that has implemented the Interface.
Some examples:
Public Interface IVector(Of T)
Sub Add(ByVal v2 as T)
[code]....
As you can see it would allow me to develop one form, since i have standardized the required Subs/Functions for any class the implements the IVector interface. As i am still in developement, i was wondering if my current understanding of the method generics is correct in its current form or what i would have to do to make the Generic Shared Class work in the fashion that i am looking for in the example implementation.
I have a routine that accepts a List of Objects, a property name and a value to search for and simply returns whether or not it found it.The code I have hangs up at the For loop in the findit routine.[code]
View 4 Repliesi've got a generic class for xml serialization and deserialization.
Public Class clsXMLHandler(Of T)
Public Sub serializeFromObject(ByVal filePath As String, ByVal [object] As T)
Dim creater As New FileStream(filePath, FileMode.Create)
Dim xml As New XmlSerializer([object].GetType)
xml.Serialize(creater, [object])
[Code]...
I'm a newbie to VB, and I am having difficulty understanding what the following (legacy code) class declaration actually means:
Public MustInherit Class ModelBase(Of T As {ModelBase(Of T, TIdType), New}, TIdType)
There is also a related ModelBaseCollection:
Public MustInherit Class ModelBaseCollection(Of TCollection As {ModelBaseCollection(Of TCollection, TModel, TIdType), New}, TModel As {ModelBase(Of TModel, TIdType), New}, TIdType)
Inherits Collection(Of TModel)
I have difficulty understanding the need for the ModelBaseCollection class as the ModelBase class is a generic type.
I have a bunch of classes that all contain a Shared ReadOnly Dictionary. If I want to access that Dictionary when the class is a generic type (such as when I have a wrapper function that takes T as an interface that all of these classes implement), what's the way to do it?
I want to do something like GetType(T).GetMember("Dict"), but that will return a MemberInfo type, and that cannot be cast to a Dictionary of my defined type(s). For calling functions this way, one can use a delegate + CreateDelegate + GetMethod. But there doesn't seem to be an equivalent Create*for GetMember stuff. Or am I missing something?
If I plug the GetMember call into the immediate window, and then use a subscript as if it is an array, then the debug output says I am getting a Dictionary back. But if I use that same approach in the actual function that I am trying to write, then I get an error about System.Reflection.MemberInfo cannot be converted to Dictionary(X, Y)
Suppose I want to write a generic function that will return the fully qualified name of the data type. In other words, how would you implement the following: Public Shared Function Foo(Of T)() As String ' Return the fully qualified name of T End Function
View 1 RepliesI have been writing same code for insert, update, delete with LINQ over and over again. I want to have some sort of generic function for Insert, Update, Delete operation. I read a post here like the following :
public static void Insert<T>(T entity) where T : class
{
using (OrcasDB database = new OrcasDB())
[code].....