Make Base Interface For Generic Classes?
May 25, 2010
I'm trying to create a base interface for a class of mine that uses generics. However, I cannot figure out how to declare a property of the interface when its type won't be defined until the class is initialized.
To clarify, consider List(of T), which according to msdn, implements IList (among other things). Note that IList is not the same as its generic counterpart IList(Of T). So that mean any List(of T) can be converted to IList, which simply returns an object for its items. That's what I want to do with MyClass(of T), be able to cast it as IMyClass regardless of what T is.
But when I try such as:
Interface IMyClass
Prop A as Object
Class MyClass(of T) Implements IMyClass
Prop A as T Implements IMyClass.A
I get a signature error for the last line, even though object is broader than T. What am I doing wrong, or how exactly did Microsoft manage to make List(of T) implement IList?
View 9 Replies
ADVERTISEMENT
Oct 22, 2010
I have written multiple programs in the past that deal with cad data. Points, lines, arcs, etc. For each program I ended up creating slightly different versions of some really base classes like a class that defines a point:
<Serializable()> Public Class Point
Public x As Double = 0
Public y As Double = 0
Public z As Double = 0
End Class
My question is how would I use that class in such a way that it could be in a namespace and imported into any future project that I write?
View 2 Replies
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
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
Jul 10, 2009
I m trying to raise Click event of Textbox explictly but I m getting "Derived classes cannot raise base classes" error.[code]....
View 1 Replies
Sep 6, 2010
I can quickly knock together soem code to xlate base 10 to/from bae 13, but I just wondered if something very easy already exists in VB.NET (or even somethign generic, with base N, but right now I am only looking at base 13)
View 1 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
May 19, 2009
i have a base class which declares the event StatusTextChanged. My child class, of course cannot directly raise this event.
[Code]...
View 5 Replies
Oct 20, 2010
I have classes setup similar to this:
<DataContract()> _
Public MustInherit Class SystemTaskProcessBase
Public MustOverride ReadOnly Property Name() As String
Public MustOverride ReadOnly Property Description() As String
Public MustOverride Property Result() As SystemTaskResult
[Code]...
I need to use these classes on the client system, but also need to be able to create these "tasks" through a management interface. Each class (Task) that inherits the base, could have its own properties that are unique to each class, but at the same time, share the same common base class properties. For example, the above shows a reboot task and a delete file task, the delete file task needs to know which file to delete, so has a property for that. But the reboot task does not need this property. So when the management application is creating these tasks, it shouldn't provide a text box for the file property for the reboot task. There may be more tasks created at a later date with completely different properties.
How would I go about providing the WinForms management application a way to enumerate each class into a ListView for example, and allowing the user to create these tasks and filling in the dynamic properties that each class would have? Desired functionality would be to create a task form that creates dynamic controls available for the properties as needed, depending on the public properties in each class, but at the same time have the base class properties available as well.
View 1 Replies
Sep 25, 2011
I have a webservice that is wrapped up by a data access object and is accessed by many different UI controls.
The proxy objects look something like this:
Public Class WebProxyObject1
' Common properties, there are about 10 of these
Public Name As String
[Code]....
View 1 Replies
Jun 26, 2010
I am a VB6 programmer learning VB.Net and am having trouble with the following concept.
[Code]...
View 4 Replies
Mar 17, 2010
I have a website (coded in vb.net) with an "admin" section (the admin section being a folder in the actual site)... So in every page of the site I'm using my own custom class as the page base (which has been set in the web.config file) but I want to inherit from different class for the files in the "admin" folder... Is there any way to inherit different classes for pages in different folders using the web.config or some other equally as global method? (meaning some other way than inheriting on a per page basis.)
View 1 Replies
Jan 30, 2009
i've finally got round to learning about classes and inheritance, but i'm not sure how to proceed. i have a base class Employee, which is inherited by 2 derived classes. how do i use the same Employee class in both derived classes? obviously if i write a sub new for both of them + declare a new Employee class, they won't be using the same class. heres my Employee class:
[Code]....
View 7 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
Jan 21, 2010
I can do this without problem.
Class A
End Class
Class B : Inherit A
End Class
Dim Obj1 As A = New B
View 4 Replies
Aug 2, 2010
I need to create a generic for all the classes having common data.I am having a Test.xsd dataset.In that dataset I am having 3 Table Adapter.
pgaddressTableAdapter1
pgaddressTableAdapter2
pgaddressTableAdapter3
Code is here. You can see all these classes having same methods. I want to create a generic class for these class.
[Code]...
View 2 Replies
Aug 15, 2006
If I have a generic.list(of ClassA), is there a simple way to create a deep copy of this list that will not affect the original copy? It seems to work if I have a generic list of Structures, but for some reason the copy constructor for lists of classes only copies pointers to the elements (or maybe a pointer to the whole list?). I would move to structures if it were not for the fact that I can't find a way to edit the members in the structs in the list. eg:list(0).a = 5 'Does not workIs there some way to get around this without declaring an instance of that structure, like this:dim str as StructA = list(0)str.a = 5I'd
View 2 Replies
Aug 8, 2011
Background:I have a base class and several inherited derived classes. The derived classes don't always need to have the same properties. If any properties are shared among the derived classes, those properties would live at the base class level ('Contents', for example).Similarly, GoodDocument below has 'GoodThings' but would not want/need to have 'BadThings'.I want to treat instances of both 'GoodDocument' and 'BadDocument' as type 'Document'
public mustinherit class Document
public property Contents as string
public sub new()...
[code]....
View 3 Replies
Jan 27, 2010
I have an interface that i have declared some of the basic internal functions, subs, properties, etc. This interface is then implemented into 3 pre-defined classes. These classes are end-use classes so they dont get derived or inherited elsewhere. I am trying to create a generic shared class that can operate on each of these 3 predefined classes and potentially more as long as they implement the interface.
[Code]...
View 10 Replies
May 11, 2012
I'm struggling here.. I know I can disable the warning manually. However I'm not sure if this would be the right way to go about this.
Here's my interface..vbnet Public Interface IPopulatingClassBase Property Identity() As Int64 ReadOnly Property Dirty() As Boolean Sub Populate_Class(ByVal RecordID As Int64) Sub Save_Class() Sub Reset_Class()End Interface
[Code]...
PS In my example think of it as classes that populate with data from a database. The parent class would be an organization, and the derived class a location. Both populate and have similar functionality. The only difference is locations are an entity of an organization(the data record for a location constraints it to an organization) upon loading location data I also populate the organization class. This is a real example of what my project does.. so having said I just want to know how I can get around this warning, and if not would it have any consequences if I left it as-is.
View 6 Replies
Nov 29, 2011
In our current project I am using a generic interface iService which is inherited by all other service interfaces. For instance IService is inherited by ILogService.
The ILogService interface is then implemented by LogService as below:
Public Interface IService(Of T)
Sub Save(ByVal T As IEntity)
Sub Remove(ByVal T As IEntity)
[Code]....
How can I update the method signature so T is displayed as Log?
View 2 Replies
Mar 25, 2012
I have a class which has a variety of details, as follows:
Vehicle Name
Vehicle Address
VEHICLE Percentage: 10
I need to somehow use an Interface for another version, SpecialVehicle.
Special Vehicle has a different Percentage, for example 15.
How can I integrate that in an interface? I just don't understand them?
View 1 Replies
Sep 10, 2009
I downloaded a .net component that I would like to make consumable by COM clients. This component allows one to create a DXF file (Cad drawing). The problem is that the component is composed of quite a few class files, some inherit another. All the examples I found only show one file no namespaces etc. [Code]
View 1 Replies
Apr 22, 2010
I think my problem is easy to solve. I developed an interface called "Animal". My programmers created classes for "Dog", "Cat", and "Horse" Later I want to let the user create an animal in a Windows form. How can I get my annimals to appear in the combo for selecting one of them? Each animal has it's own DLL. If tomorrow a new animal is developed, the combo should present the new value.
View 2 Replies
Jun 8, 2009
I have a following code which works fine
MsgBox(AddSomething(Of String)("Hello", "World"))
Public Function AddSomething(Of T)(ByVal FirstValue As T, ByVal SecondValue As T) As String
Return FirstValue.ToString + SecondValue.ToString
[code].....
View 3 Replies
Jan 2, 2011
i've been trying to toy around with generics in vb.net in an example project. At the moment, it looks like this:
I have an interface called IRow (and a class that implements it as a Datarow).
A second interface is ICanGetByRow, which looks like this:
Public Interface ICanGetByRow(Of T)
Function GetByRow(ByVal Row As IRow) As T
End Interface
The function simply takes an IRow and converts it to T. Thats easy enough. Now, for easier access, i want to implement a function in the IRow interface which takes the row and converts it into said ICanGetByRow.
My interface was enhanced by the following function
Function GetObj(Of T As ICanGetByRow(Of T))() As T
You can probably see the problem. If i implemented it like this:
Public Function GetObj(Of T As ICanGetByRow(Of T))() As T Implements IRow.GetObj
Dim foo As New T
foo.GetByRow(Me)
Return foo
End Function
i wouldn't be allowed to construct a new T, and when i tried to make it work by telling the generic function that my interface has a constructor, he wouldn't let me invoke GetByRow anymore.
Public Function GetObj(Of T As New, ICanGetByRow)() As T Implements IRow.GetObj
Dim foo As New T
foo.GetByRow(Me)
Return foo
End Function
how to tell a generic function that it will get a ICanGetByRow(of T) which has a constructor
View 1 Replies
Jul 19, 2010
i may be misunderstanding this but on MSDN i believe it says that it is good practice to implement the Dispose destructor in every class you write. should i (do you) really implement the IDisposable interface with every class i write? also, is the proper syntax for implementing an interface to put the "Implements" keyword on the line after the "class" declaration? i put it on the same line as "class" and I got an error.when coding the method implemented by the interface, is it mandatory to follow this syntax, as an example: Public Sub Dispose() Implements System. IDisposable. Dispose.
View 3 Replies
Nov 17, 2009
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] .....
View 3 Replies
Nov 30, 2010
How do I limit an Interface when defining it? What is the correct technical term for what I am describing?For example, I want MyInterface to only be implemented for objects that implement IList(Of T) and ICollection(Of T).
View 5 Replies