using System.Reflection; namespace OptionStudy.Next { /// /// 5.2 配置模型:数据结构之配置字典 /// public class DataStructurelTest:IDisposable { private readonly ITestOutputHelper testOutput; public DataStructurelTest(ITestOutputHelper testOutputHelper) { testOutput= testOutputHelper; } #region 配置字典:配置源与配置逻辑结构的统一中间实现载体 #endregion /// /// 配置字典的类型 /// [Fact] public void ConfigDictionary_DataType__Test() { //配置字典在 ConfigurationProvider 中默认实现为下面定义的 Data 属性,只能在继承类中可见 IDictionary Data = new Dictionary() { }; //配置字典的类型 var configDicDataType = typeof(IDictionary); //使用反射,获取"配置字典"类型 //获取Data属性 var dataProperty = typeof(ConfigurationProvider).GetProperty("Data", BindingFlags.NonPublic | BindingFlags.Instance); //获取Data属性的类型 var dataPropertyType = dataProperty?.PropertyType; //断言 Assert.NotNull(dataProperty); Assert.Equal(configDicDataType, dataPropertyType); testOutput.WriteLine("测试配置字典的数据类型"); } public void Dispose() { } } }