|
web
newsgroups
|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
Accessing the Class Name of a Shared Methodthe 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 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/dotnetquestions/default.asp?cmd=show&ixPost=2466 Sincerely, Walter Wang (waw***@online.microsoft.com, remove 'online.') Microsoft Online Community Support ================================================== Get notification to my posts through email? Please refer to http://msdn.microsoft.com/subscriptions/managednewsgroups/default.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/subscriptions/support/default.aspx. ================================================== This posting is provided "AS IS" with no warranties, and confers no rights. 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 Show quoteHide quote "BBM" <bbm@newsgroups.nospam> schreef in bericht news:FFBAC11E-A104-44B2-AA3F-7628631D0F8B@microsoft.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
CURRENT INDEX of Iteration on ILIST collection ?
Registry enigma - please help! firefox com for winform ? 1.1 equivalent for Drawing.Icon.ExtractAssociatedIcon? Help with using bits in an integer Strings, a couple of questions like difference between += and &= new form Set Statement vs Function Error help chm and application.startuppath |
|||||||||||||||||||||||