.net - Extending ENUM Valus Inherited From Base Object?

Jun 14, 2010

If I defined a ENUM in a base object with serveral default values. When I inherit from the base object I want to add more options the the ENUM list which are specific to the inheriting object.

For example my base could have a ENUM called Direction with values:
None
ALL
Stop
Start

I create a new class call Compass which inherits the base class and what to add the following to the ENUM Direction. I create a new class call Navigation which inherits the base class and what to add the following to the ENUM Direction. So, In my inheriting class haow do I extend the ENUM.

View 1 Replies


ADVERTISEMENT

Passing Base Object Type When Using Inherited One?

Oct 8, 2010

I have a project that has mainly two objects, both inheriting from a base. Like this:

Public Class Vehicle
Property Model As String
Property Make As String[code].....

The above function doesn't work because myVehicle is a Vehicle, not a Truck.Is there a way I can pass around a Vehicle type and have the IDE know which type to use? Or am I completely missing a better way to do this?

View 5 Replies

VS 2010 Extending An Enum?

Jun 27, 2011

I know from .NET 3.5 onwards (or might be 3.0) we can use Exension Methods to add our own methods to any Type in the .NET Framework and this is very handy, but I'm wondering if it is possible to "extend" an Enum as well?

View 13 Replies

C# - Extending The Base Class?

Mar 5, 2010

When you create a webpage in ASP.net, the codebase inherits System.Web.UI.Page Now when I extend the page object to check for SessionExpired for example, I create a new class and inherit from system.web.ui.page, and overwrite some functions. The problem then is that on each page, I have to replace system.web.ui.page with my custompage class. Is there a way to extend a class by adding methods or modifying its methods directly (e.g. add the sessionExpired check to System.Web.UI.Page) ?I'm using .NET 2.0

View 2 Replies

Base Form And Inherited Other Forms From It - Don't See Those Changes Take Effect In My Inherited Forms?

Jun 24, 2010

I have a base form and I inherit other forms from it. However, if i go back and change say the size of the base form, I don't see those changes take effect in my inherited forms. Does anyone know why that is? Is there a solution to this issue?So as far as design is goes, what exactly gets inherited by other forms?

View 9 Replies

"upgrade" An Object To An Inherited Class, And Keep All The Base Class's Property Values?

Jul 5, 2010

bare with me during this silly example. :-) Let's say I have a class like this:

Public Class Animal
Public iLegs as int32 ' Number of legs
Public bWings as Boolean ' Wings? Yes/No
End Class

And another class that inherits the "Animal" class and adds one more property:

Public Class ScaryAnimal
Inherits Animal
Public iScariness as int32 ' 0-100, how scary is it?
End Class

Now, if I have an instance of "Animal" with some values in it, and I decide I want to cast it to a ScaryAnimal for some reason, how do I do that without having to create a new instance of "ScaryAnimal" and copy each property value?Basically I'm looking for a way to do this, without having to write the lines marked with '*** below:

[Code]...

View 2 Replies

Cast Inherited To Base Class?

May 19, 2010

The program below trhows an error in the line "mTable2 = mTable.Copy". The error is: "Unable to cast object of type 'System.Data.DataTable' to type InherintanceQuestion.InheritedTable". This is because mTables is an instance of the InheritedTable class which inherits a DataTable and mTable is a DataTable. So, is there any way I can create the mTable2 to the mTable.copy to the mTable.

Public Class Form1
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click

[code].....

View 2 Replies

Handling The Paint Event In The Base And Inherited Forms?

Sep 21, 2010

I have a form called BaseReportForm that handles drawing some stuff to in a panel to create a template for a bunch of reports. The drawing all takes place in the Panel's Paint event and this form will always be inherited. In the inherited forms, I draw the specific details of the report in the inherited form's Panel Paint event. So I am drawing to the same panel from the base form and from the inherited form. It all works fine, but when I try to open the design view for the inherited forms, I get the following error..

Quote:

The event Paint is read-only and cannot be changed.

I'm not sure I am handling my paint events correctly. Is there a different way I should be handling the drawing of these reports?

View 9 Replies

[2008] Base Class Inherited By 2 Derived Classes

Jan 30, 2009

i've finally got round to learning about classes and inheritance, but i'm not sure how to proceed. i have a base class Employee, which is inherited by 2 derived classes. how do i use the same Employee class in both derived classes? obviously if i write a sub new for both of them + declare a new Employee class, they won't be using the same class. heres my Employee class:

