本文整理汇总了C#中IHandler.FirstOrDefault方法的典型用法代码示例。如果您正苦于以下问题:C# IHandler.FirstOrDefault方法的具体用法?C# IHandler.FirstOrDefault怎么用?C# IHandler.FirstOrDefault使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类IHandler
的用法示例。
在下文中一共展示了IHandler.FirstOrDefault方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: SelectHandler
public virtual IHandler SelectHandler(string key, Type service, IHandler[] handlers)
{
var handlerForDefaultKey = handlers.FirstOrDefault(handler => handler.ComponentModel.Name == _keyToDefaultTo);
if (handlerForDefaultKey == null)
return handlers.FirstOrDefault();
return handlerForDefaultKey;
}
示例2: SelectHandler
public virtual IHandler SelectHandler(string key, Type service, IHandler[] handlers)
{
if (key == _originalKey)
{
var replacementHandler = handlers.FirstOrDefault(handler => handler.ComponentModel.Name == _replacementKey);
if (replacementHandler != null) return replacementHandler;
}
var originalHandler = handlers.FirstOrDefault(handler => handler.ComponentModel.Name == _originalKey);
if (originalHandler != null) return originalHandler;
throw new NotSupportedException(string.Format("Tried to get key {0} from HandlerSelector for type {1} but found no matching handler", key, _serviceType.Name));
}
示例3: SelectHandler
public IHandler SelectHandler(string key, Type service, IHandler[] handlers)
{
foreach (IHandler handler in handlers)
{
if (!IsProxy && (handler.ComponentModel.Implementation == typeof(AddCalculator)))
return handler;
if (IsProxy && (handler.ComponentModel.Implementation == typeof(ProxyCalculator)))
return handler;
}
return handlers.FirstOrDefault();
}
示例4: SelectHandler
public IHandler SelectHandler(string key, Type service, IHandler[] handlers)
{
return handlers.FirstOrDefault(h => MatchHandler(service, h));
}