Click here to Skip to main content
15,889,372 members
Home / Discussions / C#
   

C#

 
GeneralRe: differentiating between MouseDown and single click Pin
Heath Stewart30-Jul-04 9:32
protectorHeath Stewart30-Jul-04 9:32 
GeneralEvent Handler Pin
eggie530-Jul-04 7:42
eggie530-Jul-04 7:42 
GeneralRe: Event Handler Pin
Heath Stewart30-Jul-04 8:25
protectorHeath Stewart30-Jul-04 8:25 
QuestionWhere is the Activitybar? Pin
matthias s.30-Jul-04 4:36
matthias s.30-Jul-04 4:36 
Questionhow can i navigate between controls on a form using enter key in c# Pin
ch_faf30-Jul-04 4:01
ch_faf30-Jul-04 4:01 
AnswerRe: how can i navigate between controls on a form using enter key in c# Pin
Michael P Butler30-Jul-04 4:21
Michael P Butler30-Jul-04 4:21 
AnswerRe: how can i navigate between controls on a form using enter key in c# Pin
Heath Stewart30-Jul-04 7:36
protectorHeath Stewart30-Jul-04 7:36 
GeneralArray´s via reflection... Pin
Norman-Timo30-Jul-04 3:09
Norman-Timo30-Jul-04 3:09 
Hello C# Guru´s!

I´ve a serious problem with array´s and reflection.

I have a assembly source something like that:

namespace Test
{

class TestClass
{
public int intTest1;
public float fltTest1;

public int[] arrTest;

// default constructor
TestClass()
{
arrTest = new int[12];
}
}
}

For each instance a default constructor defines the array 'arrTest'.

I read MetaInforation from this dll and instanced a object from this class.
Then I walk through every Field and do something.
But if the field is an array I would do something before, and for that I need the Length of the array.

I tried following lines:

using System;
using System.Reflection;

namespace Test
{
class MainClass
{

[STAThread]
static void Main()
{

Assembly assembly = System.Reflection.Assembly.LoadFrom("Test.dll");

foreach(Type tmpType in assembly.GetTypes())
{
if (tmpType.IsClass)
{
MethodInfo[] m = tmpType.GetMethods();

object myInstance = tmpType.InvokeMember(m[0].Name, BindingFlags.Default | BindingFlags.InvokeMethod, null, tmpType, null);

foreach (FieldInfo tmpField in tmpType.GetFields())
{
if (tmpField.FieldType.IsArray)
{
PropertyInfo p = tmpField.FieldType.GetProperty("Length", typeof(int));
int arrLength = (int) p.GetValue(tmpField,null);
// ************************************* //
}

// do something
}

}

}

}
}
}

Compile and Link is no problem...
But if I debug the lines it stops at // *********
with an Exception: The target object does not match (or something like that)

Why? I can´t help myself anymore, what did I wrong?

Please help me...

With regards
Norman-Timo
GeneralRe: Array´s via reflection... Pin
leppie30-Jul-04 7:30
leppie30-Jul-04 7:30 
GeneralRe: Array´s via reflection... Pin
Norman-Timo1-Aug-04 19:42
Norman-Timo1-Aug-04 19:42 
GeneralConsole.writeline not working from a windows app. Pin
Admiral Ackbar30-Jul-04 3:00
Admiral Ackbar30-Jul-04 3:00 
GeneralRe: Console.writeline not working from a windows app. Pin
Wender Oliveira30-Jul-04 4:41
Wender Oliveira30-Jul-04 4:41 
GeneralRe: Console.writeline not working from a windows app. Pin
Michael P Butler30-Jul-04 4:54
Michael P Butler30-Jul-04 4:54 
GeneralRe: Console.writeline not working from a windows app. Pin
Heath Stewart30-Jul-04 7:32
protectorHeath Stewart30-Jul-04 7:32 
GeneralRe: Console.writeline not working from a windows app. Pin
Admiral Ackbar30-Jul-04 8:19
Admiral Ackbar30-Jul-04 8:19 
GeneralDrag n drop treeview Nodes between two different applications Pin
misterbear30-Jul-04 2:02
misterbear30-Jul-04 2:02 
GeneralRe: Drag n drop treeview Nodes between two different applications Pin
Heath Stewart30-Jul-04 5:58
protectorHeath Stewart30-Jul-04 5:58 
GeneralRe: Drag n drop treeview Nodes between two different applications Pin
misterbear31-Jul-04 4:59
misterbear31-Jul-04 4:59 
GeneralRe: Drag n drop treeview Nodes between two different applications Pin
Heath Stewart31-Jul-04 5:26
protectorHeath Stewart31-Jul-04 5:26 
GeneralMessage Removed Pin
30-Jul-04 1:01
wibblewibblewibble30-Jul-04 1:01 
GeneralRe: Image Class Problem Pin
Bret Mulvey9-Aug-04 17:54
Bret Mulvey9-Aug-04 17:54 
GeneralWebBrowser's Document Complete event Pin
profoundwhispers29-Jul-04 23:02
profoundwhispers29-Jul-04 23:02 
GeneralRe: WebBrowser's Document Complete event Pin
HiltonG30-Jul-04 2:30
HiltonG30-Jul-04 2:30 
GeneralRe: WebBrowser's Document Complete event Pin
profoundwhispers30-Jul-04 8:33
profoundwhispers30-Jul-04 8:33 
GeneralRe: WebBrowser's Document Complete event Pin
Dave Kreskowiak30-Jul-04 4:27
mveDave Kreskowiak30-Jul-04 4:27 

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.