[Code]....

View 7 Replies

Get An Enum To Explicitly Cast To It's Base Type?

Mar 9, 2010

Is there a way to get an enum to explicitly cast to it's base type?If I have something like this:

Code:
Public Enum Packets As Byte
Stuff = &H0
End Enum

I have to do

Code:
Dim test As Byte = CByte(Packets.Stuff)

Rather than

Code:
Dim test As Byte = Packets.Stuff

I don't see why that's the way it works, since you know that the enum will always have values of the base type.

View 4 Replies

VS2008/VB: Moving Subclass VB Code To Inherited Base Class - Where Should Variables/objects Be Declared

Jun 3, 2009

In re-engineering a windows forms application, I find that a lot of code-behind in the various form classes is duplicative and I'm trying to centralize as many procedures as possible into a base class which can be inherited and used by the subclassed forms.

This process seems to be going well and is making the code in my subclasses much simpler and hopefully easier to maintain, but I'm not sure where to draw the line between leaving code in the subclasses and engineering for generic resusability and moving it to the base class.

Specifically, in some subclasses I have code which manipulates variables and objects specific to the subclass, and although I could move the code-behind into the base class, the base class code references specific objects which are needed to compile. For example, each subclass manipulates a databound datagridview and form detail controls which allows the user to select between multi-record and detailed single-record views of a datatable.

In Visual Basic 2008 do I need to declare dummy data objects in the base class so that the base class will compile? Or is there a way to indicate that the data objects will be provided by the subclass?

View 13 Replies

C# - Extending An Object And Any Child Collections?

Jul 30, 2009

I have an class named Foo. This class contains a collection of child objects of type FooChildBase, but I also have a further class of type FooChildTwo which inherits from FooChildBase.

Class Foo
Public Children As IList(Of FooChildBase)
End Class
Class FooChildBase

[code]....

What I would like to do is have my FooSpecial Class treat it's Children collection as if they were FooChildSpecial objects, but still be able to add FooChildTwo objects to it. Is this possible and if so how can it be done?

EDIT:I need to FooChildSpecial class to wrap any of the objects in the Children collection with the extra values, whether they are FooChildBase or FooChildTwo?

View 3 Replies

Flattening An Object Hierarchy Using A Shim Class - Initializing Derived Object Properties From The Base Object?

Jul 10, 2010

I am somewhat new to object oriented programming and am attempting to flatten a Linq object hierarchy by using a shim class.how to initalize a derived class with property values from a base class?I have two objects, a base object with about 100 properties, and a derived object which inherits from the base object and adds a few additional properties beyond those of the base object. My simple constructor creates the derived object, but I am looking for a way to initialize the derived object properties with values from the base object.Right now I am using reflection to iterate over the properties individually and I suspect there may be a better way. The following example shows my shim class constructor for the derived class, and two properties:

newProperty1 - a new string property of the derived class

flattenedProperty2 - a new string property of the derived class, copied from a 2nd-level object of the base class

Code example:

Public Class derivedObj
Inherits baseObj
Private _newProperty1 As String[code].......

Is this the correct constructor approach to flatten the object hierarchy using a shim class? My second question relates to initialization of properties in the derived class. The constructor above creates the derived object, but what is the best way to initialize the derived object properties with values from the base object? The following code uses reflection to iterate over the properties individually, but I suspect there may be a better way.

Code example:

' property names are in the string array fieldNames

'baseObjQuery is an ienumerable of baseObj

'derivedObjList is a list of derivedObj[code].....

Is there a simple way to initialize values for the properties in the derived object based upon the values of the common properties in the base object?

View 7 Replies

Create A Enum Or Enum Type Functionality Witch Return String (enum Returns Int) In .net

Dec 30, 2009

I have a URL lets say . some time i need to send HTTP and some time i need to send it to HTTPS for that i created a enum:

Private _protocol As Protocol

Enum Protocol
HTTP
HTTPS

[CODE]...

Now when i get value back from protocoltype it returns me integer value as enum do so tell me how to get string from enum or other substitute.

Dim targetUri As String = setting.protocolType & "://www.mysite.com"

View 1 Replies

LINQ To SQL: Reference The Data Context When Extending A Table Object?

Jul 27, 2009

If I'm extending OnCreated for a LINQ to SQL table object, is it possible to get a reference to the data context to which the table belongs? For example, if I add a property to the data context:

Partial Class MyDataContext
Private _myValue As String
Public ReadOnly Property MyValue As String

