OOP - Shared Methods And Base Properties?

Feb 25, 2009

If you can't use Me. in a non-instance method, how would you use properties/functions from a base class in a Shared method?

For example, ClassB inherits from ClassA
ClassB has a Shared Method DoWork();
ClassA has a ReadOnly Property SecurityKey

How do I Public Sub DoWork() Dim test as String = Me.SecurityKey End Sub

View 5 Replies


ADVERTISEMENT

Use Derived Class Shared Variables In Shared Methods Of Base Class?

Jun 4, 2010

I am trying to add shared members in derived classes and use that values in base classes...

I have base

class DBLayer
public shared function GetDetail(byval UIN as integer)
dim StrSql = string.format("select * from {0} where uin = {1}", tablename, uin)
end function
end class

[Code]..

currently there is error using the tablename variable of derived class in base class but i want to use it i dun know other techniques if other solutions are better then u can post it or u can say how can i make it work? confused...

View 2 Replies

Can't Inherit Shared Properties From A Base Class In A Child Class?

Dec 29, 2010

This is another one of my "I think it's not possible but I need confirmation" questions.I have a base class for a bunch of child classes. Right now, this base class has a few common properties the children use, like Name. The base is an abstract class (MustInherit)Technically, this means that everytime a child class is instantiated, it lugs around, in memory, its own copy of Name. The thing is, Name is going to be a fixed value for all instances of a given child. I.e., Child1.Name will return "child_object1", and Child2.Name will return "child_object2".

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

Shared Methods In ASP.NET Sessions

Feb 25, 2011

As a followup to the previous question I have asked "ASP.Net Architecture Specific to Shared/Static functions" I am still struggling to understand the implications of using shared methods in ASP.NET.

So for example let us take the following code.[code...]

View 3 Replies

Application Wide Shared Methods

Jul 26, 2011

I am developing an application that has multiple forms and I wanted to know the best method to have application wide methods and functions. Currently I am using a Module with all my methods that are needed to be used across the entire application in it. However, I read at one point that modules should not be used, as they are only there to preserve backwards compatibility with older VB code. Is there a better way to have methods able to be called anywhere?

View 1 Replies

C# - Static (Shared In VB) Or Normal Methods

Oct 27, 2009

I Want to know which one is preferred while coding to use Static Methods or normal instances, I prefer to use static if they where few but if there was many of them I start to get some doubts

[code]...

if the EmployeeManager Has Many methods (selects deletes updates) is it ok to make them all static.and if it was Normal instance. wouldn't be a drawback if the object is initiated every time specially if GetAllEmployees() is heavily used.What is the better approach to use?

View 3 Replies

Calling Private Shared Methods?

Aug 8, 2011

I have a form (frmMain) that contains a custom control (con class). frmMain contains a combo box control and when the user selects a value from it, I pass this value to a sub routine within con class (see red line below). This purpose of the sub routine is to populate a set of comboxes contained in con class according to the value that is passed in.

Private Sub cboGuidelines_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cboGuidelines.SelectedIndexChanged
If bChanged = True Then

[code].....

View 6 Replies

Derived Class Shared Methods?

Nov 3, 2010

I have a function that 2 derived classes use, but the third doesn't, would it make sense to just leave it in the base class, even though one of the 3 derived classes doesn't use it?The only way I could think of disallowing the third class is to basically create an intermediate class that is derived of the base, then the 2 that use the common function are derived off the second class.

Is it possible to prevent the 3rd class from using the function, while letting the two that are supposed to use it, use it?Does that just seem to go overboard, I mean as long as I don't "try" to call the function from the 3rd class, it shouldn't be a problem, I just was interested if there was a way to prevent it all together without a lot of hassle.

View 2 Replies

Shared Class With Generic Methods?

Jan 28, 2010

I have created a Interface and a couple classes that implement this Interface. I am in the process of developing a Shared Class that utilizes the functions that each of the individual classes have, due to the interface implementation.What i need to know is how do i develop this Shared Class so that way each of the methods within it are restricted to a single data type. This single data type needs to be restricted to any class that has implemented the Interface.

Some examples:

Public Interface IVector(Of T)
Sub Add(ByVal v2 as T)

[code]....

As you can see it would allow me to develop one form, since i have standardized the required Subs/Functions for any class the implements the IVector interface. As i am still in developement, i was wondering if my current understanding of the method generics is correct in its current form or what i would have to do to make the Generic Shared Class work in the fashion that i am looking for in the example implementation.

View 6 Replies

Subclassing Object With Shared Methods

Aug 3, 2009

