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


C# Lazy.Value方法代码示例

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


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

示例1: TryDispose

 static bool TryDispose(this IDisposable disposable, Lazy<Action<Exception>> exceptionHandler)
 {
     try {
         if (null != disposable) {
             disposable.Dispose ();
             return true;
         }
     }
     catch (Exception exception) {
         exceptionHandler.Value (exception);
     }
     return false;
 }
开发者ID:GeorgeTsiokos,项目名称:corlib,代码行数:13,代码来源:DisposableExtensions.cs

示例2: GetValidators

        protected override IEnumerable<ModelValidator> GetValidators(ModelMetadata metadata, ControllerContext context, IEnumerable<Attribute> attributes)
        {
            var localizedAttributes = new List<Attribute>();

            // overriden messages have their localization in the scope of the class they are applied to
            var tContainer = new Lazy<Localizer>(() => LocalizationUtilities.Resolve(context, (metadata.ContainerType ?? metadata.ModelType).FullName));

            foreach (var attribute in attributes) {
                Func<ValidationAttribute, Localizer, ValidationAttribute> localizedAttribute;

                // default translations use the attribute's scope, e.g., Coevery.Mvc.DataAnnotations.LocalizedRequiredAttribute
                var localAttribute = attribute;
                var tProvider = new Lazy<Localizer>(() => LocalizationUtilities.Resolve(context, localAttribute.GetType().FullName));

                var validationAttribute = attribute as ValidationAttribute;

                // substitute the attribute to its localized version if available
                if ( _validationAttributes.TryGetValue(attribute.GetType(), out localizedAttribute) ) {
                    localizedAttributes.Add(localizedAttribute((ValidationAttribute)attribute, tProvider.Value));
                }
                else {

                    // try to inject the localizer if it's an unkown validation attribute
                    if ( validationAttribute != null ) {

                        var propertyInfo = validationAttribute.GetType().GetProperty("T", typeof(Localizer));
                        if ( propertyInfo != null ) {
                            propertyInfo.SetValue(attribute, tProvider.Value, null);
                        }
                    }

                    if ( attribute is DisplayNameAttribute ) {
                        metadata.DisplayName = tContainer.Value(metadata.DisplayName).Text;
                    }

                    localizedAttributes.Add(attribute);
                }
            }

            var result = base.GetValidators(metadata, context, localizedAttributes);

            return result;
        }
开发者ID:gokhandisikara,项目名称:Coevery-Framework,代码行数:43,代码来源:LocalizedModelValidatorProvider.cs

示例3: PerformanceTest

        public void PerformanceTest()
        {
            int iterations = 1000000;
            IMethodWithReferenceTypeParameter target = new MethodWithReferenceTypeParameter();
            Measure(() => target.Execute("SomeValue"), iterations, "Direct");

            var method = typeof(IMethodWithReferenceTypeParameter).GetMethods()[0];
            //Measure(() => method.Invoke(target, new object[]{"SomeValue"}), iterations, "Reflection");

            var methodInvoker = GetMethodInvoker();
            Measure(() => methodInvoker.Invoke(method, target, new object[] { "SomeValue" }), iterations, "MethodInvoker");

            Func<object, object[], object> del = GetMethodInvoker().CreateDelegate(method);
            Measure(() => del(target, new object[] { "someValue" }), iterations, "CachedDelegate");

            Lazy<Func<object, object[], object>> lazy = new Lazy<Func<object, object[], object>>(() => methodInvoker.CreateDelegate(method));
            Measure(() => lazy.Value(target, new object[] { "someValue" }), iterations, "LazyDelegate");
        }
开发者ID:seesharper,项目名称:LightProxy,代码行数:18,代码来源:MethodInvokerTests.cs


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