[Code].....

I don't want the property on the data context to be Shared, because it could be different per instance. I've been pouring over the designer code to figure out where the reference might be, but no luck yet.

View 3 Replies

Does An Inherited Class Automatically Implement An Interface From Its Base Class

Jun 10, 2011

Suppose I have piece of code like this:

Public Interface ISomething
....
End Interface

[code]....

View 2 Replies

Returning A Inherited Class As Base Class Type With Web Services?

Sep 25, 2009

I suspect I am being very silly here but I have the following setup

Class MustInherit myBaseClass
'some stuff
End Class
Class myInheritedClassA

[code]....

Running this results in the following error

Unhandled Exception: System.InvalidOperationException:
There was an error generating the XML document. --->
System.InvalidOperationException:

[code]....

is there any way of 'Widening' the inherited class to the base class so this would work?

EDIT:regarding XmlInclude(typeof inheritedClass), currently this method could potentially return a number of types of inherited class (i.e myInheritedClassA and myInheritedClassB) is it case of simply having to add each of the inheritedTypes in this tag?

View 2 Replies

Convert From Base Class To Inherited Class?

Jun 2, 2009

I understand that inherited classes can't be converted from base classes. But is there any way to write a conversion sub, so that the base class gets assigned to MyBase, then extra properties are added?[code]...

View 7 Replies

Change Property Of An Inherited Object

Oct 31, 2010

On form1 I put a picturebox from the toolbox.[code]Is it possible to set picturebox.visible=true of the inherited picturebox?

View 1 Replies

Object Aggregation Of Inherited Classes?

Oct 4, 2011

Object aggregation of inherited classes

View 3 Replies

Enum Item - Protected Name - Statement Cannot Appear Within An Enum Body

Mar 25, 2011

I'm trying to declare an enumeration and one of the names I'd like to use for an item is not usable apparently. Where I am declaring 'STEP = 3', I get this error message in visual studio: "Statement cannot appear within an Enum body. End of statement expected." Is it possible to use STEP as an item name somehow? [Code]

View 4 Replies

Get Base Class Object Reference Outside It's Definition?

Feb 13, 2012

If we are within the derived class then ofcource we can use MyBase keyword to access base class's object reference . That's fine , how can we take that base class's object reference outside that derived class's definition.

My following code will explain what i want . Actually that is giving error right now, but it is explaining my requirement .[code]...

View 6 Replies

ENum Names And Values Don't Match For Same ENum

Jan 2, 2012

RE - FilesystemRights Enum

This Code:

Dim FSRS As Type = GetType(FileSystemRights)
For Each fsr As String In [Enum].GetNames(FSRS)
TextBox1.AppendText(fsr.ToString & vbCrLf)
Next

View 3 Replies

Object Casting - TryCast Statement And Base Class

Jun 17, 2009

Here is a test program I wrote to explore a facet of object casting ...
Module Module1
Sub Main()
Dim class1 As MyBaseClass = New MyBaseClass()
Dim class2 As MyInheritedClass = New MyInheritedClass()
Dim class3 As MyBaseClass = Nothing
[Code] .....
The problem comes with the TryCast statement on class3. My intention is that class3 remains as a baseclass, but when the TryCast is applied, class3 morphs itself into an Inherited class which is not what I wanted. So is there a gap in my OOP/VB.NET knowledge and this action is legitimate or should class3 still be regarded as a base class?

View 6 Replies

.net - Getting Base Field Type When Databinding To A Decimal (or Object) Property?

May 28, 2012

I've got a custom NumericEditor control that has a nullable Decimal property called Value. When I bind a data field to Value, I'd like to retrieve the underlying Type of the data that's bound, so that I can restrict the use of decimal places if the source field is an integral data type.I figure I'd have to do this in the BindingContextChanged event, but how do I get the Type of the data field from the binding itself? My Google-Fu is failing me at the moment.

In short, I'm looking for something like the GetValueType method mentioned in the following question: Simple databinding - How to handle bound field/property change. Winforms, .Net I imagine this method would also be handy if the Value property was an Object.

View 2 Replies

Storing An Object That Implements Multiple Interfaces And Derives From A Certain Base (.net)

Dec 7, 2010

