VB Allows The Type Parameters To Be Used As The Base Class For The Generic Type?

Mar 30, 2010

1) VB Allows non-type template parameters2) VB supports explicit specialization 3) VB allows the type parameters to be used as the base class for the generic type4) VB allows a generic type parameter itself to to be a generic 5) VB enforces that all codes are valid for all types of parametrs

View 1 Replies


ADVERTISEMENT

.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 - Get A Base Class Method Return Type To Be The Subclass Type?

Nov 23, 2009

I have a copy function that I'd like to override in subclasses to return the type of the subclass. Here are my interfaces:

Public Interface IBase(Of T)
Function Copy() As T
End Interface

[Code]....

View 4 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

Typecasting Generic Parameters - Error Value Of Type 'String' Cannot Be Converted To 'T'

May 23, 2010

Using the following code:

[Code]...

View 6 Replies

Returning A Inherited Class As Base Class Type With Web Services?

Sep 25, 2009

I suspect I am being very silly here but I have the following setup

Class MustInherit myBaseClass
'some stuff
End Class
Class myInheritedClassA

[code]....

Running this results in the following error

Unhandled Exception: System.InvalidOperationException:
There was an error generating the XML document. --->
System.InvalidOperationException:

[code]....

is there any way of 'Widening' the inherited class to the base class so this would work?

EDIT:regarding XmlInclude(typeof inheritedClass), currently this method could potentially return a number of types of inherited class (i.e myInheritedClassA and myInheritedClassB) is it case of simply having to add each of the inheritedTypes in this tag?

View 2 Replies

Where To Find Base Type Of A Class

Jun 9, 2009

One thing that always bugged me, is that I do not see the base type in Visual Studio.I just stumbled on this, because I tried to cast a System. Windows.Forms.MenuItem to a System.Windows.Forms.Control..In eclipse the "intellisense" (or whatever it is called) shows me while exploring the members of a class for each member from which base class it is inherited.In Visual Studio I cannot see the base class, even if I use the Object browser or the help.[code]Is there a way to query the base type tree of a class at Design Time?

View 8 Replies

Inherit From A Generic Class Without Specifying A Type?

Apr 29, 2009

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

View 1 Replies

Recursive Generic Type Class Declaration

Mar 23, 2011

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.

View 1 Replies

VS 2008 Dragdrop - Check If The Present Data Type Inherits From The Base Type

Aug 20, 2009

I have a number of controls (Device1, Device2, etc.) that all inherit from BaseDeviceControl. In the DragEnter event handler I am trying to test for the correct type by using the BaseDevvceControl like this....

[Code]....

View 8 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

Get The Fully Qualified Class Name Of The Type In A Generic Function?

Apr 18, 2011

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 Replies

C# - .NET Generic Class Instance - Passing A Variable Data Type

Jun 2, 2010

I'm tyring to pass a variable data type to a template class. Something like this:

frmExample = New LookupForm(Of Models.MyClass) 'Works fine

Dim SelectedType As Type = InstanceOfMyClass.GetType() 'Works fine
frmExample = New LookupForm(Of SelectedType) 'Ba-bow!
frmExample = New LookupForm(Of InstanceOfMyClass.GetType()) 'Ba-bow!

[Code].....

I'm assuming it's something to do with the template being processed at compile time but even if I'm off the mark there, it wouldn't solve my problem anyway. I can't find any relevant information on using Reflection to instance template classes either.

(How) can I create an instance of a dynamically typed repository at runtime?

View 4 Replies

Warning: Type Library Exporter Encountered A Generic Type Instance In A Signature

May 5, 2009

I'm compiling a VB.Net 2.0 app (created in VS2008) using msbuild, and now I've added a generic return type, it's giving me the following:

Warning: Type library exporter encountered a generic type instance in a signature. Generic code may not be exported to COM.

Having just spent ages removing all of the previous warnings, I don't really want to add a new one. Any idea how to get rid of it (aside from not using generics)?I don't know what details I'd put in the attribute, or what number to put in the project-level ignore list.

View 1 Replies

Unable To Cast Object Of Type .objectquery To Type Generic.list

Sep 12, 2011

I have a question about ASP.Net, visual basic I have 2 LINQ query's, the first one works, the second one doesnt, produces a

"Unable to cast object of type 'System.Data.Objects.ObjectQuery'1[SelmaV2.Products]' to type 'System.Collections.Generic.List'1[System.String]'.

[Code]....

View 1 Replies

Cast Value Type To Nullable Enumeration Type In Generic Object If All Types Are Unknown At Write-time?

Dec 14, 2011

I have a generic Class I'm using to hold information loaded from a database.I have a method which takes a DataRow as an argument, uses the object's known column name and extracts the data from the DataRow, such that:Dim loadData As T = CType(myDataRow("myColumnName"), T))works as my default assignment in most cases.Unfortunately, due to some horrifying design constraints, some of my columns may be null, and may also be taken from enumerations.This means that when <T> is Nullable(Of SomeEnumeration) the above code does not work because I can't cast 0 directly to SomeEnumeration.Zero.Is there some way to check whether <T> is Nullable(Of [Enum])? Or some way to write a method which allows Integers to be cast to Nullable(Of [Enum])?I feel like I'm forgetting something that would allow me to write one of the other of these, but my weak google-fu is turning up nothing.

