Click here to Skip to main content
15,887,939 members
Home / Discussions / C#
   

C#

 
AnswerRe: How do i change theimage quality of background images? Pin
Christian Graus9-Oct-05 2:46
protectorChristian Graus9-Oct-05 2:46 
Questionstatus bar Pin
Saurabh Walia9-Oct-05 1:16
Saurabh Walia9-Oct-05 1:16 
AnswerRe: status bar Pin
Guffa9-Oct-05 2:12
Guffa9-Oct-05 2:12 
AnswerRe: status bar Pin
David Stone9-Oct-05 3:22
sitebuilderDavid Stone9-Oct-05 3:22 
QuestionPropertyGrid scrolls to selected property Pin
biggz_daddy8-Oct-05 17:20
biggz_daddy8-Oct-05 17:20 
AnswerRe: PropertyGrid scrolls to selected property Pin
joegood10-Oct-05 6:21
joegood10-Oct-05 6:21 
QuestionFinding the volume level of the currently recording audio? Pin
karl6438-Oct-05 17:16
karl6438-Oct-05 17:16 
QuestionAccessing property values using GetValue() Pin
mossu8-Oct-05 16:35
mossu8-Oct-05 16:35 
Hi,

I'm trying to build a test in nUnit, that checks if after a specific function call, all numeric property values are set to zero. Since I don't know if I will eventually add other properties, I tried building this test in a generic way. I'm not even sure I can do something like this, but if yes, how should I do it?

I'm used to programming in VB 6 and a bit of VB.Net, so I'm not too sure where to start on how to do this in C#, but I've tried a couple of things that look like this :
MyClass myClass = new MyClass();

for (int i = 0; i <= myClass.GetType().GetProperties().GetUpperBound(0);i++)
    {			
	if (myClass.GetType().GetProperties()[i].PropertyType.IsValueType)
	{
             if (myClass.GetType().GetProperties()[i].GetType().IsArray)
             {
	          MessageBox("Don't forget to check array properties eventually!");
             }
             else
             {

                  //Assert.AreEqual(0,(int)myClass.GetType().GetProperties()[i].GetValue(this, null));
                  Assert.AreEqual(0,(int)myClass.GetType().GetProperties()[i].GetValue(myClass.GetType().GetProperties()[i],null));
             }
        }
     }


Each time, I get a System.Reflection.TargetException.

Thanks in advance if anyone can help me!

P.S. Maybe it could be easyier to access the object's private variables directly, but I don't know how to do that either.

jG
AnswerRe: Accessing property values using GetValue() Pin
Guffa9-Oct-05 0:22
Guffa9-Oct-05 0:22 
GeneralRe: Accessing property values using GetValue() Pin
mossu9-Oct-05 2:38
mossu9-Oct-05 2:38 
GeneralRe: Accessing property values using GetValue() Pin
Guffa9-Oct-05 8:50
Guffa9-Oct-05 8:50 
GeneralRe: Accessing property values using GetValue() Pin
mossu10-Oct-05 3:01
mossu10-Oct-05 3:01 
AnswerRe: Accessing property values using GetValue() Pin
S. Senthil Kumar9-Oct-05 3:18
S. Senthil Kumar9-Oct-05 3:18 
GeneralRe: Accessing property values using GetValue() Pin
mossu9-Oct-05 6:05
mossu9-Oct-05 6:05 
QuestionOODBMS are the best solution for Today applications Pin
tolgayikilmaz8-Oct-05 12:16
tolgayikilmaz8-Oct-05 12:16 
AnswerRe: OODBMS are the best solution for Today applications Pin
johhnny8-Oct-05 12:20
johhnny8-Oct-05 12:20 
AnswerRe: OODBMS are the best solution for Today applications Pin
Colin Angus Mackay8-Oct-05 22:26
Colin Angus Mackay8-Oct-05 22:26 
GeneralRe: OODBMS are the best solution for Today applications Pin
tolgayikilmaz9-Oct-05 1:45
tolgayikilmaz9-Oct-05 1:45 
GeneralRe: OODBMS are the best solution for Today applications Pin
Colin Angus Mackay9-Oct-05 1:48
Colin Angus Mackay9-Oct-05 1:48 
AnswerRe: OODBMS are the best solution for Today applications Pin
Kevin McFarlane9-Oct-05 8:29
Kevin McFarlane9-Oct-05 8:29 
QuestionOpening the Form in maximized mode? Pin
E6AD8-Oct-05 12:09
E6AD8-Oct-05 12:09 
AnswerRe: Opening the Form in maximized mode? Pin
S. Senthil Kumar8-Oct-05 20:03
S. Senthil Kumar8-Oct-05 20:03 
QuestionWindowScraping Pin
budidharma8-Oct-05 11:17
budidharma8-Oct-05 11:17 
AnswerRe: WindowScraping Pin
XRaheemX10-Oct-05 5:06
XRaheemX10-Oct-05 5:06 
QuestionTaskbar Applications Pin
jgallen238-Oct-05 11:13
jgallen238-Oct-05 11:13 

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.