假设我们有一个NodeData类: public class NodeData { public string Name; public T Value; public NodeData(string name, T value) { this.Name = name; this.Value = value; } } 以及具有NodaData类型的多个属性的基类Node类和子类: public class Node { public List<NodeData> listOutputs() { var fieldInfos = GetType().GetFields(); var list = new List<NodeData>(); foreach (var item in fieldInfos) { Type t = item.FieldType; string name […]
我有一个基本抽象类及其抽象类型参数: public abstract class Database where T : DatabaseItem, new() { protected List _items = new List (); protected virtual void Read (string[] cols) { T item = new T (); … } public abstract class DatabaseItem { … } 然后我有许多固有的儿童课程: public class ShopDatabase : Database {} public class ShopItem : DatabaseItem {} public class […]
C#,Net 2.0 这是代码(我拿出了所有特定于域的东西,它仍然返回一个空数组): 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 { private int myVar; public int MyProperty { get { return myVar; } set { […]