M
Milan
Hi comunity,
I have noticed that once IList object is created with:
IList<baza> il_baza = new List<baza>();
Later if I try with reflection to InvokeMember:
type.InvokeMember("ElementAt", BindingFlags.Default |
BindingFlags.InvokeMethod, null, il_baza, arg);
I get MissingMethodException error message because of type of il_baza is not
any more IList`1 but List`1:
Method "System.Collections.Generic.List`1[[Reflection.baza,
ConsoleApplication2, Version=1.0.0.0, Culture=neutral,
PublicKeyToken=null]].ElementAt" can not be found.
There are 2 questions:
1. Why type has been not read out correctly like generic IList but generic
List ?
2. How I can using reflection and il_baza call the method ElementAt ?
Thanks and have a nice day,
Milan.
The code is following:
class baza
{
public string vrati()
{ return "u bazi"; }
}
class Class1
{
[STAThread]
static void Main(string[] args)
{
IList<baza> il_baza = new List<baza>();
il_baza.Add(new baza());
il_baza.Add(new baza());
il_baza.Add(new baza());
//foliwing code works fine...it finds function "ElementAt"
il_baza.ElementAt(0);
il_baza.ElementAt(1);
il_baza.ElementAt(2);
Type type = (Type)il_baza.GetType();//returns type "List`1", why ?
object[] arg = new object[1];
arg[0] = 0;
//folowing code fires error message! it does not find "ElementAt"
type.InvokeMember("ElementAt", BindingFlags.Default |
BindingFlags.InvokeMethod, null, il_baza, arg);
}
}
I have noticed that once IList object is created with:
IList<baza> il_baza = new List<baza>();
Later if I try with reflection to InvokeMember:
type.InvokeMember("ElementAt", BindingFlags.Default |
BindingFlags.InvokeMethod, null, il_baza, arg);
I get MissingMethodException error message because of type of il_baza is not
any more IList`1 but List`1:
Method "System.Collections.Generic.List`1[[Reflection.baza,
ConsoleApplication2, Version=1.0.0.0, Culture=neutral,
PublicKeyToken=null]].ElementAt" can not be found.
There are 2 questions:
1. Why type has been not read out correctly like generic IList but generic
List ?
2. How I can using reflection and il_baza call the method ElementAt ?
Thanks and have a nice day,
Milan.
The code is following:
class baza
{
public string vrati()
{ return "u bazi"; }
}
class Class1
{
[STAThread]
static void Main(string[] args)
{
IList<baza> il_baza = new List<baza>();
il_baza.Add(new baza());
il_baza.Add(new baza());
il_baza.Add(new baza());
//foliwing code works fine...it finds function "ElementAt"
il_baza.ElementAt(0);
il_baza.ElementAt(1);
il_baza.ElementAt(2);
Type type = (Type)il_baza.GetType();//returns type "List`1", why ?
object[] arg = new object[1];
arg[0] = 0;
//folowing code fires error message! it does not find "ElementAt"
type.InvokeMember("ElementAt", BindingFlags.Default |
BindingFlags.InvokeMethod, null, il_baza, arg);
}
}