Create A Generic Shared Class That Can Operate On Predefined Classes

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


ADVERTISEMENT

Shared Class With Generic Methods?

Jan 28, 2010

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.

View 6 Replies

.net - Fetch A Shared Member From A Class When It Is A Generic Type?

Nov 4, 2011

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)

View 2 Replies

Create A Generic For All The Classes Having Common Data?

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

Overload Operator In Generic Class With Generic Interface Of Super Class And Inherit Class?

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

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

Create A "shared" Variable That Is Shared With All Instances Of A Class?

Jan 14, 2011

I seem to be drawing a blank. I'd like to create a "shared" variable that is shared with all instances of a class but not classes that inherit from it. For example.Class A: Shared list As New List(Of String): list.Add("A")

Class B Inherits A: list.Add("B")Class C Inherits B: list.Add("C")The end result I'd like is that any instance of A has just A in the list. Any instance of B has A and B in the list. Any instance of C has A, B, and C in the list. I can accomplish it by creating Instance variables, but I have to construct the list for each instance of a class. I'd like to construct it once for a specific point in the Hierarchy and then share it accross other instances of that class.

View 12 Replies

Use Derived Class Shared Variables In Shared Methods Of Base Class?

Jun 4, 2010

I am trying to add shared members in derived classes and use that values in base classes...

I have base

class DBLayer
public shared function GetDetail(byval UIN as integer)
dim StrSql = string.format("select * from {0} where uin = {1}", tablename, uin)
end function
end class

[Code]..

currently there is error using the tablename variable of derived class in base class but i want to use it i dun know other techniques if other solutions are better then u can post it or u can say how can i make it work? confused...

View 2 Replies

C# - Create A Generic Method In A Class?

Apr 28, 2010

I 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]...

View 4 Replies

Create A Private Shared Object In Each Class And Lock On That Instead?

Jul 13, 2009

I have created a synchronized queue and am using SyncLock on the SyncRoot property of that queue when I invoke the Enqueue/Dequeue methods. The methods are invoked from instances of standard producer/consumer classes.Is that a proper use of the SyncRoot property?

Would it be better practice to create a private shared object in each class and lock on that instead?

View 1 Replies

Create Multiple Classes Of Different Names That Use That Class?

Mar 6, 2009

Okay, say I have a class named "ChannelList", and it raises an event named "FoundChannel"

But what I'M wanting to do is create multiple classes of different names that use that class, but I want to have all of the "FoundChannel" events be handled under one single sub routine?

View 15 Replies

Create A Class To Deal With Records From The Classes Table?

Dec 5, 2010

Create a class to deal with records from the Classes table, much like the Student class we created in Lecture #17 handles Students records. The name of the class should be Ualb_Class (note we cannot use Class, as it is a reserved word in VBA). All of the fields should have corresponding properties. There are few considerations:

The class (course) code, department code, and course number are set at Initialize, so there is only a Get property method for those

The property for Meeting Day only accepts one of the values defined in the table. You can decide whether to accept an integer value or a string value of the days represented.

You are also to code the Initialize method, much like we coded the Initialize method for the Student class in Lecture #17. In the Initialize method, you will use the InputBox function to obtain the department code and course number. use a different InputBox for each value, so you don't have to mess with separating the single text value returned from that function. The Course Code will be obtained by using a function that has already been created, called GetNewCourseID. It has no parameters.

TABLE: Classes
Field Name
Data type

[Code]....

View 2 Replies

Inheritance (Private Overrides Function) - Create A Class And All Other Classes Inherit From It And Modify It A Bit

Oct 15, 2011

I am cleaning up some code and I have multiple classes that are 99% exactly the same. So my understanding is that my options are...

1. Create a class and all other classes inherit from it and modify it a bit

2. Create an abstract class and all classes inherit from it and modify a bit ** I took this route

3. Create an interface and all classes Implement that interface.

Here is my 'original' class below (the one that all of them look 99% identical). This class is used in an arraylist so I have a listing of all my images from a folder I have searched.

[Code]...

View 10 Replies

.net - Can A Generic Version Of A Derived Class Override A Base Method Using The Generic Type

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

.net - Determining A Generic Type At Runtime In Non-Generic Class

Aug 14, 2010

I have a Journal that records entries for different types: Journal(Of ParentT)

[Code]....

View 2 Replies

Construct A Generic Interface Class With Generic Functions

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

VS 2010 Structure Classes So That The User Interfaces Though A Single Class While The Supporting Classes Are Hidden From Their View?

Jun 13, 2012

How can I structure my classes so that the user interfaces though a single class while the supporting classes are hidden from their view? I think its best understood in an example:

