【问题标题】:NCache Generic Type Handler ImplementationNCache 泛型类型处理程序实现
【发布时间】:2013-10-19 12:57:58
【问题描述】:

在每个缓存的 NCache 管理器中,您必须单独定义紧凑类型以防泛型有没有办法一次将所有类提供给缓存紧凑

【问题讨论】:

    标签: .net ncache


    【解决方案1】:

    您应该从 Runtime.dll 实现 Ncache IGenericTypeProvider 接口 类 GenericTypeProvider1 : IGenericTypeProvider { #region IGenericTypeProvider 成员

        public Type[] GetGenericTypes()
        {
            ArrayList aryList = new ArrayList();
    
            #region Classes that hold generic types inside or inherited from the generic types...
            aryList.Add(new PrimitiveTypes());
            aryList.Add(new ComplexTypes());
            aryList.Add(new UnsignedTypes());
            aryList.Add(new GenericHolder());
            aryList.Add(new GenericChild()); 
            #endregion
    
            #region Custom Generic objects that take only one type arguemt ...
            aryList.Add(new GenericClass<string>());
            aryList.Add(new GenericClass<bool>());
            aryList.Add(new GenericClass<double>());
            aryList.Add(new GenericClass<byte[]>());
            aryList.Add(new GenericClass<DateTime>());
            aryList.Add(new GenericClass<TimeSpan>());
            aryList.Add(new GenericClass<Guid>());
            aryList.Add(new GenericClass<Product>());
            aryList.Add(new GenericClass<AllTypes>());
            aryList.Add(new GenericClass<NullableObject>());
            aryList.Add(new GenericClass<List<AllTypes>>());
            aryList.Add(new GenericClass<List<AllDataTypes>>());
            aryList.Add(new GenericClass<List<NullableObject>>());
            aryList.Add(new GenericClass<Dictionary<string, NullableObject>>());
            aryList.Add(new GenericClass<List<GenericList<NullableObject>>>());
            aryList.Add(new GenericClass<List<Dictionary<string, NullableObject>>>()); 
            #endregion
    
            //--- Populate the type array with the types of the above given objects ...
            Type[] types = new Type[aryList.Count];
            for (int i = 0; i < types.Length; i++)
                types[i] = aryList[i].GetType();
    
    
            return types;
        }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2019-06-12
      • 1970-01-01
      • 1970-01-01
      • 2016-10-16
      • 1970-01-01
      • 2020-06-11
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多