Click here to Skip to main content
15,904,023 members
Home / Discussions / C#
   

C#

 
GeneralRe: Get Client Browser Time on server side Pin
sher_azam19-Feb-10 1:04
sher_azam19-Feb-10 1:04 
GeneralRe: Get Client Browser Time on server side Pin
J4amieC19-Feb-10 1:09
J4amieC19-Feb-10 1:09 
QuestionRegular expression [modified] Pin
Eduard Keilholz19-Feb-10 0:08
Eduard Keilholz19-Feb-10 0:08 
AnswerRe: Regular expression Pin
Not Active19-Feb-10 0:37
mentorNot Active19-Feb-10 0:37 
GeneralRe: Regular expression Pin
Eduard Keilholz19-Feb-10 2:27
Eduard Keilholz19-Feb-10 2:27 
AnswerRe: Regular expression Pin
rhuiden19-Feb-10 2:33
rhuiden19-Feb-10 2:33 
GeneralRe: Regular expression Pin
Eduard Keilholz19-Feb-10 3:47
Eduard Keilholz19-Feb-10 3:47 
Question[SOLVED] How do I get the type of the class I'm in without knowing its name? [modified] Pin
blackblizzard18-Feb-10 23:44
blackblizzard18-Feb-10 23:44 
Hi everyone.

I'm creating a class through reflection and I'd like to have a static initializer like this:

class MyClass {
     static MyClass() {
          someMethod(typeof(MyClass));
     }
}


That is, I'd like to obtain the type of MyClass and pass it to someMethod as argument. What's giving me trouble is obtaining the type of MyClass, since I'm emitting this code before the type MyClass is created: I'm defining MyClass with a TypeBuilder, but I haven't called CreateType() yet because I first need to add the static initializer. I have a hen-and-egg situation here.

Ideally what I'd like is to do something like:

class MyClass {
     static MyClass() {
          someMethod(this.GetType());
     }
}


but of course not with this because I'm in a static member and there's no "this". So, is there something equivalent to this but that identifies the class (or type) in which the code is declared (i.e., to which class belongs the code that is being run)? Sorry if I don't make much sense, I'm having trouble expressing this clearly Blush | :O

Thanks!
modified on Friday, February 19, 2010 8:35 AM

AnswerRe: How do I get the type of the class I'm in without knowing its name? Pin
Abhinav S19-Feb-10 0:47
Abhinav S19-Feb-10 0:47 
GeneralRe: How do I get the type of the class I'm in without knowing its name? Pin
blackblizzard19-Feb-10 1:03
blackblizzard19-Feb-10 1:03 
GeneralRe: How do I get the type of the class I'm in without knowing its name? Pin
Daniel Grunwald19-Feb-10 2:22
Daniel Grunwald19-Feb-10 2:22 
GeneralRe: How do I get the type of the class I'm in without knowing its name? Pin
blackblizzard19-Feb-10 2:35
blackblizzard19-Feb-10 2:35 
QuestionSql Connection Pin
Isaac Gordon18-Feb-10 23:29
Isaac Gordon18-Feb-10 23:29 
AnswerRe: Sql Connection Pin
Eddy Vluggen19-Feb-10 1:05
professionalEddy Vluggen19-Feb-10 1:05 
QuestionGet an "index" for a field of a class? Pin
blackblizzard18-Feb-10 23:29
blackblizzard18-Feb-10 23:29 
AnswerRe: Get an "index" for a field of a class? Pin
Luc Pattyn19-Feb-10 0:21
sitebuilderLuc Pattyn19-Feb-10 0:21 
GeneralRe: Get an "index" for a field of a class? Pin
blackblizzard19-Feb-10 0:30
blackblizzard19-Feb-10 0:30 
QuestionMemory Leak in WPF. Multiple instances of the same control in memory. [modified] Pin
AWriter18-Feb-10 23:03
AWriter18-Feb-10 23:03 
AnswerRe: Memory Leak in WPF. Multiple instances of the same control in memory. Pin
Saksida Bojan19-Feb-10 20:21
Saksida Bojan19-Feb-10 20:21 
Questiongrid view row copy Pin
Syed Shahid Hussain18-Feb-10 23:01
Syed Shahid Hussain18-Feb-10 23:01 
AnswerRe: grid view row copy Pin
Saksida Bojan19-Feb-10 20:14
Saksida Bojan19-Feb-10 20:14 
QuestionDatagridViewColumn displayIndex - column order wrong after setting them from control settings table. Pin
PoppysDad18-Feb-10 22:48
PoppysDad18-Feb-10 22:48 
AnswerRe: DatagridViewColumn displayIndex - column order wrong after setting them from control settings table. Pin
Vishal Bhatt115-Sep-10 22:58
Vishal Bhatt115-Sep-10 22:58 
AnswerRe: DatagridViewColumn displayIndex - column order wrong after setting them from control settings table. Pin
Zombie_Inc18-Nov-10 20:24
Zombie_Inc18-Nov-10 20:24 
GeneralRe: DatagridViewColumn displayIndex - column order wrong after setting them from control settings table. Pin
henhao8-May-11 7:23
henhao8-May-11 7:23 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.