Extending Classes: Adding Shared Procedures?

Nov 2, 2009

is there anyway we could extend a shared function for a class? example:

<Extension()> Public Shared Function GetName(ByRef e As [Enum], ByVal value As Object) As String
Return [Enum].GetName(e.GetType, value)

[Code].....

however i dun hav a choice as Extension methods can be declared only within modules

View 21 Replies


ADVERTISEMENT

.net - Extending Web Service Proxy Classes?

Jul 28, 2011

I need to add functionality to my web service calls so object translation and automatic retries are done and abstracted away.I would usually override the base class to add the extra functionality, but as the proxy methods aren't over-ridable I can't keep the method names the same. The only other option I can think of to do it this way is to use the 'Shadows' keyword to achieve what I want.What other methods do people use to add functionality to their web service proxy classes without modifying the generated classes?

View 1 Replies

Inheritance In Classes And Extending Subs ?

Feb 26, 2011

I've been wondering if there is anyway to extend a sub of a base class in a derived class or subclass. To date, the only thing I've been able to find is overrides and overloads functions, but to my understanding these functions just ignore your base class's sub and just allows you to run the new one with the same name.

What I want to be able to do is:

CODE:

I'm not sure whether this is possible, or if I'd simply either make a new sub in my derived class that first ran the base's class sub or whether I'd override the base class and then copy and paste the old code.

View 6 Replies

VS 2008 Extending Sealed Classes?

Apr 1, 2010

Briefly, what I'm trying to do is add some methods and properties to the FileInfo class, which is sealed (NotInheritable). As far as I can tell, I have two options to do this.

1) Inherit from FileSystemInfo (the base class for FileInfo) and recreate the methods and properties added by FileInfo (essentially recreating the FileInfo class from scratch)

2) Use extension methods (??) which I just learned about two minutes ago and it being 1am, I'm going to get into this tomorrow

3) Create a wrapper class around a FileInfo object - I think that's the proper term

Ok, so I guess there are 3 options.

A) Why make a class uninheritable

B) Is creating a wrapper class "basically" the same as inheriting from an object, but at least with inheritence you don't need to create any properties and methods other than those you want to modify or add?

Am I correct when I say that a Field is a protected property that can only be accessed by the base class and inherited classes, or is the definition of a field something else?

View 2 Replies

Interfaces, Type Identity, Extending .net Native Classes?

Jun 18, 2010

So in a lot of frameworks there is usually some base type that you tend to extend a lot because well, it is what enables the "visual" aspect of the framework. Here in .Net it's the Control/Form... you tend to be inheriting these frequently for different things, and despite the suggestions otherwise, the team always agrees to extend explicitly and forget about composition.So now say you want to create some relationship between all of these... just a simple interface that uncovers some basic properties that all your forms and controls should have. In this case lets call it 'IProjControl'

Code:
Public Interface IProjControl
Property ProjControlId() As String

[code]....

So this interface is something you expect all your windows and dialog boxes and other some other controls implement. They all don't extend the same exact type, they all just happen to be controls.In there lies the problem... you want to enforce the contract with this interface that not only is it a 'IProjControl', but it's also a 'Control'. But we can't exactly have our interface extend Control (that doesn't make sense), and there isn't an 'IControl' interface to require implementing.

So the method I've always used is something like this:

Code:
Public Interface IProjControl
ReadOnly Property ProjControlComponent() As Control
Property ProjControlId() As String

[code]....

(if there is actually a language/compiler specific feature that allows you to require an interface implementation to be implemented by a class extending a specific type... please, do tell... but I highly doubt there is because for all intensive purposes that sounds weird).

View 12 Replies

Testing UserControls, Classes, Procedures?

Jun 8, 2010

Can we make a test if a user control, classs, or procedure is working properly without running the whole program?Im testing a user control behaivor but its parent window located deep in the program, is there any way running a control for testing purposes only? im starting to get annoyed by running my whole program to test a user control just to find out that its not

View 1 Replies

.net - ASP.net: Extending Or Adding Pieces To Existing BoundField

Nov 5, 2010

Is it possible to add a property to the existing asp:BoundField control without creating a brand new instance to which I'd have to declare <tst:BoundField></tst:BoundField>?

View 1 Replies

