C#, .NET 2.0Co jest nie tak z tym kodem odbitek? GetFields() zwraca pustą tablicę
Oto kod (wyjąłem wszystkie moje domeny specyficzne rzeczy, i nadal zwraca pustą tablicę):
using System;
using System.Collections.Generic;
using System.Text;
using System.Reflection;
namespace ConsoleApplication1
{
class Program
{
static void Main(string[] args)
{
ChildClass cc = new ChildClass();
cc.OtherProperty = 1;
FieldInfo[] fi = cc.GetType().GetFields();
Console.WriteLine(fi.Length);
Console.ReadLine();
}
}
class BaseClass<T>
{
private int myVar;
public int MyProperty
{
get { return myVar; }
set { myVar = value; }
}
}
class ChildClass : BaseClass<ChildClass>
{
private int myVar;
public int OtherProperty
{
get { return myVar; }
set { myVar = value; }
}
}
}
+1 To jest to, * musisz * określać instancję oraz NonPublic. –
Pozdrawiam za odpowiedź! Mam jednak problem z jego zrozumieniem. Czy ktoś mógłby wyjaśnić, dlaczego instancja lub statystyka jest wymagana wraz z NonPublic dla pól prywatnych? – Zack
@ rory.ap: Tak, dokładnie. –