.net - Creating A Generic List Of A Generic Type

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


ADVERTISEMENT

Creating A Generic List Of A Specified Type?

May 26, 2010

I want to create a generic list - but I want to specify the type at runtime - is there a way I can do this? using reflection perhaps?Something like this...

Public Shared Sub create(ByVal t As Type)
Dim myList As New Generic.List(Of t)
End Sub

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

Generic Cannot Instantiate Instance Of The Generic Type With New?

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

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

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

Difficulties Sending A Type To A Generic List?

Nov 23, 2011

I'm trying to use a generic list without knowing the type when loading the page. I have a typePropertyCollection which inherits from List(Of PropertyData). The usercontrol that uses this collection doesn't know what type of data is used (which objects). So when the page is loaded, I pass along the type to the usercontrol using a dependencyproperty. This type ends up in this method:

Private Shared Sub OnObjectTypeChanged(ByVal obj As DependencyObject, ByVal args As DependencyPropertyChangedEventArgs)
Dim objectType As Type = TryCast(args.NewValue, Type)

[code].....

View 1 Replies

Generic Function For List Type Filter?

Jan 13, 2011

I would like to write a generic function that would search a List(Of T) for all elements of type TFilter and return a List(Of TFilter) which comprises those elements.

I've tried this:
Public Function FilterList(Of T, TFilter)(ByVal ListToFilter As List(Of T)) As List(Of TFilter)
Return ListToFilter.FindAll(Function(z) z.GetType.Equals(GetType(TFilter))).ConvertAll(New Converter(Of T, TFilter)(Function(z) CType(z, TFilter)))
End Function

But, it gives the following error:
Value of type 'T' cannot be converted to 'TFilter'.

View 2 Replies

Create A List Of A Generic Type That Will Be Passed As A Parameter?

Feb 14, 2011

say I have two POCOs I'm using in EF code first

Public class C1
property F1 as integer
End Class
Public class C2
property F2 as String
End Class

I want to have a function that will create a list either of C1 or C2, to be used in some generic operation, such that

[Code]...

View 1 Replies

.net - Test If Property Of Type System.Collections.Generic.List(of T)?

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

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

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

Generic TypeOf Operator - See If List Is A List(Of T) Variable - Error: "Type Expected"?

Jan 5, 2011

Dim x = GetType(List(Of )) 'valid statement
Dim list As New List(Of String)

Now I want to see if list is a List(Of T) variable: Dim isList = TypeOf list Is List(Of ) On the last line I get a compile error: "Type Expected". Is there any cheap-performance TypeOf operator alternative for generics?

View 2 Replies

Error - Red "List" Says Too Few Type Arguments To System.Collections.Generic.List(Of T)'

Mar 12, 2009

I have converted c# .cs to vb:= I have 6 errors on:

Red "List" says Too few type arguments to system.Collections.Generic.List(Of T)'
Orange "Calendar" says Value of type 'System.Windows.Forms.Control.ControlCollection' cannot be converted to 'Form1.Kobush.Windows.Forms.Appointment'.

[code]....

View 6 Replies

Can't Find The .net Equivalent Of A Variable Type Of A "raw" Generic List That Takes A Wild Card?

May 17, 2012

I'm strictly looking for a language conversion here of this:List<?> I already have a work around I'm just surprised that I can't find the vb.net equivalent of a variable type of a "raw" generic list that takes a wild card.Java's mechanism here enables you to reference a list regardless of what T is.Java even enables you to go further and do things like:

List<? extends Number>
List<? super Double>I tried:
List(Of )

and that did not work. That only seems to work inside the GetType function.

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

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

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

VS 2008 Accessing Something With A Generic Generic?

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

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

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

Asp.net - Value Of Type 'System.Collections.ArrayList' Cannot Be Converted To 'System.Collections.Generic.List(Of ITextSharp.text.IElement)'

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

Creating Custom Generic Class?

Jan 1, 2011

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

View 7 Replies

Determine If Property Is Generic List<of T> Via Reflection And Loop List Items

Oct 1, 2009

I'm looping all the properties in an object via reflection:

For Each p As PropertyInfo In values.[GetType]().GetProperties()
If p.CanRead Then
'Do stuff
End If
Next

how to determine whether the property in question is a generic List(Of T)? If it is I need to loop the list itself.

I've experimented with GetType and TypeOf but have not managed to get anything working.

To clarify, I want to keep this generic. I do not want to specify the type of T, I need to loop the list items and call the ToString method on each item. T could be one of a number of different types (application specific reference types). Is it possible to do this without specifying types?

(VB.NET 2005 with .Net 2.0)

View 3 Replies

Generic Declaration Using Type?

Jul 31, 2009

I'm trying to declare a generic using a variable of type System.Type, with VB 2005, and haven't found the right approach. Consider the typical:

Dim m_GenObj As MyGenericObject(of T)
Instead of using "T" I want to use a variable of System.Type, for something like:
Dim m_MyType as Type
Dim m_GenObj as MyGenericObject(of m_MyType)

But of course that doesn't work.

View 2 Replies

Returning Generic Type In .NET?

Mar 7, 2011

Someone (w69rdy) in Stack Overflow helped me out with a great example to handle DB output, that could potentially be NULL, passed into a function. The problem is I can understand the method as written in C# but I am having a problem understanding how to rewrite the method in VB.NET. The method uses generics and I am lost. Here is the method written in C# ..

public T ParseValue<T>(System.Data.SqlClient.SqlDataReader reader, string column)
{
T result = default(T);
if (!reader.IsDBNull(reader.GetOrdinal(column)))

[code].....

How is this written in VB.NET? How does the method signature change when returning a generic type?

View 2 Replies

.net - Returning A List Using Entity Framework, 'System.Collections.Generic.List Cannot Be Converted To '1-dimensional Array

May 3, 2012

i have issue returning a list in a web method. here is the code

<WebMethod()> _
Public Function getTags(para_parents As String) As List(Of getTypeDetailsByParentName_Result)()
Dim context As New PPEntities

[code]....

the error is

Value of type 'System.Collections.Generic.List(Of SaftyonRoad.getTypeDetailsByParentName_Result)' cannot be converted to '1-dimensional array of System.Collections.Generic.List(Of SaftyonRoad.getTypeDetailsByParentName_Result)'

View 1 Replies

Pass Generic List To A Function That Has A Custom Defined List

Apr 7, 2011

it seems always at this time I cant figure out how to do something maybe it has something to do with lunchtime.

Im having trouble using a method that is defined by an outside company

This is a link to their integration guide:

[URL]

This is their documentation for the class Im trying to use

OrderQueryWebService Class

This class is for SID in particular and is made for use with the notification methods. This is for the Order Query Web Service specifically, allowing clients to return the status of transactions for their merchant, whenever they want to.

Methods
/ <summary>
/ Pass through the variables required and receive a list of Transaction
objects showing transaction status

[Code].....

The MerchantCode, the MerchantUsername, the MerchantPassword are all good the List is a custom type called SetComHash.Transaction

Everytime I try adding a string to the list such as the transactionNumber and some other values it gives me a type error:

"Value of type string cannot be converted to 'SetcomHash.Transaction'

View 13 Replies

Creating Generic Collections And Calling To New VB Page?

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







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