In .net, it's possible to use generics so that a function can accept arguments which support one or more interfaces and derive from a base type, even if there does not exist any single type from which all valid argument types derive. For example, one could say: Sub Foo(Of T As {IInterface1, IInterface2, SomeBaseType})(Param as T) And be allowed to pass any derivative of SomeBaseType which implements both IInterface1 and IInterface2. This will work even if SomeBaseType does not support Interface1 and Interface2, and classes which do implement those interfaces don't share any common ancestor that also implements them. This can be very convenient if one won't need to keep the parameter anywhere after the function has exited. Unfortunately, I can't figure out a way to persist the passed-in parameter in such a way that it can later be passed to a similar function, except perhaps by using Reflection. Is there any nice way of doing that?

The closest I've been able to come up with is to define an interface INest (perhaps not the best name-- thus:

Interface INest(Of Out T)
Function Nest() As T
End Interface

And for any interface that will be used in combination with others or with base-class "constraint", define a generic version as illustrated below:

Interface IFun1
' Any members of the interface go here, e.g. ...'
Sub DoFun1()

[CODE]...

A class which will support multiple interfaces should declare itself as implementing the generic ones, with itself as the type argument.

Class test123a
Inherits sampleBase
Implements IFun1(Of test123a), IFun2(Of test123a), IFun3(Of test123a)
End Class

If that is done, one can define a function argument or class variable that supports multiple constraints thusly: Dim SomeField as IFun1(Of IFun2(Of IFun3(Of sampleBase)))

And then assign to it any class derived from sampleBase, which implements those interfaces. SomeField will implement IFun1; SomeField.Nest will implement IFun2; SomeField.Nest.Nest will implement IFun3. Note that there's no requirement that IFun1, IFun2, IFun3, or sampleBase share any common derivation other than the generic interfaces inheriting from INest(Of T). Note also that, no matter how many INest-derived interfaces a class implements, it only needs to define one implementation of INest(Of T).Nest. Not exactly beautiful, but there are two nice things about it: (1) any concrete class which in fact implements the necessary interfaces can be assigned directly to a field declared as above, without a typecast; (2) while fields which chain the types in a different order are not assignment compatible, they may be typecast to each other. Is there any better way to store something in such a way that it's "known" to support multiple interfaces and derive from a certain base type? Given that one can write such code in a type-safe manner, it would seem like the .net 2.0 CLR could probably support such a thing quite nicely if compilers offered a little assistance.

View 1 Replies

Storing An Object That Implements Multiple Interfaces And Derives From A Certain Base (.net)?

Jan 24, 2012

I was looking through some legacy code we have and I noticed something that struck me as particularly odd.Say we have the concrete class TestClass. TestClass implements the interface ITestClass.What sort of behavior should I expect in the following case, then? (I didn't realize this was even possible)

Dim testClass as TestClass = Nothing
Try
testClass = New ITestClass

[code].....

View 1 Replies

C# - Invoking Private / Protected Methods Via Reflection From The Same Object Instance (or Base)

Jan 5, 2012

Is it possible to call a protected method via reflection. I am using this:

Me.GetType.InvokeMember(Stages(CurrentStage),
Reflection.BindingFlags.InvokeMethod,
Nothing,
Me,
Nothing)

Which always calls a method with no params or return. The idea is that the user of my object (transactional processing of business logic) inherits the base class adds in a load of private methods to fire. They then add these method names to a list in the order they would like them fired and the code above will take care of firing them.

It works fine with public methods but not with private or protected methods in the same class (Protected because I have some 'standard' pre built methods to add to the base class). Realistically I could make the methods public and be done with it but my inner nerd wont allow me to do so...

I am assuming this is a security feature. Is there a way to get around this or does anyone have any suggestions on how to proceed but keep my tasty, tasty visibility modifiers in tact?

(NOTE: ITS IN VB.NET but a C# Answer is fine if that is what you are comfortable with).

View 3 Replies

Deep Clone Of Object With Base Class System.Windows.Forms.Control

Apr 18, 2012

I have an object (a third component gridview) which is serializable, and I need a deep clone of this object. I have the following code which throws the exception."The type System.Windows.Forms.Control in assembly System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKey Token=b77a5c5 61934e089 is not serializable".So the gridview's base class is System.Windows.Forms.Control, which is not serializable. How can I get a deep clone from the gridview? [code]

View 5 Replies

Nullable Enum Verse Enum.None?

May 26, 2010

Which is better, using a nullable enum or adding the value None=0 to your enum list?Using nullables requires more code, but I kind of like it since it forces me to think about the possibility. Otherwise I'm liable to forget about the None enum and fail to account for it being a special case.

View 11 Replies







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