示例#1
0
    public static void UnitTest()
    {
        var objs = new object[]
        {
            new List <char>(),
            new List <short> {
                1, 2, 5
            },
            new List <int> {
                1, 2, 3, 4
            },
        };

        foreach (var obj in objs)
        {
            int count = (int)obj.GetType().GetMethod(MethodName_Count).Invoke(obj, null);
            Debug.Assert(count == MonoCache_Count.Get(obj));
            Debug.Assert(count == PolyCache_Count.Get(obj));
            Debug.Assert(count == MegaCache_Count.Get(obj));
            Debug.Assert(count == CallSite_Count.Get(obj));
            Debug.Assert(count == SimpleCache_Count.Get(obj));

            int capacity = (int)obj.GetType().GetMethod(MethodName_Capacity).Invoke(obj, null);
            Debug.Assert(capacity == MonoCache_Capacity.Get(obj));
            Debug.Assert(capacity == PolyCache_Capacity.Get(obj));
            Debug.Assert(capacity == MegaCache_Capacity.Get(obj));
            Debug.Assert(capacity == CallSite_Capacity.Get(obj));
            Debug.Assert(capacity == SimpleCache_Capacity.Get(obj));

            var i = DynamicObject.ToInterface <ICountCapacity>(obj);
            Debug.Assert(count == i.get_Count());
            Debug.Assert(capacity == i.get_Capacity());
        }
    }