Implementing Generic IComparer Of Own Class?

Jun 17, 2012

I am trying to create a class implementing the generic IComparer of my own class "Stellungen" (which translates to positions, like on a chess or checkers board).

This is what I got:
Private Class comparer(Of Stellung)
Implements System.Collections.Generic.IComparer(Of Stellung)
Public Function Compare(x As Stellung, y As Stellung) As Integer Implements System.Collections.Generic.IComparer(Of Stellung).Compare
End Function
End Class

Problem is: inside the function I have no access to any fields of my class. If I start off with x. Intellisense will only give me .Equals, .GetHashCode - the methods you get on a type but not on an instance. Visual Studio 10 also highlights this, in the definition of the function the bits "x as Stellung" and "y as Stellung" are written in light blue, meaning it is a type and not an actual object. How do I access the things I want to compare inside my class?

View 1 Replies


ADVERTISEMENT

Way To Implement IComparable (Of T) Or IComparer(Of T) If Class Is Not A Generic Class

Feb 19, 2010

I am working on a general helper class to sort ListView SubItems. I wrote a base class that has much of the code I need. It includes a MustOverride for the Compare method so that the various inherited classes can implment their own comparisons based upon their type. For the value types, I end up with very similar code such as the following, where x and y are ListViewItems: Public Overloads Overrides Function Compare(ByVal x As Object, ByVal y As Object, ByVal sortColumnIndex As Integer, ByVal sortOrder As System.Windows.Forms.SortOrder) As Integer [code]

View 3 Replies

Implementing IList (Of T) In Generic Class

Jun 26, 2009

I am creating a generic class that is Implementing IList(Of T) which requires that I implement the GetEnumorator of both IEnumerable(Of T) and IEnumerable. When looking at the members of IList(Of T) I see only one GetEnumorator function, yet it implements IEnumerable(Of T) and IEnumerable. How can I use one function to implement both interfaces when the function definitions only vary by return type?

View 8 Replies

Implementing IComparer For Custom Objects After Converting A Dictionary To SortedDictionary?

Jun 5, 2012

I'm having trouble implementing an IComparer method. Essentially, I want to compare the properties of two custom objects (the properties are of type integer).dE is a Dictionary(Of String, customObj)prTabIndex is a property of customObj and is of type Integer (these hold true for all examples)After some more searching I found this thread which suggested 3 things: a List approach, utilizing LINQ, and using some C# 3.0 features. I've tried three different ways:...rolling my own IComparer implementation:

Public m As Sub(ByRef d As Dictionary(of String, customObj))
Dim sortedD As New SortedDictionary(Of String, customObj)(d, myCompare)
End Sub

[code]....

Note that VS2008 has underlined 'dE.ToDictionary...' (to the end of the line) and giving me two messages depending on where I hover my mouse:

1) "Data type(s) of the type parameter(s) in extension method 'signature' As 'signature defined in 'System.Linq.Enumerable cannot be inferred from these arguments. Specifying the data types explicitly might correct this error. Seen while hovering over "ToDictionary".

2) Nested function does not have the same signature as delegate 'signature'. Seen while hovering over anything after "ToDictionary".

Q1) How far off am I in each of the implementations?

Q2) Which one is the computationally least expensive? Why?

Q3) Which one is the computationally most expensive? Why?

View 1 Replies

Overload Operator In Generic Class With Generic Interface Of Super Class And Inherit Class?

Jan 21, 2010

I can do this without problem.

Class A
End Class
Class B : Inherit A
End Class
Dim Obj1 As A = New B

View 4 Replies

Implementing Inherited Generic Interface?

Nov 29, 2011

In our current project I am using a generic interface iService which is inherited by all other service interfaces. For instance IService is inherited by ILogService.

The ILogService interface is then implemented by LogService as below:

Public Interface IService(Of T)
Sub Save(ByVal T As IEntity)
Sub Remove(ByVal T As IEntity)

[Code]....

How can I update the method signature so T is displayed as Log?

View 2 Replies

.net - Performance Implications Of Implementing A Generic Type And A Delegate In A Function?

Aug 4, 2010

I wrote a serializer (to Byte Array) for dictionaries that have a string key, but an object of some sort as its value.I've never implemented a generic type in a function or used a delegate before, so I'm a bit concerned about this being significantly slower than writing a serialization function for a specific type of Dictionary (Dictionary(Of String, MyClass) for example)Should this code be significantly slower due to the use of the generic type or the delegate?

[code]...

It works, and I could loop it and compare it to a more static Dictionary serializer, but I'm more concerned about when I start using this for a lot of different String/Object dictionary combinations, and it'll take me a long time to write a bunch of static dictionary serializers (that's what I'm hoping to avoid in the first place)edit: simplified intro text

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

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

