当前位置: 首页>>代码示例>>C#>>正文


C# TimeSpan.IsGreaterThanZero方法代码示例

本文整理汇总了C#中System.TimeSpan.IsGreaterThanZero方法的典型用法代码示例。如果您正苦于以下问题:C# TimeSpan.IsGreaterThanZero方法的具体用法?C# TimeSpan.IsGreaterThanZero怎么用?C# TimeSpan.IsGreaterThanZero使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在System.TimeSpan的用法示例。


在下文中一共展示了TimeSpan.IsGreaterThanZero方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: Select

        public ICacheImplementation Select(TimeSpan durationToCacheItemFor,
                                           StorageStyle cacheStorageStyle,
                                           ExpirationType expirationType)
        {
            Ensure.That(durationToCacheItemFor.IsGreaterThanZero(), "durationToCacheItemFor");

            return _selectorDelegate(durationToCacheItemFor,
                                     cacheStorageStyle,
                                     expirationType,
                                     _implementations);
        }
开发者ID:benaston,项目名称:NCacheFacade,代码行数:11,代码来源:CacheImplementationSelector.cs

示例2: SelectCacheImplementation

        /// <summary>
        ///   This is the method to be supplied to the constructor of 
        ///   the base type as the delegate to use for cache selection.
        ///   Selects a cache based on the heuristic of duration to 
        ///   store for, followed by the availability of the requested 
        ///   caching functionality. This logic serves as a workable 
        ///   example, rather than a recommended strategy. For example, 
        ///   the fallback case is handled without error or warning.        
        ///   Public rather than protected for testing purposes.
        /// </summary>
        /// <remarks>
        ///   NOTE: BA; should we throw an exception if the user requests 
        ///   a storage strategy that cannot be fulfilled due to 
        ///   limitations of the underlying cache?
        ///   NOTE: BA; Potentially have a flag to indicate strictness of
        ///   choice of cache - i.e. does the cache really need to 
        ///   support all the desired features, or can we substitute 
        ///   them?
        ///   "narrow down choice of caches to those that can be used, 
        ///   then choose the enabled one according to priority".
        /// </remarks>
        /// <param name = "implementations">Ordered by preference of use 
        ///   with highest pref first.</param>
        public static ICacheImplementation SelectCacheImplementation(TimeSpan durationToCacheItemFor,
                                                                     StorageStyle cacheStorageStyle,
                                                                     ExpirationType cacheExpirationType,
                                                                     Dictionary<string, ICacheImplementation>
                                                                         implementations)
        {
            Ensure.That<FriendlyExceptions.ArgumentOutOfRangeException>(durationToCacheItemFor.IsGreaterThanZero(),
                                                                        "durationToCacheFor")
                .And<FriendlyExceptions.ArgumentNullException>(implementations.IsNotNull(), "implementations")
                .And<FriendlyExceptions.ArgumentException>(implementations.Count.Is(2), "implementations")
                .And<MissingCacheImplementationArgumentException>(
                    implementations.ContainsKey(MemcachedImplementationTypeName), "memcached missing")
                .And<MissingCacheImplementationArgumentException>(
                    implementations.ContainsKey(AspDotNetImplementationTypeName), "asp.net data cache missing");

            ICacheImplementation cacheToUse = null;

            //simply tries to select memcached if an extended caching period is requested
            //otherwise attempts to fallback to ASP.NET data cache. This might occur because
            //the caching expiration type is not supported by memcached.
            if (durationToCacheItemFor >= LongTermBoundary)
            {
                if (implementations[MemcachedImplementationTypeName].Supports((cacheExpirationType))
                    && implementations[MemcachedImplementationTypeName].IsEnabled)
                    cacheToUse = implementations[MemcachedImplementationTypeName];

                if (cacheToUse == null
                    && implementations[AspDotNetImplementationTypeName].Supports((cacheExpirationType))
                    && implementations[AspDotNetImplementationTypeName].IsEnabled)
                    cacheToUse = implementations[AspDotNetImplementationTypeName];

                Ensure.That(cacheToUse.IsNotNull(), () => { throw new CacheSelectionException(implementations); });
            }
            else
            {
                if (implementations[AspDotNetImplementationTypeName].Supports((cacheExpirationType))
                    && implementations[AspDotNetImplementationTypeName].IsEnabled)
                    cacheToUse = implementations[AspDotNetImplementationTypeName];

                if (cacheToUse == null
                    && implementations[MemcachedImplementationTypeName].Supports((cacheExpirationType))
                    && implementations[MemcachedImplementationTypeName].IsEnabled)
                    cacheToUse = implementations[MemcachedImplementationTypeName];

                Ensure.That(cacheToUse.IsNotNull(), () => { throw new CacheSelectionException(implementations); });
            }

            return cacheToUse;
        }
开发者ID:benaston,项目名称:NCacheFacade,代码行数:72,代码来源:ExampleCachingStrategy.cs


注:本文中的System.TimeSpan.IsGreaterThanZero方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。