Generics And Interfaces: Correct Deceleration?

Feb 8, 2012

I came to the point where I have to clone a complex data structure. During this process, cloning an object multiple times must be avoided, and circular references must be considered. I already have a working solution for this:

Friend Interface ICloneable(Of T As {Class, ICloneable(Of T)})
Function Clone(ByVal CloneMap As CloneMap(Of T)) As T
End Interface
Friend MustInherit Class CloneMapBase(Of T As Class)

[code]....

View 3 Replies


ADVERTISEMENT

Class Deceleration As Array?

Dec 20, 2011

I have done developments using class module and property. I have done the deceleration as follows in VB6.

VB6 deceleration
Public BomMatList() As New MaterialList

After this deceleration i use BomMatList as array as follows

BomMatList(I).MatDescription = "New Material"

I can execute this statement on a for loop and change the value of "I" to increase the array size. How can i do the same in Visual Studio 2010.

View 3 Replies

Is It Correct To Correct Properties Values On The Fly

May 15, 2010

Is it correct to correct properties values on the fly? for example: (note the .ToLower)

Public Property X() As String
Get
Return _x.ToLower
End Get

[code]....

View 1 Replies

Connect To SQL DB Receive The Code And Then Check If That Code Is Correct And If Its Correct Download Silence The Pro File?

Jun 8, 2010

i'm working on a system that upgrades a basic version to a proversion but i have a payment gateway . it generates a code in an SQL DB.now i have a form in VB that has a textbox and a button how can i let VB connect to my SQL DB receive the code and then check if that code is correct and if its correct download silence the pro file. from an url.

View 7 Replies

VS 2005 Getting The Correct Number Of Attributes To Match The Correct Number Of Text Boxes?

Apr 18, 2009

I have created a basic query generator which allows a user to select the Select, WHERE and criteria attributes using a number of checkboxes.However i have got stuck. In the results form i have the following code

Private Sub DisplayRecord()
RichTextBox1.Text = ds.Tables("newResults").Rows(intCurrentRecord).Item(0)
RichTextBox2.Text = ds.Tables("newResults").Rows(intCurrentRecord).Item(1)
RichTextBox3.Text = ds.Tables("newResults").Rows(intCurrentRecord).Item(2)

[code]....

The program keeps on crashing if the user does not select the corresponding amount of display records from above for the amount of attributes they want for the SELECT part of the query in the intreface in form 1.

How would i go about making something where the number of SELECT attributes selected which are listed in a string create the correct number of textbox fields in the results form (form2)

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

Are Interfaces Used Often

Oct 16, 2009

Are Interfaces used often? Need opinions.

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

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 - Casting Interfaces And MEF?

Mar 13, 2009

I have the following problem with MEF: Interface definition to be used by host:

Public Interface IExecuteDoSomething
Inherits IAddinSettings
Event DataReceived As EventHandler(Of DataReceivedEventArgs)
Function DoSomething() As Boolean
End Interface

[Code]...

Everything seems to work fine until the Button2_Click routine is executed, then an InvalidCastException is thrown with the info:Unable to cast object of type 'System.Collections.Generic.List1[SharedLibrary.IExecuteDoSomething]' to type 'System.Collections.Generic.List1[SharedLibrary.IAddinSettings]'.

How can i solve this problem, because the imported object implements both of the interfaces?

View 1 Replies

A To Z Usage Of Interfaces In .NET?

Dec 30, 2011

In this discussion let us discuss every usage of interfaces in .NET. Any real time examples and difficulties in using interfaces can also be discussed here.

View 6 Replies

Multiple Interfaces With .NET?

Aug 6, 2009

Im building a game with VB.NET I designed the core of the game in form1 window But now I need menus. How can I implement this without having 5 or so windows that I show() and hide() ? Doing that slows it down a lot and uses lots of memory. I tried tabs, but I don't want the tabs to appear, just switch. Whats the best way to implement multiple interfaces?

View 1 Replies

Oop - Inheritance And Interfaces ?

Jul 14, 2011

Has someone a hint what I'm doing wrong in VB.Net?

Module Module1

Interface ISearch(Of T As ISearchResult)
Function ids() As List(Of T)
End Interface

[CODE]...

The third cast isn't working. Why? did I miss a oop lesson?

View 2 Replies

Using Dictionary With Interfaces?

Sep 12, 2009

What I would like to do is make an abstract class that will hold objects in a dictionary and manage the adding/deleting/key changes of those items in the dictionary. My problem is that in order to make the class as generic as possible I declared the dictionary as dictionary(of long, of SomeInterface).The problem is when I try to pass a strongly typed dictionary in the constructor using dictionary( of long, ClassThatImplementsSomeInterface) I get a compiler error because it cannot convert to that type.

The reason I want to pass the dictionary in the abstract class's constructor is so that I can use the strongly typed dictionary in the subclass and have the abstract class manage the keys when it needs to. So how can I do something like this? Also- If there is a much better way to manage keys than what I am doing feel free to let me know, but I am much more interested in how to make this work since I have encountered this type of problem a few times before.

Here's the abstract class:
Public MustInherit Class HasChildrenKeys
Protected m_childItems As Dictionary(Of Long, IHasKey)

[code].....

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







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