Public Class MyInterface
Public Economic as EconomicClass
Public Sub New()
MyBase.New()

[code].....

So you might ask why am I even separating them? It's strictly for others who will be working with this interface. I need to funnel them though a logical structure:

interface.Economic.MyMethod
interface.Currency.MyMethod
etc

This way everything is already handled for them in the background and they only need to run the method they need. I don't know if I can have it both ways in VB.NET.

View 23 Replies

Make A Shared Function Generic?

Feb 16, 2011

I can create classes that use generics, however I was wondering if it is possible to apply this to a shared method rather than rely on the caller casting to the correct type.This is the method:

Public Shared Function DeserializeObject(ByVal serializedXml As String, ByVal givenType As System.Type) As Object
Dim serializer As New XmlSerializer(givenType)
Return serializer.Deserialize(New IO.StringReader(serializedXml))
End Function

I'm pretty sure this can't be done, but thought I'd check (if so Extra points will be awarded if someone can technically explain why the compiler can't do this)..

View 3 Replies

Create A File And Fill It Until A Predefined Size Value?

Jun 5, 2011

There is some way to open a file and fill it with randon information until it reach a determined value?

View 19 Replies

Asp.net - How Are Classes Shared Between Projects In The Same Solution

Jan 29, 2011

Currently, I have a solution that contains two projects (ASP.net websites, FWIW). If I create a class in Project1, how do I expose it to Project2? Is it automatically available to Project2 because they are in the same solution? Or do I need to do something special to make the connection?

View 5 Replies

Shared (Static) Classes With Events In C#

Mar 27, 2010

[code]Now how do i do this in c#. I know there is not handles clause in c# so i need some function that is called and assign the event handlers there. However since its a shared class there is no constructor i must put it somewhere outside of a function.

View 2 Replies

Shared Events In Child Classes

Jul 7, 2011

I have a program with a base class and classes that inherit the base. A Windows Form will call a function of each child class which raises an event from the base class. The function call to the first child class works fine: the event is raised for the first child class.

[Code]...

View 7 Replies

.net - Generic Classes (T) - Specifying From A Range Of Type?

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

Generic Constraints That Allow Type To Be 2 Different Classes?

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

.net - Access Shared Members In Partial Classes

Feb 16, 2011

I'm writing a WCF-Service and I split up my service class to multiple partial class files, so every ServiceContract-Implementation gets its own file. I have one file however that should contain e.g. members that are used by every partial class file such as a logger. The service is hosted with IIS 7 if this matters in any way.

[Code]....

The code compiles fine, but at runtime I get an BC30451: The name m_Log is not declared Error (Don't know the exact words for it. I get a german message ;) ). I don't think it has something to do with the type of m_Log or a depending assembly because I get the same error if i try this with a String. What am I doing wrong? How can I make this work? Edit: I was trying the same thing in a simple console application without any problems. :(

View 1 Replies

Asp.net - How To Get Classes To Expose The Same Shared/Static Method

Mar 4, 2010

I have a base class with several derived classes. I want all of my derived classes to have the same Public Shared (static) method with their own implementation. How do I do this? Is it even possible?

View 3 Replies

C# - ASP.NET's App_Code Folder And Shared/Static Classes?

May 15, 2011

If I have a 'Shared' object defined in the App_Code folder; is that object shared amongst all users/visitors of my website? Or is it shared on a per-user basis?I don't know if that makes sense or not; but I've got a puzzle/solver I'd written earlier that I'm trying to incorporate into a simple ASP.Net site. It's probably poorly written, but I'd used a Shared boolean to determine if a solution had been found. The code works, now as an ASP.NET site, but if two visitors to my site were both validating their puzzle at the same time, would they both be accessing the same boolean?

View 3 Replies

Extending Classes: Adding Shared Procedures?

Nov 2, 2009

is there anyway we could extend a shared function for a class? example:

<Extension()> Public Shared Function GetName(ByRef e As [Enum], ByVal value As Object) As String
Return [Enum].GetName(e.GetType, value)

[Code].....

however i dun hav a choice as Extension methods can be declared only within modules

View 21 Replies

Use Modules Instead Of Classes With Shared Member Functions?

May 19, 2009

Is it considered an acceptable practice to use Modules instead of Classes with Shared member functions in VB.Net?I tend to avoid Modules, because they feel like left over remains from VB6 and don't really seem to fit in anymore. On the other hand, there doesn't seem to be much difference between using a Module and a Class with only Shared members.

View 4 Replies

Deep Copy Generic List Of Classes

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







Copyrights 2005-15 www.BigResource.com, All rights reserved