Implementing A C# Interface In A VB Class?

Oct 28, 2010

I am working on a plugin architecture and after some reading I have settled on one. The host class will be implemented in C# as well as some of the plugins for that host. The issue I am having is that some of my team uses VB.net. So the question, is it possible to implement a C# (plugin)interface in VB, such that when it is dynamically loaded into the host program it will have the methods required by the interface.

View 1 Replies

Implementing Class With Chain Of Inheritances

May 30, 2009

Usually, if I make a class that has an implementation and also inherits a class with same method signatures, then I do not need to manually add implementation code. For example, if I create a class that inherits List(of Double) and Implements IList(of Double), then I do not need to add any code to make this compile, since the program realizes that the inheritance covers all the methods of the implementation. (Even though VB will auto-generate methods you can remove them no problem).

Now I'm trying do to something more complicated, using an implementation on top of IList, with a class that has a chain of inheritances, and the program won't accept it. See this example:

Interface ICustomList
Inherits IList(Of Double)
Sub TestSub()
End Interface
Class BaseList
[Code] .....

The final item, CustomList, is not compiling. The program says 'TestSub' must be implemented, but by inheriting BaseList, the class has a TestSub (and it is recognized by intellisense)! All the subs exist, they are functional, so why is the implementation not valid? (I know I can get rid of this error by manually creating an (overloading) TestSub in CustomList and specifying that it is an implementation. However, this should not be necessary since it already exists, and if I am going to be building a chain of classes inheriting each other, this could potentially become time-consuming and annoying.)

View 1 Replies

Implementing Events In A Base Class?

Nov 15, 2010

Consider the following objects:

Public MustInherit Class FileRepository
Public MustOverride Sub SaveStringToFile(ByVal FileText As String, ByVal FilePath As String)
Public Event FileSaved(ByRef sender As Object, ByVal EventArgs As EventArgs)

[code]....

I want my base class to raise the FileSaved event in it's implentation of SaveStringToFile once it's saved the file. However in VB.NET you can't have a derived class raise a base classes event. I suppose I can treat XMLFileRepository_FileSaved as a standard function call and have my SaveStringToFile implementation call it directly?

View 1 Replies

Implementing Interfaces During VB To .NET Class Migration?

Jul 11, 2011

I'm migrating the CenterSnap.cls from its vb version to vb.NET and I'm confused about the following 2 errors after I import the vb6 project to VS 2008.

[Code]...

View 1 Replies

Implementing Singleton In Parent Class?

Nov 18, 2009

implement singleton in a parent class. Infact what I want is that All the childs etc. should use same instance of the parent.

I have implemented singleton, Changed the scope of parent class's constructor to "Protected". But in the application when ever the new child's constructor is called i.e. "Dim abc as New Ch1()" the constructor of Parent is called (as it is Proctected and can be access from child). Which is undesired behaviour.

View 2 Replies

Errors On Class When Implementing A Specific Interface

Feb 3, 2011

In some DLL, I have an interface defined like this (shortened code):

Public Interface wsIInvoice
''' <summary>
''' Perform plugin specific actions for a given memberhip invoice that is processedin an incasso batch, and return success result.

[Code].....

The DLL implementing the interface has a reference to the one defining it. And the defining DLL is imported.

I'm doing exactly the same thing in another DLL, and there VS does not complain.

View 2 Replies

Forms :: VB With Implementing A Class In Form Code?

May 8, 2009

I am having trouble with this project I am working on. I am a beginner to vb and have some background in access databases. I will attach my am doing an inventory project. When you execute the form, a main form pops up that allows you to choose Production or Inventory. My issue is with the Production. In the production form that pops up after clicking Production, there are text boxes to be filled out by the user based on the production run.plementing a class that will give the box count based on the box type entered. I have to use a class based on the project requirements.

Basically to calculate the usage, enter in a random number for Pods Produced, then enter in a box type (which is A box, B box, C box, D box, Master Case). I want the Public Class Box Count in the code to be able to be placed in the production form's main class code and calculate the box count based on the box type entered. If A box, box count should be 50. If B Box, box count should be 100, If any other box is typed in, the box count should be 150

View 4 Replies

Implementing Cell Class That Has Value Property Of Different Types

Jan 27, 2010

I am trying to design a table type structure that contains rows and cells. I intend the cell class to have a value property. I'm trying to work out how I can create a value that can return some defined different types e.g integer, single, date, string. I'd like the cell value to be strongly typed, but I am unsure how best to get this working.

My thinking in code so far:
Public Class Cell
Private _value as object
Public Property Value as Object // How can I define this so that it return a Type
Get // e.g. integer, string, etc
Return _value
[Code] .....

View 1 Replies

Interfaces - Implementing Interface For Multiple Class

