473,385 Members | 1,673 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

Accessing the Class Name of a Shared Method

BBM
I may be putting too fine a point on this, but I'd like to be able to know
the class name of a shared method from within the method.

BTW, the shared method is in a "MustInherit" class.

So it looks like this...

Public MustInherit Class BaseClass
Public Shared Sub DoIt()
' Need to know which class is "running"
' There is no "me" because the method is Shared
End Sub
End Class

Public Class DerivedClass
Inherits BaseClass
End Class

Calling Code would look like this...

DerivedClass.DoIt()

PS. DoIt needs the class name to do a lookup of user rights to that class.
The lookup procedure is the same for all classes - hence the shared method.
I realize I could always use a parm to pass the class name...

DerivedClass.DoIt("DerivedClass")

But it's cleaner if the DoIt method figures out the class name on its own.

Thanks.

BBM
Oct 2 '06 #1
2 1592
Hi BBM,

I'm afraid what you're trying to do is not possible. If you call the static
method with both BaseClass and DerivedClass, then use ildasm to view the
generated IL code, the instructions are the same, both are calling
BaseClass::DoIt(). So using reflection, you will always get the BaseClass.

Here's some similar discussion:

#The Old .NET Questions Forum - Calling type of a derived static method
http://discuss.fogcreek.com/dotnetqu...ow&ixPost=2466

Sincerely,
Walter Wang (wa****@online.microsoft.com, remove 'online.')
Microsoft Online Community Support

==================================================
Get notification to my posts through email? Please refer to
http://msdn.microsoft.com/subscripti...ult.aspx#notif
ications. If you are using Outlook Express, please make sure you clear the
check box "Tools/Options/Read: Get 300 headers at a time" to see your reply
promptly.

Note: The MSDN Managed Newsgroup support offering is for non-urgent issues
where an initial response from the community or a Microsoft Support
Engineer within 1 business day is acceptable. Please note that each follow
up response may take approximately 2 business days as the support
professional working with you may need further investigation to reach the
most efficient resolution. The offering is not appropriate for situations
that require urgent, real-time or phone-based interactions or complex
project analysis and dump analysis issues. Issues of this nature are best
handled working with a dedicated Microsoft Support Engineer by contacting
Microsoft Customer Support Services (CSS) at
http://msdn.microsoft.com/subscripti...t/default.aspx.
==================================================

This posting is provided "AS IS" with no warranties, and confers no rights.

Oct 3 '06 #2
BBM,

In addition to Walter, be aware that a Shared Class is not creating objects,
it is almost exact the same as a module which is fixed in Memory.

I would have liked it if the crazy name Class which is used in C was not
taken for that in Visual Basic. It is no Type which can be instanced.

Even more I think that it would have been better as in C# was used the name
module, but that would probably have kicked to *some* of C# users ideas that
C# is far above VB.Net.

Cor

"BBM" <bb*@newsgroups.nospamschreef in bericht
news:FF**********************************@microsof t.com...
>I may be putting too fine a point on this, but I'd like to be able to know
the class name of a shared method from within the method.

BTW, the shared method is in a "MustInherit" class.

So it looks like this...

Public MustInherit Class BaseClass
Public Shared Sub DoIt()
' Need to know which class is "running"
' There is no "me" because the method is Shared
End Sub
End Class

Public Class DerivedClass
Inherits BaseClass
End Class

Calling Code would look like this...

DerivedClass.DoIt()

PS. DoIt needs the class name to do a lookup of user rights to that
class.
The lookup procedure is the same for all classes - hence the shared
method.
I realize I could always use a parm to pass the class name...

DerivedClass.DoIt("DerivedClass")

But it's cleaner if the DoIt method figures out the class name on its own.

Thanks.

BBM

Oct 3 '06 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

8
by: Mike Caputo | last post by:
In VB.NET, need to be able to access certain properties on my main form from other forms. These are properties that may be changed by the user, so I have to be able to get to them throughout the...
9
by: Bob Day | last post by:
VS 2003, vb.net , sql msde... I have an application with multiple threads running. Its a telephony application where each thread represents a telephone line. For code that would be the same...
2
by: Allen | last post by:
Hey all, I have a question for you all. I'm learning vb.net and need some help. I have two classes one named Customers and one named CustomersDA. I have to go though Customer for everything. I have...
5
by: Khalique | last post by:
Hi everyone, I Hope that someone will be able to give me a hint to the solution to my problem. I have developed a web service (vb.net) that needs to access the folders / files and copy files to...
29
by: Michael D. Ober | last post by:
Is there any way to create a constant in a class that can be used both with an instantiated object and without. For example: dim ClassConst as string = myClass.ConstantString dim myObj = new...
3
by: C-Services Holland b.v. | last post by:
Hi all, I've created a custom button which I can stick into my toolbox. This all works well and I see my button in the designer. This button uses customised graphics and I want to stick it in...
2
by: mgoold2002 | last post by:
Hello. I've just begun programming in VB .NET, and I'm trying to turn all my modules into classes. In order to retrieve/exchange values from one class to another, I initiated New instances of the...
10
by: Bonzol | last post by:
vb.net Hey there, could someone just tell me what the differnce is between classes and modules and when each one would be used compared to the other? Any help would be great Thanx in...
1
by: iamahulk | last post by:
Why do I get a warning: Access of shared member, constant member, enum member or nested type through an instance; qualifying expression will not be evaluated When accessing a shared method in...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.