Limit A Generic Type Parameter To System.Enum?
Feb 21, 2011
Anyone know a good workaround for the lack of an enum generic constraint?[cod]e...
Is is possible to limit the generic type parameter [I don't know if that's the right name] to an Enum?[code]...
View 4 Replies
ADVERTISEMENT
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
Dec 30, 2009
I have a URL lets say . some time i need to send HTTP and some time i need to send it to HTTPS for that i created a enum:
Private _protocol As Protocol
Enum Protocol
HTTP
HTTPS
[CODE]...
Now when i get value back from protocoltype it returns me integer value as enum do so tell me how to get string from enum or other substitute.
Dim targetUri As String = setting.protocolType & "://www.mysite.com"
View 1 Replies
Mar 3, 2011
I have the following VB.NET function, for example:
Public Function MyFunction (Of TData) (ByVal InParam As Integer) As TData
End Sub
How do I, in a function, determine if TData is a NULLable Type?
View 3 Replies
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
Jan 23, 2009
I have bee trying to figure out, how to match generic types, without the type parameter in a IF-ELSE statement - heres what i mean:
<P>IF TypeOf(Obj) Is GenericTypeExample(Of ???Any???) Then</P>
<P>End if</P>
View 7 Replies
Jun 25, 2010
(Not really sure if I phrased the question correctly...) I want to create a lambda expression that would take an Object, attempt to convert it to a passed-in Type, and print to the console whether it was successful or not. At a glance, the lambda expression may seem a pretty silly way to accomplish this task, but I'd really like to know what I'm doing wrong, so I can better grow my skill set.
VS gives me a designer error about the second "T" in the expression below, telling me it isn't defined) This is where I left off:
[Code]...
View 1 Replies
Jan 7, 2012
And here is the code that produces the error
CODE:
How can i cast this one?
View 1 Replies
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
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
Feb 19, 2012
I'd like to auto-register the common/simple services in my unity container. I think the cleanest way to do this would be via a custom atribute.I can then examine all the (abstract) classes in an assembly and register those types with unity.The piece of information I'm missing is the interface(s) that the class wants to be registered against
eg:
Public Class AutoRegisterAttribute
Public Property ForInterface As System.Type
Public Sub New(ForInterface As System.Type)
[code]....
Note, I don't just want to find any class it implements as shown with IDisposableI've tried doing this using generics (generics can't inherit from Attribute), with a Type Parameter (Passing in IEngine.GetType results in a "Constant expression is required")
View 2 Replies
Feb 12, 2011
This code:
vb Dim s As String = strContents '<a global variable) Dim currentPos As Int64 = 0 Dim endPos As Int64 = strContents.Length - 1 '// A dictionary, used to count the frequencies Dim characterCounter As New Dictionary(Of [String], Int64)() While currentPos <> endPos '//
[CODE]...
Gives this error: Value of type 'System.Collections.Generic.KeyValuePair(Of String, Long)' cannot be converted to 'System.Collections.DictionaryEntry'.
View 2 Replies
Sep 2, 2009
I have a generic class Class MyTestClass(Of T)where I know that T will only ever be an enum. Is there any way to declare this restriction to the compiler?And a second question: If the answer to my first question is 'no, there isn't', then what's the best way to cast T to a plain integer? Doing that is difficult when the compiler doesn't know that T is always an enum. [code]That certainly works, but it looks nasty as it apparently involves unnecessarily boxing and then unboxing the enum value. Is there a better way of doing it?
View 1 Replies
Nov 21, 2011
I don't know how to convert the following line from VB to C#:
Dim values As New List(Of T)(System.Enum.GetValues(GetType(T)))
My version doesn't work:
List<T> values = new List<T>(System.Enum.GetValues(typeof(T)));
The best overloaded method match for 'System.Collections.Generic.List.List(System.Collections.Generic.IEnumerable)'
has some invalid arguments
The constructor-parameter doesn't take it that way - what cast (or else) am I missing?
For clarification: It is wrapped up within the following generic method
public static void BindToEnum<T>()
{
List<T> values = new List<T>(System.Enum.GetValues(typeof(T)));
//...
}
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
Aug 6, 2010
I have a Generic.List(Of ImportedVehicle) - ImportedVehicle being a simple class as below.There is an enum property which is marked as public.When I serialize to XML using an XMLSerializer, the enum's value is just set to it's default value (which is NotAllocated) and doesn't actually represent the value that is set in code.[code]
View 1 Replies
Aug 14, 2010
I have a Journal that records entries for different types: Journal(Of ParentT)
[Code]....
View 2 Replies
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
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
Jun 27, 2011
VB 2008, DataGridView,DataGridView1_CellLeave(sender, New System.EventArgs)
"Unable to cast object of type 'System.EventArgs' to type 'System.Windows.Forms.DataGridViewCellEventArgs'."
What is the Correct String for "New System.EventsArgs"
Anybody there is to help me out.
View 1 Replies
Mar 22, 2012
I want to pass an optional parameter to a function of type System.Drawing.Color. The problem I am having is that when I declare the function it says "Constant expression is required" but I have tried variations of the following, including integers, full qualified indentifiers, even old vbWhite constants to no avail.
[Code]...
View 14 Replies
Jul 7, 2010
I have created a Dictionary class (MyDictionary for the example). I am currently trying to pass MyDictionary into a function, filter it into a new instance of MyDictionary and pass this new instance into another method. When I am attempting to create the second instance from the filtered first instance of MyDictionary via Lambda Expressions and the ToDictionary Method, I am getting the following error:
Unable to cast object of type 'System.Collections.Generic.Dictionary`2[System.Int32,System.String]' to type 'MyDictionary'. I have simplified the example and recreated it in LINQPad and am getting the same error.
Here's the simplified version of my code:
[Code]...
View 2 Replies
Jun 2, 2011
I am getting this error microsoft.sqlserver.jdbc.SQLServerException: The incoming tabular data stream (TDS) remote procedure call (RPC) protocol stream is incorrect. Too many parameters were provided in this RPC request. The maximum is 2100.
Im new to coding stuffs, i know that i am passing morethan 2100 parameter that is why the error is encountered.
Here is the actual code.
CODE:
View 6 Replies
Mar 9, 2011
I want to have a "template" function that can receive different parameter and a type parameter, like:[code]But Vb told me that tupeList is not defined... is there a way I can do that?
View 2 Replies
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
Jun 25, 2010
My project worked a first and now its giving me a problem.The error
Quote:
Unable to cast object of type 'System.Windows.Forms.MouseEventArgs' to type 'System.ComponentModel.RunWorkerCompletedEventArgs'.
View 2 Replies
May 16, 2011
[URL]The issue is as soon as I change the value of the text boxes it gives me an error and forces me to close the project.
The error is:Unable to cast object of type 'System.EventArgs' to type 'System.Windows.Forms.KeyPressEventArgs'.
However I'm supposed to clear the number of gallons used and the total charged when a change is made to the contents of the 2 text boxes on the form.
View 3 Replies
Jun 6, 2011
I have an InvalidCastException Error in my program. The program is that i try to insert an employee record into a database table after getting the details from a form. I've used Money data type is SQL Server for salary and SqlTypes.SqlDecimal data type in employee template class. i've used a stored procedure to pass the values and i add the basic value by passing a parameter by the method
Dim prm8 As SqlParameter = com.Parameters.Add("@basic", SqlDbType.Money)
prm8.Direction = ParameterDirection.Input
prm8.Value = emp.Bsc
I've used the money datatype itself even in the stored procedure variable.I get the following error.
failed to convert parameter value from sql decimal to decimal
Even if i use
prm8.Value = Convert.ToDecimal(emp.Bsc)
I get an error Unable to cast object of type 'System.Data.SqlTypes.SqlDecimal' to type 'System.IConvertible'.
View 3 Replies
Dec 24, 2009
Now I want to display picture in picturebox1.To do this I use this codes, but it does not display picture
on this line: Dim arrPicture() As Byte = CType(dt2.Rows(0)("img_path"), Byte())
it shows this message,
Unable to cast object of type 'System.DBNull' to type 'System.Byte[]'.[code]......
View 1 Replies
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