Make Specialized/overloaded Generics?

Jan 26, 2012

I tend to loath repetition in code, so when I come across a problem where the only different is types I tend to use generics. Coming from a C++ background I find vb.net's version to be rather frustrating, I know C++ has template specialization and I guess vb.net does notso what I have is a set of routines that do the exact same code regardless of type being passed.something like this

Public Sub decision(Of T)(ByVal a As T, ByVal b As Integer)
If b > 10 then
gt(a)

[code].....

View 2 Replies


ADVERTISEMENT

Generics Mixed With Overloaded Event?

May 24, 2011

I am looking for a little expert design insight.I am trying to save an overloaded property from a generic class.

Base Class

Public MustInherit Class BaseEvent
Public MustOverride ReadOnly Property IsWorkCalendar() As Boolean[code]....

View 2 Replies

Added A Specialized Stringdictionary To Project?

Jun 10, 2009

i added a specialized stringdictionary to my project. i can save to it, + on form_closed it has the correct count, but when i reload my project the stringdictionary is always nothing.i read somewhere on the internet that i need to make the setting serialize as binary, but i can't see how i should do that? heres the Settings.Designer.vb file. where should i specify serialize as binary?

[Code]...

View 4 Replies

Add Item To System.Collections.Specialized.String Collection When It Is Not Already There?

Dec 29, 2010

How can I have it so that you can add items to a System.Collections.Specialized.String Collection but only if it is not there already? I have already found the code, but deleted it and cannot remember it. It is something like[code]....

View 9 Replies

Populate System.Collections.Specialized.StringCollection Object From A Text?

May 6, 2010

Say I have a text file I want to load it to a System.Collections.Specialized.StringCollection

object dim a as System.Collections.Specialized.StringCollection

set a = a contains many systems System.Collections.Specialized.StringCollection object.

Each line in text.txt go to an element in a.

View 7 Replies

What's An Example Of An Overloaded 'And' Operator

Nov 21, 2010

So Google's not a good choice for looking up examples for overloaded operators like "And" or "Or", because it tries to parse them as operators to the search query itself. MSDN also provides no examples of how to implement an overloaded And operator, so I'm not certain how to properly overload it for my project.Does anyone have an example of "And" at minimum? "Or" or "Xor" (or any others) would be a bonus. I'm not certain if I need to overload these operators in my objects just yet, as I'm still building them out and haven't planned beyond just yet. But having examples around that might get indexed by Google will probably help save the sanity of a lot of people...

View 2 Replies

2010 - Published A ClickOnce Deployment Package - Specialized Hebrew Font In The Application

Sep 29, 2011

I've developed a database application in VB.Net 2010 Express and published a ClickOnce deployment package, the only choice in the Express version. The installation is supposed to create a listing on the Start menu but this isn't happening. Also, I'm using a specialized Hebrew font in the application that is not carrying over to the installation. what I'm doing wrong or if the ClickOnce publishing method is not capable of working in this way?

View 2 Replies

Block Specific Websites By Adding Them To A System.collections.specialized.stringcollection In My.settings?

Nov 7, 2010

I'm trying to block specific websites by adding them to a system.collections.specialized.stringcollection in my.settings, where i use

Private
Function
GetBrowser() As

[code]....

View 7 Replies

Class That Contains Overloaded Methods?

Jul 16, 2011

In this project I am making a grade calculator; I am modifying an existing code I have to have the following characteristics: I need to modify the DetermineGrade method so that it accepts the maximum number of points that can be earned on both tests (currently, the max number of points is 200: 100 points per test). For an A grade, the student must earn at least 90% of the total number of points. For a B, the student must earn at least 80%. For a C, at least 70%. For a D, at least 60%. If they earn less than 60% of the total points, then grade is F. Here is the exisint code I have for the DetermineGrade method specifically:

Public Sub DetermineGrade()
Dim intTotal As Integer
intTotal = _intScore1 + _intScore2

[code]......

View 5 Replies

Combining 20 Overloaded Subs Into One?

Jan 31, 2012

I'm working with a third-party library interfacing to an old database system. There's a method - CallProg that calls a "stored procedure" (for lack of a better translation - any Pick users in the crowd?). However, instead of doing something like this:

Public Sub CallProg(ProgName, ParamArray ProgArgs() As String)
...
End Sub

[code].....

View 2 Replies

How To Come Axwebbrowser.Navigate() Is Not Overloaded

Mar 11, 2011

I have two computer. Both have VS2003, but on one of them, Navigate() is overloaded. Its either Navigate(string) or Navigate(string, ref obj, ref obj..and so on). But on my other computer, Navigate only has Navigate(string, ref obj, ref obj....)

View 1 Replies

.net - Adding An Overloaded Constructor To A WinForm?

Oct 14, 2010

I have created a dialog as a winform and am calling that winform like this:

Dim dlgEditChangeOrder As New dgEditChangeOrder
Dim dlgResult As DialogResult
dlgResult = dlgEditChangeOrder.ShowDialog

