Click here to Skip to main content
15,905,508 members
Home / Discussions / C#
   

C#

 
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 
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 
No, sorry, the problem is I'm emitting the code with Reflection.Emit, so I can't just type "MyClass".
It works like this:
* Someone calls my class ObjectFactory with a Type they want me to extend, say "MyType".
* Using reflection, I create a subclass of MyType, called EXT_MyType, which has some extra fields and methods. I want to add a static initializer to EXT_MyType, which should look like this:

static EXT_MyType() {
    someMethod(typeof(EXT_MyType));
}


But the problem is when I emit the code for this static initializer I haven't yet created the type EXT_MyType (that's what I'm doing, I'm creating its static initializer, etc), so I don't know how to emit this code. See, I'm trying to emit it like this:

ilGenerator.Emit(OpCodes.Ldtoken, typeof(EXT_MyType));
ilGenerator.Emit(OpCodes.Call, typeof(EXT_MyType).GetMethod("someMethod"));


but EXT_MyType doesn't exist yet. So I'm wondering whether there's a primitive or something I can invoke from within the static initializer that will allow me to do this instead:

static EXT_MyType() {
    someMethod(getTypeOfThisClass());
}


Where getTypeOfThisClass() would be that "primitive or something...". Since this call would take place once I've created EXT_MyType there wouldn't be a problem. I just don't know whether a primitive like that exists.

If it doesn't, I'd appreciate suggestions on alternative ways of doing this.
Thanks!
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 
QuestionHow to check if Excel-workbook is empty? Pin
Thomas ST18-Feb-10 22:28
Thomas ST18-Feb-10 22:28 
AnswerRe: How to check if Excel-workbook is empty? Pin
Thomas ST18-Feb-10 22:41
Thomas ST18-Feb-10 22:41 

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.