Click here to Skip to main content
16,014,650 members
Home / Discussions / C#
   

C#

 
GeneralRe: regd creating library Pin
Paul Watson14-May-04 4:18
sitebuilderPaul Watson14-May-04 4:18 
GeneralShow Color In Datagrid Pin
sreejith ss nair14-May-04 3:37
sreejith ss nair14-May-04 3:37 
GeneralRe: Show Color In Datagrid Pin
OmegaSupreme14-May-04 4:12
OmegaSupreme14-May-04 4:12 
GeneralRe: Show Color In Datagrid Pin
Heath Stewart14-May-04 5:47
protectorHeath Stewart14-May-04 5:47 
GeneralRe: Show Color In Datagrid Pin
sreejith ss nair16-May-04 17:45
sreejith ss nair16-May-04 17:45 
GeneralRe: Show Color In Datagrid Pin
sreejith ss nair18-May-04 2:42
sreejith ss nair18-May-04 2:42 
GeneralGetting property value using reflection Pin
Uncle Monkey14-May-04 2:57
Uncle Monkey14-May-04 2:57 
GeneralRe: Getting property value using reflection Pin
Heath Stewart14-May-04 3:06
protectorHeath Stewart14-May-04 3:06 
Wow! You really should split your lines up into distinct pieces - it greatly helps during debugging your application.

You're doing a few things that aren't necessary and would hamper performance, like Type.GetType(Page.GetType().BaseType.FullName). Instead, you already have your Type using just Page.GetType().BaseType.

Also, when you call GetValue you must pass the instance of the object (presumably Page) otherwise you would get an exception since you're trying to retrieve the value of a null reference.

Also, if you flatten your instance members, you really don't need to refer to the base Type to get the property where it's declared. Unless BindingFlags.DeclaredOnly is specified, all instance properties - both declared and inheritted - are reflected (not so with statics, unless you specify BindingFlags.FlattenHierarchy). In ASP.NET, which I assume you're using since you have a Page object - though this could be anything - there is actually a large hierarchy of pages that extend from the Page class, such as your .aspx file : your code-behind page class : Page.
Type t = Page.GetType();
PropertyInfo prop = t.GetProperty("MyIntProperty", BindingFlags.Instance |
  BindingFlags.Public | BindingFlags.NonPublic);
int MyInt;
if (prop != null) MyInt = (int)prop.GetValue(Page, null);


 

Microsoft MVP, Visual C#
My Articles
GeneralRe: Getting property value using reflection Pin
Uncle Monkey14-May-04 3:53
Uncle Monkey14-May-04 3:53 
GeneralNamespace commenting for comment web page Pin
Michael P14-May-04 2:48
Michael P14-May-04 2:48 
GeneralRe: Namespace commenting for comment web page Pin
Heath Stewart14-May-04 2:50
protectorHeath Stewart14-May-04 2:50 
GeneralRe: Namespace commenting for comment web page Pin
Michael P14-May-04 2:57
Michael P14-May-04 2:57 
Generaldatagrid question Pin
azumi14-May-04 1:02
azumi14-May-04 1:02 
GeneralRe: datagrid question Pin
Aryadip14-May-04 1:36
Aryadip14-May-04 1:36 
GeneralRe: datagrid question Pin
azumi17-May-04 22:25
azumi17-May-04 22:25 
GeneralRe: datagrid question Pin
sreejith ss nair14-May-04 1:39
sreejith ss nair14-May-04 1:39 
GeneralRe: datagrid question Pin
azumi17-May-04 22:26
azumi17-May-04 22:26 
GeneralEvent handler Pin
sreejith ss nair14-May-04 1:02
sreejith ss nair14-May-04 1:02 
GeneralRe: Event handler Pin
Aryadip14-May-04 1:25
Aryadip14-May-04 1:25 
GeneralRe: Event handler Pin
sreejith ss nair14-May-04 1:44
sreejith ss nair14-May-04 1:44 
GeneralRe: Event handler Pin
Dave Kreskowiak14-May-04 7:40
mveDave Kreskowiak14-May-04 7:40 
GeneralRe: Event handler Pin
Heath Stewart14-May-04 3:15
protectorHeath Stewart14-May-04 3:15 
GeneralRe: Event handler Pin
sreejith ss nair14-May-04 3:27
sreejith ss nair14-May-04 3:27 
QuestionHow to pass a string from c++ to c# Pin
peraonline14-May-04 0:37
peraonline14-May-04 0:37 
AnswerRe: How to pass a string from c++ to c# Pin
Heath Stewart14-May-04 2:57
protectorHeath Stewart14-May-04 2:57 

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.