Oct 21, 2009

I'm dealing a problem in implementing interface for multiple class.

Assuming I have a class named Class Unu .

I created an interface called Test for those 2 classes.

The first class Unu has 2 data members(i=12 and j=12.17). When you run the program it stores the result on screen 24.17

The second class called Doi has 2 data members(a=20 and b=32.17).

What I want now is to do the same thing for data members a and b so that it stores on screen 20+32.17=52.17

My problem is that I want to be displayed also the result for the 2 data members for the second class on my screen. I implemented the interface on class Doi but I cannot see why he isn't displaying me the second result 52.17.

What I must add to my code to do that?

Here's the full code:

CODE:

View 6 Replies

Does Dispose(disposing As Boolean) Need Implementing For Every Class In A Chain

May 9, 2012

I'm trying to work out whether every Class in an Inheritance chain needs an explicit Dispose(disposing As Boolean) method or, if a given Class has neither managed nor unmanaged resources to dispose of, it can be skipped for that Class - even if a latterClass does require a Dispose method to dispose of mananaged or unmnaged resources?

Here's two examples:
Public Class BaseClass
Inherits Component 'Component has already implemented IDisposable

[code]....

View 15 Replies

How To Auto-insert A Code Snippet When Implementing Interface Like When Implementing IDisposable

Aug 10, 2010

Is it possible to automatically insert a Code Snippet when an interface is implemented? If so, how do you do it? I am looking for something similar to when you implement IDispoable in VB.[code]This will be used by web forms when transfering parameters from one page to the next using Server.Transfer

View 1 Replies

Have A Dynamic URL In Generic Class?

Apr 22, 2009

I need to have a dynamic URL preferably from a Test Classformatting this design pattern to handle dynamic links from tests. instead of a constant HomePageURL.

Namespace TestDesign
Public Class HomePage
Inherits IE

[code].....

View 1 Replies

Recognize A Generic Class?

Mar 19, 2010

How can I recognize (.NET 2) a generic class?

Class A(Of T)
End Class
' not work '
If TypeOf myObject Is A Then

View 2 Replies

Inherit From A Generic Class Without Specifying A Type?

Apr 29, 2009

I have the following sample code in a VB.NET console application. It compiles and works, but feels like a hack. Is there a way to define EmptyChild so that it inherits from Intermediate(Of T As Class) without using the dummy EmptyClass?

Module Module1
Sub Main()
Dim Child1 = New RealChild()[code].....

The other way to do this would be to move the generic code out of the Base class and then create 2 Intermediate classes like this [code]...

Then RealChild would inherit from the generic Intermediate and EmptyChild would inherit from the non-generic Intermediate. My problem with that solution is that the Base class is in a separate assembly and I need to keep the code that handles the generic type in that assembly. And there is functionality in the Intermediate class that does not belong in the assembly with the Base class.

View 1 Replies

Add Custom Class To A Generic List?

May 10, 2010

I created two classes. One class is StudentClass and the other is HomeroomClass. The HomeroomClass contains a readonly property as a generic list of the StudentClass. [code]...

View 6 Replies

C# - Create A Generic Method In A Class?

Apr 28, 2010

I am really trying to follow the DRY principle. I have a sub that looks like this?

Private Sub DoSupplyModel
OutputLine("ITEM SUMMARIES")
Dim ItemSumms As New SupplyModel.ItemSummaries(_currentSupplyModel, _excelRows)
ItemSumms.FillRows()

[Code]...

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

Generic Class's Constructors With Param

Dec 30, 2009

i've got a Class like this public Class Cart(Of Item) Public Sub New(ByVal a As Integer, ByVal ParamArray items As Item())but i do not see how to create an instance of it: Dim block_names As New Cart(Of String, 5I)i get something like "type expected" o.O

View 2 Replies

Generic Error Handling Class?

Jan 10, 2012

We are developing an application for our shop floor. This program will be tracking material through the shop and we need to capture any errors the program generates, but we don't need to stop the program for all errors. I have some code to do a screen capture and put it in a database with exception.tostring data for debugging.

What we would like to do, is create an exception from the base class, but provide additional properties to allow us to set a severity and a user friendly error message. I would like to encapsulate this in a class that we would call in the catch of a try/catch, set the properties on the class, have the class record the data to the database, then raise the exception to the main program to display only the user friendly message and severity. The main program would then determine the severity and based on the severity stop the program or just display a discreet msg and continue to process.

Does anyone have an example of a custom exception class derived from exception that does something similar, or if I heading in the wrong direction, does anyone have a better solution?

View 5 Replies

Generic Inherited Class Definition

Jan 11, 2010

I'm having trouble with the definition of an inherited generic class. I have two base classes that are defined like this:[code]

View 2 Replies







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