Specifying Inherits / Implements On Generic Class With Multi-Constraints

Jun 7, 2010

When I write the following statement in VB.Net (C# is my normal language), I get an "end of statement expected" referring to the "Implements" statement.
<Serializable()> _
<XmlSchemaProvider("EtgSchema")> _
Public Class SerializeableEntity(Of T As {Class, ISerializable, New}) _
Implements IXmlSerializable, ISerializable
...
End Class

The C# version that I'm trying to emulate is:
[Serializable]
[XmlSchemaProvider("MySchema")]
public class SerializableEntity<T> : IXmlSerializable, ISerializable where T : class, new()
{
....
}

View 1 Replies


ADVERTISEMENT

.NET Class Inherits A Base Class And Implements An Interface (works In C#)?

Apr 9, 2010

I am trying to create a class in VB.NET which inherits a base abstract class and also implements an interface. The interface declares a string property called Description. The base class contains a string property called Description. The main class inherits the base class and implements the interface. The existence of the Description property in the base class fulfills the interface requirements. This works fine in C# but causes issues in VB.NET.

[Code]...

View 5 Replies

.NET Generic Constraints And Subclasses?

Sep 17, 2010

Consider the following extension method:

<Extension()> _
Public Function Satisfies(Of T)(ByVal subject As T, ByVal specification As ISpecification(Of T)) As Boolean
Return specification.IsSatisfiedBy(subject)
End Function

This works as expected if subject is the exact class being operated on by the specification. However, if the specification is examining the super-class of T, this extension will not work unless subject is explicitly cast to the super-class. Is there a way I can avoid this? So far, the best I've been able to come up with is:

[Code]...

Since I (apparently) can't get this to work exactly as I'd like in VB.NET due to limitations in the language itself, is my second attempt the safest/most efficient way to do this?

View 2 Replies

Generic Constraints That Allow Type To Be 2 Different Classes?

Mar 21, 2012

I have a generic function in VB.Net. I also have two classes called A and B. Is it possible to allow the generic constraints on my function to allow the Type to be either class A or B? Class A and B do not share any base classes except for object.

View 1 Replies

Use Generic Constraints Based On Attributes Rather Than Types?

Aug 28, 2009

I'm trying to write a class that will be in charge of persisting application options. Since the options need to be persisted the values that I'm sent must be serialisable.

Initially I thought I've be able to write a method with a signature like this[code]...

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

Create A Generic Dictionary That Implements IXmlSerializable ?

Apr 19, 2010

I was trying to create a generic Dictionary that implements IXmlSerializable (credit to Charles Feduke).

Here is my trial:

Sub Main()
Dim z As New SerializableDictionary(Of String, String)
z.Add("asdf", "asd")

[Code].....

View 2 Replies

.net - Multi-level Inheritance With Implements On Properties?

Jun 18, 2010

Let's say I have 2 interfaces defined like so:

public interface ISkuItem
{
public string SKU { get; set; }
}

[Code]....

VB.NET explicitly requires you to add Implements IInterfaceName.PropertyName after each property that gets implemented whereas C# simply uses regions to indicate which properties and methods belong to the interface.

Interestingly in VB.NET, on the SKU property, I can specify either Implements ISkuItem.SKU or Implements ICartItem.SKU. Although the template built by VS defaults to ISkuItem, I can also specify ICartItem if I want. Oddly, because C# only uses regions to block out inherited properties, it seems that I can't explicitly specify the implementing interface of SKU in C# like I can in VB.NET.

My question is: Is there any importance behind being able to specify one interface or another to implement properites in VB.NET, and if so, is there a way to mimic this functionality in C#? Furthermore, what is the effect of specifying one interface over another when implementing properites?

View 3 Replies

Create A New Class That Inherits From The Base Form Class And Define A New() Method With Parameters?

Oct 1, 2008

I've been creating short test apps repeatedly to try to understand some of the concepts in VB.NET.For the most part it has been illuminating.I read Bucky's .NET knowlegebase tutorial on passing objects as parameters to newly created forms. He shows how to create a new class that inherits from the base form class and define a New() method with parameters Extending the concept I thought about doing the same thing with a form that was created at design-time (In this case Form2).

[Code]...

View 6 Replies

Class C Inherits Class D Is Class D A Superclass Or Parent Of Class C?

Dec 16, 2009

If Class X is within the scope of Class Y, is X a subclass of Y?If Class A is a sub Class of B, then is Class B considered a super class of A?if Class C inherits Class D is Class D a superclass or parent of Class C?if Class E extends Class F then we can consider Class E a child of F?if Class G inherits Class H and is within the scope of Class I then who is the parent of Class G? Classes that inherits Class J and classes that are within Class J are all sub classes of Class J?

View 1 Replies

Class That Inherits Another Class In Which There Are Objects That Are Disposed In Dispose Procedure

Feb 14, 2010

If I have a class that inherits another class in which there are objects that are disposed in the dispose() procedure, do I use mybase.dispose? ex Class A inherits Class B. [code]

View 2 Replies

Visual Studio 2010 - Failed To Enable Constraints - One Or More Rows Contain Values Violating Non-null - Unique - Or Foreign-key Constraints. Error

Dec 9, 2011

There were three similar questions in StackOverFlow but none gave an answer.. If have found why this error in occurring but don't know the fix. I am using Strongly Typed Dataset for my project which is created as a dll for DAL. I have added the Sql Server Table into this dataset using the designer and has created a DataAdapter

[Code]...

View 1 Replies

Tell If A Class Implements An Interface?

Dec 4, 2009

I've got a web user control (.ascx) which implements a couple of interfaces I wrote; namely IXMLBoundControl and ISectionOverridingControl.I've written a mini-CMS type application that dynamically loads controls onto the page based on information in a database. When I click a button on a web page (.aspx), I want to look at all the controls on that page, and determine if there is a control which implements the ISectionOverridingControl.

I've got my loop and I'm looping through the controls; that's fine. However I'm not sure what the best way is to determine whether or not the control implements the interface. What I'm doing at the moment (and works) is to try to cast each control into the ISectionOverridingControl and catching InvalidCastException: If I don't get the catch; I consider it's worked. If the exception is thrown then it doesn't implement the interface.

It's working, however, I consider this inefficient (relying on exceptions): surely there's a better way in VB.NET (I've seen an example in C# but it didn't convert to VB) to tell whether an instance of a class implements an interface or not?

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

Assign To Variable If Inherits From Class .NET 2.0

Mar 31, 2009

I think I remember reading somewhere that it was possible to assign items to a variable if the item inherited from a base class, but I can't remember how.

I want to have a class that gets properties set and one of the properties is an error code property. I want to assign any exceptions that occur to the property, but it could be any type of exception. I remember that all exceptions inherit from the Exception class.

How can I assign an exception to a property based on the class it inherits from?

View 4 Replies

How To Prepopulate A Class That Inherits Combobox

Sep 24, 2010

I'm extending the ComboBox class in VB.NET and I'm running into a problem prepopulating the collection. I try to do so by using Me.Items.Add() calls in the New() sub. However, once I place the control on a form in the form designer, Visual Studio automatically adds those items to the collection in form designer, then they are added again at runtime. How can I make them only added once?

View 1 Replies

VS 2010 Class That Inherits From Picturebox

Apr 5, 2012

I have a class that inherits from the picturebox class, is represents a gauge. In that class I have an overriden function : [code]and I have on my screen what I expected. But in my form I have a timer that generates a new value for the gauge.[code]For some reason the refresh doesn't work. The gauge doesn't change, the overriden onpaint doesn't get triggerd again. anybody has any idea why?

View 12 Replies

[02/03] Base Class Called PageBase And Then A Derived Class TestPage That Inherits From PageBase

Feb 4, 2009

I have a base class called PageBase and then a derived class TestPage that inherits from PageBase. In PageBase I have overridden the OnInit() and when it is called and I inspect the value of 'Me', it is of the type of the derived class and not the base class. My question is how does inheritance really work? For instance, when instantiating TestPage does an instance of PageBase get created too?

Here is my code;

Partial Public Class TestPage
Inherits PageBase

Public Sub New()

[code]...

View 7 Replies

Require That A Class Is A Windows.Forms.Control And Implements An Interface?

Nov 29, 2011

I'm not sure that I'm doing the right thing here..I'm writing a user control that's supposed to be (fairly) generic. It's a bit like a modified email client specifically tailored to some of the internal things we do.

The view is composed of two main pieces, a message list and a viewer. I need this viewer to be interchangeable, so if someone wants a different style of view they can simply handle an event and change a property. My original idea was to just have an INoteViewer, but since I'm adding it to my form I also need to guarantee that this object is a Windows.Forms.Control of some sort.

Should I continue along these lines and maybe raise an ArgumentException if I can't cast it to INoteViewer, or should I go a different direction and create a class that inherits from Windows.Forms.Control?

View 2 Replies

System.Data.Linq.Table(Of X) Cannot Hold Class That Implements X

Dec 15, 2010

I have an interface 'ICRUDable' and a class called ClientAddress which implements the ICRUDable interface.

My understanding of OOP would lead me to believe that if I declare a System.Data.Linq.Table(Of ICRUDable) then I should be able to put ClientAddress's in there.

The code I have tried includes;

Dim dc As New CRMDataContext
Dim items = dc.ClientAddresses
and

[Code]....

View 6 Replies

How To Store An Instance Of A Class Which Inherits From NameObjectCollectionBase In Settings

Nov 30, 2010

I have created 3 classes which inherits from(System.Collections.Specialized.NameObjectCollectionBase)

The first class "SQLCommandsCollection" stores "SQLCommands" in a collection.

The second class "SQLTableNamesCollection" stores "SQLCommandsCollection" objects in its collection.The Third class "SQLDBNamesCollection" stores "SQLTableNamesCollection" objects in its collection.

Ultimately I will sit with a "SQLDBNamesCollection" collection which contains all Table names and its respective SQLCommand objects.

I would like to store this "SQLDBNamesCollection" object in my.settings("QueryViewerQueriesPerTableNamePerDBName")
at runtime but I am unsure what this settings type should be.

I have tried system.oject but this does not seem to work as I get an "Unable to cast object of type 'System.String' to type 'Fusion.SQLTableNamesCollection'" exception when I try to retrieve from settings. See below code.

[Code]...

View 6 Replies

Transparencies - Quickly Made Up A Class That Inherits Listboxes And Uses

Aug 10, 2010

I have quickly made up a class that inherits listboxes and uses

[Code]...

View 4 Replies

C# - Make Sure That The Class Defined In This Code File Matches The 'inherits' Attribute?

May 28, 2012

Sometimes in my web applications I used to get this sort of error, I have no clue why is it coming however if I refresh the page few times the page is loading normally.I am using .net framework 2.0 and visual web developer 2005.

View 1 Replies

Code Running In Class Inherits From ServiceBase Doesn't Have Have Credentials Of Logged In User?

Jul 9, 2010

I have a window service that Inherits System.ServiceProcess.ServiceBase. While running in debug mode (havent tested compiled), the thread does not see the current user credentials. I need the credentials so I can set up the WebProxy and I would prefer to use the account that service is running under instead of passing the user and pwd as a string.Can someone help me figure out why the code running in the class the inherits from ServiceBase does not have have the credentials of the logged in user?

View 1 Replies

Multi-constraint Generic Function Calls Actually Work?

Jan 8, 2011

In vb.net, it is possible to design a function which can operate on generic parameters which meet multiple constraints. For example, it is possible to have a function accept as a parameter a class which inherits from Control and implements IList. This function could use "Control" or "IList" methods on such an object, and also pass the object to anything that expected a Control or an IList [note that this particular combination was chosen to facilitate a brief example, not to be a particularly useful combination].

[Code]...

This approach provides compile-time type-safety; there's no need for a cast that could fail at runtime. An alternative approach would be to pass the argument as either a Control or an IList, and have the function cast to the other. That would, however, fail at runtime if the object that was passed didn't in fact meet both constraints.

Under what circumstances is it good to use a generic function like the above, in what cases would it be better to have objects which are going to meet both constraints have a new interface like IListableControl(Of T) which would include a TheControl property that would return itself (cast as a control), and in what cases would it be better to have a generic ISelf(of T) interface, any implementor of which would be expected to provide a "Self" property that would return itself as a T?

Using multi-constrained generics, it's possible to do a lot of things without requiring any run-time typecasts, but I don't know what the performance costs are likely to be. I tried writing a short program to generate 65,536 different generic types at run-time, e.g. Foo(of Bar(Of Foo(Of Foo(Of Bar(Of Foo(...(Of Blah)) and it got pretty slow, so I can tell that the time required to handle generics isn't fixed, but I don't know what factors affect it.

View 1 Replies

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

VS 2008 Serialize A Class That Implements An Event That Don't Want To Serialize?

Aug 17, 2010

If a class is serialized and has events fired from it that are handled on a form you get the error "Form1 cannot be serialized" in c# you can use (to work around this):

[Code]....

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







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