Call NET Generics In A Dynamic Way?

Oct 28, 2011

Names of entities have been altered to protect their identities...

I've created a class called AnimalSearch(Of AnimalType As Animal(Of Int32))

Public Class AnimalSearch(Of AnimalType As Animal(Of Int32))[code]...

View 2 Replies


ADVERTISEMENT

Call A Dynamic Compiled Func(of ) Function Via Expression.Call?

Mar 22, 2012

I want to create an ExpressionTree where a Func(of Vector, Vector, Vector, Vector, Double, Double, Vektor) should be called. So I use

Expression.Call(Forces(0).Function.Method, {Vec1, Vec2, Vec3, Vec4, Double1, Double2})(Vec1-4, Double1-2 are declared as ParameterExpression and Forces(0).Function as Func(of Vector, Vector, Vector, Vector, Double, Double, Vector). But I get an AgrumentException, because Forces(0).Function.Method has seven Arguments. (System.Runtime.CompilerServices.Closure as seventh argument at Index 0).

View 2 Replies

Call A Chart By Its Dynamic Name?

May 2, 2012

How do you select a chart based on its name? I have a number of charts in a form and I need to assign data to particular charts at particular times. I would like to have a simple code sequence to assign data to the appropriate chart depending[code]....

View 7 Replies

.net - Dynamic Call To A Database From Web Application?

May 16, 2012

I am looking to make a database call based on user input. The line I am using is:general_read.CommandText = "SELECT * FROM general WHERE Business_Name = '" & business_name & "';"

business_name is dynamically loaded from:Protected Sub btnLoad_Click(sender As Object, e As System.EventArgs) Handles btnLoad.Click business_name = txtName.Text

[Code]...

The error that is being shown is: Exception Details: System.NullReferenceException: Object reference not set to an instance of an object.I'm assuming it has something to do with the variable not being set before the database call is made, but I'm not entirely sure.

View 1 Replies

Call Dynamic Function In Access And VB6?

Mar 12, 2009

I work with Access and VB6 for quite a while. I have read the thread of Phillip Maerz, but there was still the problem that the Function names had to be written in the delegate array. Thats why I started a new thread.Following Problem:How can I call a funktion dymacally, something like thisPublic Function Test1()Returns 1End Function Public Function Test2()Returns 2End Function Sub Main()dim i, r as integeri=2

View 5 Replies

.net - LINQ Dynamic Method Call Using Expressions?

May 3, 2011

I'm trying to implement multicolumn filtering using LINQ expressions in a class that extends BindingList(Of T). Here is the relevant code:

Public Function GetFilterPredicate() As Func(Of T, Boolean)
Dim expressionList As List(Of Expression) = New List(Of Expression)
For Each item as FilterInfo in _FilterList

[code]....

However, an exception is thrown at the Expression.Call statement. I can't quite figure out the right arguments to supply. As it is now, I am getting this error when I run the code:

InvalidOperationException was unhandled:No generic method 'Equal' on type 'System.Linq.Expressions.Expression' is compatible with the supplied type arguments and arguments. No type arguments should be provided if the method is non-generic.

View 1 Replies

Access Values Of Dynamic Controls Added To Dynamic Tabpages?

May 8, 2011

i have created a dynamic tabpage and a dynamic tablelayoutpanel inside it then added dynamic textboxes and labels inside the tablelayoutpanel...the thing is , i am having a problem on how to access the value of those textboxes and labels and add them as new columns in the new table(tagpage) in mysql database, i can already create the table in the database but i cant add the new columns in it. heres the code for accessing the values of the labels and textboxes

error: NullReferenceException was unhandled....Object variable or With block variable not set.

sql = "alter table " & tbl_selected(counter) & " add " & frmMain.Controls("TLP_" & SecArrList_sp(counter2)).controls.item(SecArrList_sp(counter2) & "label" & counter).Text & " varchar(100) NULL;"

View 2 Replies

Dynamic LINQ Query Based On Dynamic Number Of Comboboxes?

Feb 5, 2010

I would like to bind a DataGridView to a different LINQ query every time (in order to reuse the same form/DGV for different queries), like this:

[Code]....

but the "Qry", and the number of comboboxes, and their field names would change every time.

View 5 Replies

Can The T Of Generics Be An Interface

Jul 17, 2010

In my program I have an interface iGraphable that contains two properties: Abscissa and Ordinate. Then I have an xxxx class (actually more than one) implementing iGraphable and a ListOfxxxx class implementing BindingListView(Of xxxx).To draw graphs I have a Graph class with a property called Data whose type is BindingListView(of iGraphable).Why have I a cast exception when I pass a BindingListView(Of xxxx) to the Data property.

View 3 Replies

Constraints On Generics With .Net?

Dec 14, 2011

I have the a function that is declared like so: Public Sub Modify(Of SIMType As {New, DAOBase})(ByVal obj As SIMType)

I also have a class called Products which is declared like so:

Public Class Products Inherits DAOBase

So as you can see, if I were to call this function like so:

Modify(Of Products)(new Products())

This would not be an issue. The issue actually arises when I try to cast the object being past in to its real type. For example: both do not work. I get a Value of type SIMTYPE cannot be converted to IMS.Products error. Im assuming this is because I am using generics. Is there a way to adjust my function to allow for a casting operation like I am trying to do? In the end, what I need is a reference of the actual type (Products in this case) to the object.

View 2 Replies

VS 2010 MDITAbControl Add Dynamic TextBox With Dynamic Webbrowser?

Feb 29, 2012

Basically i have one TabControl with a form and 2 browsers within one form I have ProBlem To call the dynamic browser to navigate with dynamic Textbox.text

[Code]...

View 6 Replies

.net - Polymorphism In .Net When Dealing With Generics?

Jan 6, 2012

I have a function called Modify. It is delcared like so:Public Function Modify(Of SIMType As {New, DAOBase})(ByVal obj As DAOBase) As Boolean

You can see that this function is generic. It takes as a paramer a object that is a DAOBase or subclasses of DAOBase.Inside the modify function there is a call like so:

DAOToGP(obj)This is where the polymorphism comes into play. There are four or so subclasses I have created of DAOBase. I have written a DAOToGP() for each of these types. So in the Modify() function, when it calls the DAOToGP(obj), polymorphism should kick in and it should call the correct implementation of DAOToGP() depending on the type that I pass into Modify().

However, I get the following error:Error 20 Overload resolution failed because no accessible 'DAOToGP' can be called without a narrowing conversion:'Public Shared Function DAOToGP(distributor As Distributors) As Microsoft.Dynamics.GP.Vendor': Argument matching parameter 'distributor' narrows from 'SierraLib.DAOBase' to 'IMS.Distributors'.'Public Shared Function DAOToGP(product As Products) As Microsoft.Dynamics.GP.SalesItem': Argument matching parameter 'product' narrows from 'SierraLib.DAOBase' to 'IMS.Products'. C:Usersdvargo.SIERRAWOWIRESDocumentsVisual Studio 2010ProjectsSIMDev_2SIMIMSDVSIMLibGPGPSIMRunnerRunnersRunnerBase.vb 66 39 IMS

I am kind of at a loss here. I am not sure why it cant figure out which function to call.

View 2 Replies

.net - Suppress COM Generics Warning?

Dec 8, 2010

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

.Net To Use Generics For Settings Persistance?

Nov 30, 2010

I'm trying to reduce code bloat, reduce errors and simplify codebehind by use of generics. In this case I'm applying generics to declaration of persistable properties. Persistance is implemented by My.Settings. Here's the code so far.

[Code]...

View 1 Replies

C# - Appropriate To Use Generics Versus Inheritance?

Apr 28, 2009

What are the situations and their associated benefits of using Generics over Inheritance and vice-versa, and how should they be best combined?I'm going to try to state the motivation for this question as best I can:I have a class as shown below:

[Code]...

Now suppose I have a repository that takes an InformationReturn argument, that has to strore different fields in a DB depending on the type of Info object T is. Is it better to create different repositories each for the type T is; one repository that uses reflection to determine the type; or is there a better way using inheritance capabilities over/with generics?

View 6 Replies

C# - Multiple Generics Ambiguity?

Dec 27, 2011

The codes below are exactly the same, except that one is C# and the other one is VB.Net.C# compiles just fine, but VB.Net throws the warning:

Interface 'System.IObserver(Of Foo)' is ambiguous with another
implemented interface 'System.IObserver(Of Bar)' due to the 'In' and
'Out' parameters in 'Interface IObserver(Of In T)'

Why does VB.Net show the warning and not C#? And most important, how can I resolve this problem?

Obs: I'm using .Net Framework 4 with Visual Studio 2010 Ultimate.

VB.Net Code:

Module Module1
Sub Main()[code]......

View 2 Replies

Calling Constructor When Using Generics

Mar 9, 2011

I'm not sure if this is possible or not. I have a number of different classes that implement interface IBar, and have constructors that take a couple of values. Rather than create a bunch of almost identical method, is it possible to have a generic method that will create the appropriate constructor?

private function GetFoo(Of T)(byval p1, byval p2) as List(Of IBar)
dim list as new List(Of IBar)
dim foo as T
' a loop here for different values of x
foo = new T(x,p1)
list.Add(foo)
' end of loop
return list
end function

I get:
'New' cannot be used on a type parameter that does not have a 'New' constraint.

View 2 Replies

Converting VB6 Collections To .Net Generics?

Apr 21, 2012

I have a VB6 project with about 100 custom collection classes which I want to convert to VB.Net. A typical example would be something like.

Class CAccounts
Private m_Accounts As New Collection
Public Sub Add(newItem As CAccount)
m_Accounts.Add newItem, newItem.IdKey

[code].....

All of the collection classes in the project use this standard approach. However, not all the properties/methods of the collection classes are actually used. Most of the collection are used in "for each" loops. Keyed access using the string key is quite common. Keyed access by index is much less common.

Ideally I'd like to take a standard approach to converting these classes. I don't really want to have to review each collection and it's usage to consider whether I need a List, Dictionary, etc. Some of these collection contain 100,000 objects, and some will only contain 10. However, on the other hand I don't want to cause performance problems by using a more complex structure where a simpler option would do.

Sticking with the old style Collection. So, it would be relatively easy to convert to VB.Net But, I'd rather move to the more modern structures.Have CAccounts Inherit KeyedCollection(Of String, CAccount). Fortunately most of the classes held in the collections do have the key as part of the class (eg CAccount.IdKey above). This seems to work well. However, relatively few classes will access the colelction by numeric index. So, perhaps this is overkill if I only want keyed access by the string key?Have CAccounts Inherit Dictionary(Of String, CAccount) for the classes where I don't need access by numeric index. The problem I have with this is that all the existing "for each" loops are like "for each account in accounts". I don't want to have to change all these occurences to something like "for each account in accounts.Values". Although perhaps I can get round this by changing the default property?Have CAccounts Inherit MyCollection(Of String, CAccount), where MyCollection is my own bespoke collection. This seems a bit too much hard work.

View 2 Replies

Generics And Duck-Typing XML In .NET?

Feb 12, 2010

I'm working with some XML representations of data instances.I'm deserializing the objects using .NET serialization but something in my soul is disturbed by having to write classes to represent the XML.[code]

View 4 Replies

Generics Versus Extensions?

Nov 8, 2009

This is my problem:

<System.Runtime.CompilerServices.Extension()> _
Function CastAs(Of TSource As TTarget, TTarget)(ByVal array As TSource()) As TTarget()
Return Global.System.Array.ConvertAll(array, Function(src As TSource) DirectCast(src, TTarget))
End Function

View 10 Replies

Have Generics In A Class Property?

Jul 28, 2010

I have a Class that is defined as

Public MustInherit Class Entity(Of T As Entity(Of T))

And various classes derived from it. I would like to have another class accept all of the derived objects as a property, but I cannot seeem to find a workable syntax. If it were a parameter of a sub, I could say

Public Sub Foo(T As Entity(Of T))(TheEntity As T)

I can't seem to get that to work for a property:

Public Property E(Of Entity(Of T))() As Entity(Of T)

Gives me "Type parameters cannot be specified on this declaration"

Public Property E() As Entity2008(Of T)

Gives me "Type Parameter T does not inherit from or implement the constraint type ..."Is there an acceptable way to do this or am I stuck with using a Set Sub and a Get Function?

View 2 Replies

Numeric Type Only Generics?

Jan 20, 2011

Suppose I have an interface called IParseable(Of TParsed, TUnparsed) which requires two functions:[code]Is there a way that I can restrict TParsed and TUnparsed to be numeric types (for which operations like "*" and "+" are already defined)?The problem is that, when I try to implement my interface and define one of the functions, e.g.:[code]VS throws an error saying the "*" is not defined for TUnparsed. I understand that, since TUnparsed could be anything, but is there a way to restrict my generic such that, say, TUnparsed could only be Double, Integer, Long, etc? To require Control to be a TextBox (or maybe I don't understand that very well either). But, anyway, any idea or am I way off track? Just trying to get a hang of these interface thingies and generic types.

View 2 Replies

Use Generics In Linq Query?

Jul 28, 2009

I am trying to write a generic function that generates an Xelement based on a list of objects, and a property of the object[code]....

View 3 Replies

.net - Naming Standard For Generics - Of T Or Of TEntity?

Mar 16, 2011

I know this is a stupid question maybe, but what is the naming standard for generics?Of t or Of TEntity or Of..it doesn't really matter?I see IQueryable(Of T) but then DBSet(Of TEntity).

View 3 Replies

C# - .NET Generics - Compare Two Lists And Filter?

Jun 19, 2011

I have two generic lists of type T. Both lists contain same type, and I'd like to create a third list (or a filtered version of list 2) based on the items in list two that do not exist in List 1, based on the ID of each item.Each list holds a "Package" object, which has an ID property.Right now I mocked up the code using For Each loops, which I know is horrible (the Big O is constant time) so I'd like a more efficent method. this code is in VB per project requirments, but I prefer C# - so either code sample would work for me.

Private Sub RemoveStockPackagesFromSelection()
Dim p As Package
Dim packageList As List(Of Package) = New List(Of Package)

[code]....

View 5 Replies

C# - .Net Generics: Making Validation Generic?

Feb 27, 2012

I have the following C# code. Here the validations are kept outside the class to satisfy Open - Closed Principle. This is working fine. But the challenge is - the validations are not generic. It is specific to employee class (E.g DateOfBirthRuleForEmployee). How do I make the validations generic for all objects (DateOfBirthRuleForAnyObject).

Note: Make Generic <==> Make Type-Independent

Note: I have NameLengthRuleForEmployee validation also. New validation may come in future.

class Program
{
static void Main(string[] args)

[code]....

View 1 Replies

Difference Between Array List And Generics

Dec 20, 2010

I know boxing and unboxing part in arraylist but question is if I define only string in arraylist then there is no question of boxing or unboxing. What will be the difference.

View 1 Replies

First Parameter In The Definition Of .NET Generics Uses The 'Of' Keywo?

Dec 13, 2011

Why only the first parameter in the definition of VB.NET Generics uses the 'Of' keyword ?

For example I have here the the full code that LINQ uses for the Enumerable.Select() method :

<System.Runtime.CompilerServices.Extension()> _
Public Shared Function [Select](Of TSource, TResult)(
ByVal source As IEnumerable(Of TSource),
ByVal selector As Func(Of TSource, TResult)
) As IEnumerable(Of TResult)

[Code]...

View 9 Replies

Flexibility Vs Performance With CType And Generics?

Apr 11, 2012

Recently I found a way to make CType work with generics (FYI, VB 2010 Express with option strict on). Say I have two generic types, T1 and T2, with variables x as T1 and y as T2. y=CType(x,T2) diagnoses with "Value of type 'T1' cannot be converted to 'T2'". y=CType(CObj(x),T2) compiles cleanly, and it works fine provided that T1 can be converted to T2. Failing that, an exception will be raised at run-time. Obviously, a downside of this is the boxing performance hit. Also, it is a half a step backward along the road to strong typing (a type conversion problem is discovered at run-time vice compile-time).

These objections aside, consider the GSU class below. There are two ways to do a generic CType of a variable, and then there is a way to do a CType of an entire array. GSU is sufficient (see sub Test) to convert an item or an array of items between, for example, all the numeric types (byte, short, double, ...). Exception handling remains to be done.

Type conversion code tends to get lengthy, so I think this is a nice result. What do you think? I am guessing that CType has some pre-generic smarts in it, and all I did was find a way to exploit it in the context of generics and option strict. I am mostly interested in generic tricks for value types.

[Code].....

View 3 Replies

Free Items In Generics List?

Mar 21, 2011

I have been trying to use the Generics List as a means of storing a large amount of data that I am reading in from hardware. I defined a class called 'Datapoint', that has several public variables of type Double, and as I read in a number of points (this is of variable length, and could potentially be very large), for every point I create a new instance of 'Datapoint', update its fields and then add it to a List(of Datapoint) which I named 'Datalist'. All works fine, except when I come to reset the List, I do not know how to free up the allocated memory. I have attached some snippets of code,

[Code]...

View 3 Replies







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