Asp.net - How Are Classes Shared Between Projects In The Same Solution

Jan 29, 2011

Currently, I have a solution that contains two projects (ASP.net websites, FWIW). If I create a class in Project1, how do I expose it to Project2? Is it automatically available to Project2 because they are in the same solution? Or do I need to do something special to make the connection?

View 5 Replies

Shared (Static) Classes With Events In C#

Mar 27, 2010

[code]Now how do i do this in c#. I know there is not handles clause in c# so i need some function that is called and assign the event handlers there. However since its a shared class there is no constructor i must put it somewhere outside of a function.

View 2 Replies

Shared Events In Child Classes

Jul 7, 2011

I have a program with a base class and classes that inherit the base. A Windows Form will call a function of each child class which raises an event from the base class. The function call to the first child class works fine: the event is raised for the first child class.

[Code]...

View 7 Replies

.net - Access Shared Members In Partial Classes

Feb 16, 2011

I'm writing a WCF-Service and I split up my service class to multiple partial class files, so every ServiceContract-Implementation gets its own file. I have one file however that should contain e.g. members that are used by every partial class file such as a logger. The service is hosted with IIS 7 if this matters in any way.

[Code]....

The code compiles fine, but at runtime I get an BC30451: The name m_Log is not declared Error (Don't know the exact words for it. I get a german message ;) ). I don't think it has something to do with the type of m_Log or a depending assembly because I get the same error if i try this with a String. What am I doing wrong? How can I make this work? Edit: I was trying the same thing in a simple console application without any problems. :(

View 1 Replies

Asp.net - How To Get Classes To Expose The Same Shared/Static Method

Mar 4, 2010

I have a base class with several derived classes. I want all of my derived classes to have the same Public Shared (static) method with their own implementation. How do I do this? Is it even possible?

View 3 Replies

C# - ASP.NET's App_Code Folder And Shared/Static Classes?

May 15, 2011

If I have a 'Shared' object defined in the App_Code folder; is that object shared amongst all users/visitors of my website? Or is it shared on a per-user basis?I don't know if that makes sense or not; but I've got a puzzle/solver I'd written earlier that I'm trying to incorporate into a simple ASP.Net site. It's probably poorly written, but I'd used a Shared boolean to determine if a solution had been found. The code works, now as an ASP.NET site, but if two visitors to my site were both validating their puzzle at the same time, would they both be accessing the same boolean?

View 3 Replies

Use Modules Instead Of Classes With Shared Member Functions?

May 19, 2009

Is it considered an acceptable practice to use Modules instead of Classes with Shared member functions in VB.Net?I tend to avoid Modules, because they feel like left over remains from VB6 and don't really seem to fit in anymore. On the other hand, there doesn't seem to be much difference between using a Module and a Class with only Shared members.

View 4 Replies

Declare A Variable To Be Shared By 2 Forms (classes) In The Same Project?

Jan 1, 2011

I've gone brain dead and can't remember how (where) to declare a variable to be shared by 2 forms (classes) in the same project.

View 2 Replies

VS 2005 Modules Vs Private Classes With Shared Members

Mar 28, 2011

I've read that modules are basically shared classes. For a module though, you can call a method directly without prefixing the module name. So I can do this: methodTest("abc", mod1Enum.enum2)But for a class with shared members I have to fully qualify the method call, and in this case fully qualify the enum:[code]In our conversion from VB6 to .NET the need to fully qualify all calls like this might be an argument for us to bring our VB6 modules over as modules instead of converting them to classes.

View 7 Replies

Create A Generic Shared Class That Can Operate On Predefined Classes

Jan 27, 2010

I have an interface that i have declared some of the basic internal functions, subs, properties, etc. This interface is then implemented into 3 pre-defined classes. These classes are end-use classes so they dont get derived or inherited elsewhere. I am trying to create a generic shared class that can operate on each of these 3 predefined classes and potentially more as long as they implement the interface.

[Code]...

View 10 Replies

Method To "override" Shared Members In Child Classes

Mar 5, 2010

At the moment I'm trying to create a kind of model in vb.net which can be used to create/fetch database entrys.

I created a main class Model with a shared function to fetch the datasets, e.g. Model.find(). Now I'd like to create Classes which inherit the main Model-Class, e.g. a separate one for users: UserModel.find() => "SELECT * FROM users".

What I need now is to find a way to tell the Class which table it should use. I thought about an abstract String "table" which is a constant in each "child-model", but how could this be implemented as it's not possible to override shared members?

Edit: Maybe this will make it a little clearer what I mean:

Public Class Model
Public Shared _controller As Controller
Public Shared table As String

[Code].....

So I want a shared method which finds all database entries and gives back an array of instances of its own type, e.g. Model(). That's why I wanted to keep the find-method shared and not bound to an instance.

View 4 Replies

Adding Operators To Classes?

Oct 7, 2009

Is it possible to define operators like addition, subtraction and such to classes? I'm trying to convert a vector class from C++

class CVector2
{
public:
float x, y

[Code].....

View 2 Replies

VS 2008 Adding Only Distinct Classes To Listbox

Apr 23, 2009

I have a List(Of SomeClass) containing a number of SomeClass items. SomeClass is just a small class with two properties, a Name string and an Int integer:

[Code]....

View 6 Replies

VS 2010 - Automatically Adding Namespaces To Classes Within Folders

Jul 26, 2010

Is it possible to have visual studio 2010 automatically add namespaces to classes within folders just like c#?

View 1 Replies

.net - Why Can't Call Private Shared Methods From A Public Shared Method

Aug 25, 2011

I have a class like this:

[Code]...

It works, when I make getBar methods public, but I don't want to expose these unneccessarily. Why I can't call private shared methods from a public one in the same class is over my head. I'm using .net framework 4.0 in a web application.

View 1 Replies

Asp.net - Public Shared Variable Shared Between Users?

Mar 30, 2012

I've taken over the maintenance of the website (ASP.NET VB) and on one particular page I noticed the below code

Inherits System.Web.UI.Page
Public Shared UserNumber As String
Private Sub Page_Init(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Init

[Code]....

My question is whether the variable UserNumber can be accessed or changed by any other user than the current one?

View 2 Replies

Shared Method Not Calling Shared Constructor

Aug 12, 2009

Given in the following language specification, for me at least, calling Db.Foobar() [In the following code] does not indeed call off to the Shared Constructors of the base classes. I am curious as to a) is this my own fault for doing something wrong or b) is this an error in the language specification[code]...

View 2 Replies

Use LINQ To Filter Collection Of Nested Classes To Yield Dictionary Of Unique Properties Of Those Classes?

Jan 23, 2012

I have two classes, one nested in the other. [code]Neither "Name" or "ID" are unique between operations and records.I wish to construct a dictionary using LINQ = Dictionary(Of String, Of List(Of Integer), whereby the keys are uniqe examples of Names in my collection and the values are the collective set of distinct IDs that are associated with those names.

View 2 Replies

VS 2010 Structure Classes So That The User Interfaces Though A Single Class While The Supporting Classes Are Hidden From Their View?

Jun 13, 2012

How can I structure my classes so that the user interfaces though a single class while the supporting classes are hidden from their view? I think its best understood in an example:

Public Class MyInterface
Public Economic as EconomicClass
Public Sub New()
MyBase.New()

[code].....

So you might ask why am I even separating them? It's strictly for others who will be working with this interface. I need to funnel them though a logical structure:

interface.Economic.MyMethod
interface.Currency.MyMethod
etc

This way everything is already handled for them in the background and they only need to run the method they need. I don't know if I can have it both ways in VB.NET.

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

Extending A Class By Namespace?

Mar 17, 2011

I have a class within a library, with no root namespace, firstone.dll:

namespace first
public partial class one
public sub fun()

[Code]....

Is there a way to extend the class in a separate dll and still have access to the original class? I don't want to inherit the class just extend it.

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

VS 2010 Extending DataGridView?

Aug 19, 2011

I would like to create a DataGridView that displays records that fill either 18 or 35 columns. I would like to avoid displaying all 35 columns for all records, instead showing the 17 extra columns on a second row for records that need them.How would I go about this? I'm guessing I need to create a new class that inherits from DataGridViewRow and override it's Paint or PaintCells method, but I have no experience with overriding Paint events, so I'm kind of lost after that.

View 8 Replies







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