I want to create a subclass of a class that has some shared methods. These shared methods all call one specific method. But I can't redefine that specific method in the subclass. If I try to make it overridable in the parent class, it says that shared and overridable can't both be used.

[Code]...

View 5 Replies

More Specific Type From Base Shared Constructor?

Nov 26, 2010

How do I get using reflection the most generic type from a shared constructor in the base class :

Public Class Foo()
Shared Sub New()
'Here we have code to get the type[code]....

I expect the result to be Bar type and not the Foo. Is it possible?

View 1 Replies

Anything Wrong With Using Lots Of Shared Methods And Objects

Jul 9, 2009

I seem to find more and more that I declare a lot of objects or methods as Shared now but it feels like I am not doing things properly.I try to avoid doing this but then I just end up with situations where I have to create an instance of a class just to call one method that would act no differently if it was just a shared method.Basically I'm just wanting to know if there is any good reason to avoid using Shared objects/methods. Obviously I dont declare EVERYTHING as shared, but it just seems to make things a lot simpler most of the time.For example in my current project (a chat application using WCF) I have a class just called Core which houses a lot of the main functions of the client program, so it has methods such as: SignUserIn, SignUserOut, SendMessage, MessageReceived etc and it also holds properties such as a list that contains all of the currently online users. These things are all declared Shared in my program because as far as I can see there is no reason for having to do this:[code]

View 15 Replies

Calling Shared Methods From .NET Class Library In VB6

Jan 25, 2010

I have the following class in a .NET class library:

Code:
Public Class JasonTest
Sub New()
End Sub

[Code]....

The .AddNumbers call works fine, but the AddStrings call yields the error 'Object doesn't support this property or method'.

Is there any way to call a shared method from .NET in VB6? I was unable to find any documentation on this.

View 5 Replies

Dynamic Assembly Loading And Using 'Shared' Methods?

Dec 20, 2011

I now have a need to dynamically load a dll into my application and I've found the reflection/assembly information and it's fairly easy to implement so I thought I was on my way. However, I quickly found out that I'm only able to use 'shared' methods. What I was originally thinking was I could have one shared method 'library.beginprocess' and then that would make all the necessary calls to the other methods, but this doesn't work unless all the other methods and class level objects are also shared.

I feel like I'm missing something or somethings just going right over my head. I've looked at many, many sites and examples, but I've only run across examples that expose 1 method,[URL]..which explain how to implement a plugin architechture, which I have not tried yet, but maybe would allow me to keep my class structure the same without having to make everything shared?

View 14 Replies

Overload Shared Methods On Non-instance Types Using Extensions?

May 14, 2012

I want to extend the BitConverter class with an overload of ToString() that takes a parameter of type Char, representing a value delimiter.Why? By default, the ToString() call returns a string representation of a byte array, delimited by dash symbols. The signature does not allow you to specify a different delimiter, which I find very unfortunate.Now because this is not an instance type, or maybe because I'm overloading a shared method, I'm having a hard time finding the proper syntax to define my extension method.What am I doing wrong here, causing the overloads to not show up in IntelliSense:

Imports System.Runtime.CompilerServices
Module BitConverterExtensions
<Extension()>

[code].....

View 1 Replies

Passing Parameters By Reference Into Public Shared Methods

Oct 21, 2009

I have a List(Of AddlInfo) with AddlInfo being an object. I'm trying to pass addlInfoList by reference into a function of another class:

[Code]...

This works if I'm not passing the reference into another class, but when I try to do this, I get the following error: Overload resolution failed because no accessible 'Sort' can be called with these arguments:

[Code]...

View 1 Replies

Purpose Of Using Shared Methods That Return An Instance Of A Class?

Oct 11, 2010

What is the purpose of using shared methods that return an instance of a class, as opposed to a constructor?

ie: in VB.net, the system.drawing.color class has shared method "FromArgb(int, int, int) as color". This is different from java's implementation which simply is a constructor that takes three ints. Why the decision to do one or the other?

View 1 Replies

Will Modifying Shared Methods Change The Class That Reference Them

Jun 4, 2011

I'm wondering what will actually change a class, in the sense that serialized objects of this class will no longer be recognized. If the class has reference to shared methods of another class. Will changing such shared methods also change the classes that reference them?

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

Base Class With Shared Fields And Functions Good Design ?

Apr 22, 2010

I've got a BaseDataClass with shared fields and functions

CODE:

I have several classes that derive from this base class. The derived classes have all Shared functions that can be called directly from the BLL with no instantiation. The functions in these derived classes call the base Init(), call their specific stored procs, call the base CleanAll() and then return the results.