EDIT: Okay, thanks to dasblinkenlight's answer below, I can detect when this circumstance is occurring, but what I need to do now is to take a type <T> which I know is Nullable(Of SomeClass), get a type reference to SomeClass and then create a new object of type Nullable(Of SomeClass) and assign that to LoadData.My problem was that I had a lot of difficulty in finding any function which would accept baseType as an actual Type.Parse accepted baseType as a parameter, I knew baseType was an [Enum] type because of dasblinkenlight's code, so I was, in this instance, able to code a solution. It's a solution which is very specific to my problem (i.e., T is Nullable(of SomeEnumeration)), but it's a solution nonetheless.

View 2 Replies

Using An Interface Defined In A Generic Type From Within The Defining Type

Feb 14, 2012

In trying to add a bit of usage variety to a generic class I'm working on, I ran into this issue with trying to cast an object into an interface instance where the interface is defined inside the generic class.

[Code]...

View 1 Replies

Sql - Passing Parameters To A Stored Proc Accepting In Parameter Of Type XML Type?

Jun 7, 2011

I have a storedproc accepts parameters in XMLtype as

CREATE OR REPLACE PROCEDURE GetDetails(
p_para IN XMLTYPE,

[code].....

View 1 Replies

Casting From Base Type To Derived Type

Jun 29, 2010

I'm wrestling with this treeview control. I have extended the TreeNode class to attach some extra data to the node. Basically, I added one property:[code]Is there a way to cast from a base type to a derived type?

View 11 Replies

String - 'Public Function' Has No Type Parameters And So Cannot Have Type Arguments

Mar 12, 2012

I am having some issue here, and I am not too sure how to handle it. If you could lead me in the right direction

[Code]....

View 1 Replies

Unable To Cast Object Of Type 'System.Collections.Generic.List`1[System.Int32]' To Type 'crmWebService.ArrayOfInt'?

May 14, 2012

I'm getting an error after sending a list to a web service.This is the code that is calling the web service:

Dim sProgramInterest As New List(Of Integer)
crmService.InsertProspectGetId(sProgramInterest.ToList)
But I'm getting this error.

[code].....

View 3 Replies

Unable To Cast Object Of Type 'ImagesFlag' To Type 'System.Collections.Generic.IEnumerable`1[ImagesFlag]'

Jan 7, 2012

And here is the code that produces the error

CODE:

How can i cast this one?

View 1 Replies

Create A New Class That Inherits From The Base Form Class And Define A New() Method With Parameters?

Oct 1, 2008

I've been creating short test apps repeatedly to try to understand some of the concepts in VB.NET.For the most part it has been illuminating.I read Bucky's .NET knowlegebase tutorial on passing objects as parameters to newly created forms. He shows how to create a new class that inherits from the base form class and define a New() method with parameters Extending the concept I thought about doing the same thing with a form that was created at design-time (In this case Form2).

[Code]...

View 6 Replies

Convert From Base Class To Subclass (BC30311: "Value Of Type '<type1>' Cannot Be Converted To '<type2>'")

Nov 16, 2009

take a look at the following code:

[Code]...

View 2 Replies

Create A Function Which Have Either 1 Parameter With A String As Data Type Or 2 Parameters With Double As Data Type?

Jun 11, 2012

I need to create a function which have either 1 parameter with a string as data type or 2 parameters with double as data type.Something like the substring method.

View 2 Replies

VS 2008 Pointer - Error32'System.Reflection.Pointer' Has No Type Parameters And So Cannot Have Type Arguments

Jul 15, 2010

I have an open source project I converted to vb.net. I solved all the errors, except for one. This is the C# line

[Code]....

View 4 Replies

Get Type Of Derived Generic List Class From List Item Method?

Mar 23, 2011

Public Class notifierMain
Public Class Contacts
Inherits List(Of row)
Public Sub New()

[code]....

When I debug this winforms application I get curType = "notifier.notifierMain+Contacts+row" I want to the Validate function to know it is in MyContacts. How do I do this?

View 3 Replies

Generic Mustinherit Class - Receive: "Type Argument BaseObject Is Declared 'MustInherit' ?

Aug 23, 2011

i have 2 mustinherit classes where one is a generic one:

'Visual Basic 2008 - .net 3.5 - Any CPU
Public MustInherit Class BaseObject

End Class

Public MustInherit Class BaseObjectList(Of T As {New, BaseObject})
Inherits List(Of T)
End Class[code]...........

i receive: "Type argument BaseObject is declared 'MustInherit' and does not satisfy the 'New' constraint for the type parameter"users would never enter data in the wrong form,files they choose to open would always exist and code would never have bugs.

View 1 Replies

Unable To Cast COM Object Of Type 'System.__ComObject' To Class Type?

May 14, 2009

Unable to cast COM object of type 'System.__ComObject' to class type 'rjsDocMan.Folder'.Instances of types that represent COM components cannot be cast to types that do not represent COM components; however they can be cast to interfaces as long as the underlying COM component supports QueryInterface calls for the IID of the interface.The code where it is flagging the error is:

<div style="color: Black; background-color: White;">
treeview += AddChildren(Session("DocMan").RootFolder)
</div>

[code].....

View 4 Replies

Parameters Data Type - Add Parameter With Same Data Type As Column Data Type

Feb 26, 2012

For each column in data table i want to add parameter with same data type as column data type. But looks it's not that simple.


Dim cmd As New SqlCommand
Dim dType As New System.Data.SqlDbType

For Each cl As DataColumn In DataTable1.Columns

[CODE]...

How can I do this?

View 4 Replies







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