本文整理汇总了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;
}
示例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;
}
示例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");
}