So if I have 5 derived classes with 10 functions each, totaling 50 possible function calls, since they are all Shared, the CLR only calls one at a time, right? All calls are queued to wait until each Shared function completes.

Is there a better design with having Shared functions in your DAL and still have base class functions? Or since I have a base class, is it better to move towards instance methods within the DAL?

View 1 Replies

Mimic An Interface / Contract For Shared Methods In A Class For Use By Generics?

Nov 15, 2010

So I implemented my own form of Enum static classes so I can associate strings to enumeration values. One of the shared functions in each enum class, GetValue, is used to quickly look up the string value from an internal array via the offset. While all of the enum classes implement the same exact function, the data types of their parameters differ, specific to the enums in each class.

So I come to a point where I want to create a generic class that can use any of the enums by passing it as a generic type parameter. But I cannot find a way to constrain type T in such a way to be able to call each enum's GetValue function. This is where an interface would come in handy, but VB.NET forbids interfaces for shared methods.

I have a base class that I could constrain to, but the base class doesn't implement the GetValue method, and I can't define a generic version of it, because I need to rely on shared properties of each child class in order for GetValue to do its thing.[code]..

View 2 Replies

.net - Invoking COM Properties And Methods

Nov 22, 2010

I am trying to dynamically create COM object, call COM method and set COM properties. The COM class is a VB6 ActiveX DLL. The implementation is exactly equal to the VB6 code from this page

[Code]...

View 1 Replies

.net - Class Definition Properties Or Methods?

Aug 4, 2010

I have a class definition that I've seen other define properties that return collections of objects.

Public Property GetAllAdults() as Adults End Property I made the argument that this should be a method in the class, because it doesn't define an attribute of the class, and could not be extended with parameters. Is/Are there reasons why this should be defined as a property vs. a function?

View 3 Replies

Access Methods Or Properties From Html In Asp.net Mvc?

Dec 4, 2009

In c# asp.net mvc I can declare some public class like:

public class Foo {
public static string Bar {get
{return "bar";}
}
}

and access it from any html like:

<%=Foo.Bar;%>

right?Well, I have to do the same in ASP.NET MVC VB.Net but I cannot access any variable or method:

public class Foo
public Shared ReadOnly Bar as string
Get

[code]....

UPDATE:standard VB.NET puts modules in the namespace defined in your project.I had to type

MVCApplication1.Foo.Bar

how to create a module that doesn't wrap this into a namespace? Or have the view import the application namespace by default?

View 2 Replies

Get Properties And Methods For Custom Class?

Oct 29, 2009

Is it possible to iterate through the properties and methods of a custom class, getting the details about those properties and methods in the process.[code]....

View 2 Replies

Use Control Name To Access Properties And Methods?

Sep 3, 2009

I have a sub (Sub 1)that passes a control to another sub (Sub2) Sub2 only knows that the control will either be a picturebox ("Pict1") or a rich textbox ("Rchtxbx").I want to put code in Sub2 that does the following if the control that is passed is aPictureBox:ictureBox1.Load("C est.bmp")However I don't know how to do this as when I type in "x" in Sub2, it does not default to the PictureBox properties and methods.Is it possible to use the name of a control and wrap it in some sort of ControlType() enclosure that identifies its type and grants access to its properties and methods?

View 1 Replies

Assigning Results To Base Class Properties

Apr 26, 2009

I have a base class where amongst other code I have declared 2 properties. In my derived class, I get data from the DB and assign the results to the base class properties. This is so when I go back to the base class code, I can access the property values. It allows me to set the values in the derived class but once I go back to the Base class, the values don't exist.

Snippets of code sample:
base class:
Public Class ServiceProcessor
Private mSalesOrderID As Integer = 0
Private mName As String = ""
Friend Property SalesOrderID() As Integer
[Code] .....

View 6 Replies

Nested Class Access Methods For Properties In .NET

Jan 20, 2011

I am trying to figure out the best approach for setting and getting properties in a nested class I am creating. I have a class, Car which has a nested class ControlPanel and want to make the properties of the Control Panel only accessible to the Car and Control Panel class.

[Code]...

View 5 Replies

Using String Properties/methods To Evaluate A Number?

May 4, 2012

I have one text box that the user enters an integer into. I use a select case to determine what the length of the number is. (along w/ string.length, etc)based on how long it is, I can determine if the number is 1-9, 10-99, 100-999, etc. What I want to do next is, evaluate the number and display a roman numeral that matches.

intMyNumber.substring(1,?) ' 1 would return the leftmost number
if intMyNumber.substring(1,?) = 1 then
if intMyNumber.substring(2,?) = 1 then 'etc

[code]....

View 3 Replies







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