pretty simple. I want to be able to set the visiblility of a control on the win form when the win form is called. I would like to do this as a constructor so I could write the following. Dim dlgEditChangeOrder As New dgEditChangeOrder(visibleIsTrue)

Can someone give me the contructor code to make this happen? The reason I am concerned is I dunno if its legal to do this inside a winform since the winform is loaded bby the precreated IntializeComponent() function

View 1 Replies

.net - Alias In Function Declaration Overloaded?

Feb 24, 2009

I have some VB6 code that I am converting to VB.net and came across this section

Declare Function TmSendByLen Lib "tmctl.dll" Alias "TmSendByLength"(ByVal id As Integer, ByRef msg As Any, ByVal blen As Integer) As Integer
'snip'

[code]....

I have not come across the Alias term before but I can guess what it does. What I am unsure of is the reasoning behind overloading the alias. If that is what is happening.I need to create overloads for the TmSendByLen function as the 'As Any' is not supported in VB.net so I am not sure if I should just remove the alias or if I should leave it in place.

View 2 Replies

Overloaded Constructor In Abstract Class

Nov 19, 2010

I have an abstract class in vb.net with two subclasses. In the abstract class I have a constuctor that looks like this:[code]I would like to create a second constructor that doesn't take any arguments and just initializes the args to default values.[code]When I attempt to create a new subclass using the second constructor the compiler complains that I'm missing two args to the constructor.Is there a reason I can't overload the constructor in the abstract class?

View 2 Replies

Property Attribute Overloaded 11 Of 11 DefaultValue

Jan 18, 2012

[Code]...

Why is the first line not correct? What it wants is a System.Type and a System.String but refuses to work.

View 15 Replies

Search Routine Causes An Overloaded Exception?

Jan 11, 2010

As some of you may know i been working on an inventory program, for this part of the app the user enters an ID number and clicks search, the app searches for the ID and shows if it exists or not.

[Code]....

View 3 Replies

.net - Entity Framework Parameterized/Overloaded Constructors?

Mar 17, 2011

In my previous application using Linq2SQL I was able to overload constructors with parameters by doing this:

Namespace CoreDb
Partial Public Class Accomplishment
Public Sub New(ByVal accomplishmentTypeID As Object, ByVal description As String, ByVal title As String, ByVal applicableDate As DateTime, ByVal lastUpdatedBy As String)

[code]....

Basically using a partial class off the object, sharing the namespace of the .dbml file and calling the default constructor and then doing additional stuff. So then in my code I could do something like:

Dim accomplishment As New Accomplishment(id, description, title, applicableDate, lastUpdatedBy)

This seems to no longer work in Entity Framework as there is no default constructor to call.Does this no longer work? And if so what is a good alternative to implementing something like this?

View 2 Replies

C# - Overloaded .NET Extension Method In Class Library?

Jul 20, 2010

It seems that my library of extension methods that was written in VB.NET has problems.I have 2 overloaded extension methods Crop().When i reference the lib from a VB.NET project i see them. If reference it from a C# project i can't see them.

View 3 Replies

Overloaded Vb Methods Not Found At Runtime When Called By C#?

Oct 12, 2010

Not sure if this question belongs here or the Interop forum, but here is the situation. I have a vb.net app that was upgraded from vb6. It has an overloaded Login method. A simple method with two string parameters for name/password calls the primary login method with numerous optional parameters. The simple method is for compatibility with C# because, until Visual Studio 2010, optional parameters were not supported.The C# intellisense finds the overload and compiles ok... but throws an error at startup stating that it cannot find the Login method. This makes no sense and appears to be a problem with vb. (I am using .net 4 for both vb.net and the c# test harness.)ILDASM shows the following:

Public Function Login(ByVal LoginName As String, ByVal Password As String, ByVal Alias_Renamed As String, Optional ByVal LoginFrom As String = "", Optional ByVal ClientIPAddress As String = "", Optional ByVal ServerIPAddress As String = "", Optional

[code].....

View 4 Replies

VS 2010 Create An Overloaded Method In A Module

Feb 14, 2012

I'm trying to create an overloaded method in a module, but if I type Public Overloads Function GetData(ByVal sql As String) As String it tells me "Inappropriate use of 'Overloads' keyword in a module". Are overloaded methods not allowed in modules?

View 3 Replies

.net - Save System.Collections.Specialized.NameValueCollection Instance To Hard Disk And Load It Back As An Instance?

Jun 24, 2011

I have following instance of System.Collections.Specialized.NameValueCollection:

Dim UserSelection As New System.Collections.Specialized.NameValueCollection
UserSelection.Add("D_Color1", "Black")
UserSelection.Add("D_Color2", "Green")
UserSelection.Add("D_Color3", "Purple")

I need to save this instance to hard disk and then load it back from hard disk as an instance. How do I do that?

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

.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

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

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







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