using System;
namespace Question
{
class Program
{
class A{
public class AC{}
}
class B: A{
}
class D: A{
new public class AC:A.AC{} // do I have to do this ?
public class DAC:A.AC{}
}
static void Main(string[] args)
{
var b_ac = new B.AC{}.GetType();
var B_AC = typeof(B.AC);
var D_AC = typeof(D.AC);
var DAC = typeof(D.DAC);
Func<Type,string> enclosure = (x)=>{
Console.WriteLine(x.DeclaringType.Name); // gives A - wrong
Console.WriteLine(x.BaseType.Name); // gives Object - wrong
Console.WriteLine(x.FullName); // gives A+AC - wrong, I want B+AC
Console.WriteLine(x.ReflectedType.FullName); // gives A - wrong
return "B"; // I want to get name of class B through reflection
};
Console.WriteLine(enclosure(b_ac)); // gives A+AC - wrong, see details in comments above
Console.WriteLine(enclosure(B_AC)); // gives same wrong
Console.WriteLine(enclosure(D_AC)); // gives D+AC - good
Console.WriteLine(enclosure(DAC)); // gives D+DAC - good
Console.ReadKey();
}
}
}
lundi 9 mars 2015
Is outer derived class visible through C#.NET reflection of inner class inherited from parent?
Inscription à :
Publier les commentaires (Atom)
Aucun commentaire:
Enregistrer un commentaire