本文整理汇总了C#中IReadOnlyCollection.First方法的典型用法代码示例。如果您正苦于以下问题:C# IReadOnlyCollection.First方法的具体用法?C# IReadOnlyCollection.First怎么用?C# IReadOnlyCollection.First使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类IReadOnlyCollection
的用法示例。
在下文中一共展示了IReadOnlyCollection.First方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: GenerateNext
private static Func<IMessage, Task<object>> GenerateNext(
BusSettings busSettings,
IDependencyScope dependencyScope,
IReadOnlyCollection<Type> pipelineHandlerTypes,
IEnumerable<Type> leftHandlerTypes
)
{
return (async message => {
if (message == null) {
throw new NullMessageTypeException();
}
if (!pipelineHandlerTypes.Any()) {
return await RunLeafHandlers(busSettings, dependencyScope, leftHandlerTypes, message);
}
var head = pipelineHandlerTypes.First();
var nextHandler = (IPipelineHandler)dependencyScope.GetService(head);
var tail = pipelineHandlerTypes.Skip(1).ToList();
var nextFunction = GenerateNext(busSettings, dependencyScope, tail, leftHandlerTypes);
return await nextHandler.Handle(nextFunction, message);
});
}
示例2: CombinedNodeCommandWrapper
public CombinedNodeCommandWrapper(IViewModelServiceProvider serviceProvider, string name, IReadOnlyCollection<ModelNodeCommandWrapper> commands)
: base(serviceProvider)
{
if (commands == null) throw new ArgumentNullException(nameof(commands));
if (commands.Count == 0) throw new ArgumentException(@"The collection of commands to combine is empty", nameof(commands));
if (commands.Any(x => !ReferenceEquals(x.NodeCommand, commands.First().NodeCommand))) throw new ArgumentException(@"The collection of commands to combine cannot contain different node commands", nameof(commands));
this.commands = commands;
Name = name;
}
示例3: CombinedNodeCommandWrapper
public CombinedNodeCommandWrapper(IViewModelServiceProvider serviceProvider, string name, string observableNodePath, ObservableViewModelIdentifier identifier, IReadOnlyCollection<ModelNodeCommandWrapper> commands)
: base(serviceProvider, null)
{
if (commands == null) throw new ArgumentNullException("commands");
if (commands.Count == 0) throw new ArgumentException(@"The collection of commands to combine is empty", "commands");
if (commands.Any(x => !ReferenceEquals(x.NodeCommand, commands.First().NodeCommand))) throw new ArgumentException(@"The collection of commands to combine cannot contain different node commands", "commands");
service = serviceProvider.Get<ObservableViewModelService>();
this.commands = commands;
this.name = name;
this.identifier = identifier;
this.serviceProvider = serviceProvider;
ObservableNodePath = observableNodePath;
}
示例4: GetCommonRoot
private static string GetCommonRoot(IReadOnlyCollection<string> normalizedPaths)
{
if (normalizedPaths.Count == 0)
return string.Empty;
var maxPathLength = normalizedPaths.Max(s => s.Length);
var longestPath = normalizedPaths.First(p => p.Length == maxPathLength)
.Split(Path.DirectorySeparatorChar)
.Select(p => p + Path.DirectorySeparatorChar);
var result = string.Empty;
foreach (var path in longestPath)
{
// If this is the first path segment we need check whether it's a valid
// prefix of all paths.
//
// If it's not then it means there is no common root.
if (result.Length == 0 && normalizedPaths.All(p => p.StartsWith(path)))
{
result = path;
continue;
}
// We already have a path.
//
// In that case the combined path must be a valid prefix.
var fullPath = Path.Combine(result, path);
if (normalizedPaths.All(p => p.StartsWith(fullPath)))
{
result = fullPath;
continue;
}
break;
}
return result;
}
示例5: AlbumPhoto
private static AlbumPhoto AlbumPhoto(IReadOnlyCollection<Photo> photos, AlbumPhoto previous)
{
if (photos.Count == 0)
{
return null;
}
var head = photos.First();
var tail = photos.Skip(1).ToList();
var headPhoto = new AlbumPhoto
{
Photo = head,
Previous = previous
};
var tailPhotos = AlbumPhoto(tail, headPhoto);
headPhoto.Next = tailPhotos;
return headPhoto;
}
示例6: AfterShapesAdded
void AfterShapesAdded(IReadOnlyCollection<Shape> newShapes)
{
_selectedShapes.Clear();
_selectedShapes.Add(_partialSelShape);
if (newShapes.Count == 1) {
var s = newShapes.First();
_partialSelShape = s;
_focusShape = s;
}
}
示例7: PopulateStatesAsync
public async Task PopulateStatesAsync()
{
var items = new List<ComboBoxItemValue> { new ComboBoxItemValue() { Id = string.Empty, Value = _resourceLoader.GetString("State") } };
var states = await _locationService.GetStatesAsync();
items.AddRange(states.Select(state => new ComboBoxItemValue() { Id = state, Value = state }));
States = new ReadOnlyCollection<ComboBoxItemValue>(items);
// Select the first item on the list
// But disable validation first, because we don't want to fire it at this point
_address.IsValidationEnabled = false;
_address.State = States.First().Id;
_address.IsValidationEnabled = true;
}
示例8: SmoothPath
private List<Node> SmoothPath(IReadOnlyCollection<Node> path)
{
var currentNode = path.Last();
var smoothPath = new List<Node> {currentNode};
for (var i = path.Count - 2; i >= 0; i--)
{
if (!IsValidNode(path.ElementAt(i), currentNode))
{
smoothPath.Add(path.ElementAt(i + 1));
currentNode = path.ElementAt(i + 1);
}
}
smoothPath.Add(path.First());
return smoothPath;
}
示例9: PopulateStatesAsync
public async Task PopulateStatesAsync()
{
string errorMessage = string.Empty;
try
{
var states = await _locationService.GetStatesAsync();
var items = new List<ComboBoxItemValue> { new ComboBoxItemValue() { Id = string.Empty, Value = _resourceLoader.GetString("State") } };
items.AddRange(states.Select(state => new ComboBoxItemValue() { Id = state, Value = state }));
States = new ReadOnlyCollection<ComboBoxItemValue>(items);
// Select the first item on the list
// But disable validation first, because we don't want to fire validation at this point
_address.IsValidationEnabled = false;
_address.State = States.First().Id;
_address.IsValidationEnabled = true;
}
catch (Exception ex)
{
errorMessage = string.Format(CultureInfo.CurrentCulture,
_resourceLoader.GetString("GeneralServiceErrorMessage"),
Environment.NewLine,
ex.Message);
}
if (!string.IsNullOrWhiteSpace(errorMessage))
{
await _alertMessageService.ShowAsync(errorMessage, _resourceLoader.GetString("ErrorServiceUnreachable"));
}
}
示例10: AggregateActionItems
private static IActionItem AggregateActionItems(IReadOnlyCollection<IActionItem> actionItems, string name = null)
{
if (actionItems.Count == 1)
{
var actionItem = actionItems.First();
if (!string.IsNullOrEmpty(name))
actionItem.Name = name;
return actionItem;
}
return new AggregateActionItem(name, actionItems.ToArray());
}
示例11: RequestAdd
public void RequestAdd (IReadOnlyCollection<Contracts.Options> options)
{
foreach (var vm in _optionsViewModelFactory.Create (options, _generalOptions))
_options.Add (vm);
if (options.Any())
ShowProfile (options.First().Id);
}
示例12: Combine
public static Stream Combine(IReadOnlyCollection<MemoryStream> imageStreams)
{
if (imageStreams == null) throw new ArgumentNullException("imageStreams");
if (!imageStreams.Any()) throw new ArgumentException("imageStream cannot be empty.");
var images = imageStreams.Select(Image.FromStream);
var outputStream = new MemoryStream();
// Handle the case where only one image stream is provided.
if (imageStreams.Count == 1)
{
imageStreams.First().CopyTo(outputStream);
}
else
{
using (var combinedImage = images.Aggregate((image1, image2) =>
{
try
{
return image1.Combine(image2, 0);
}
finally
{
image1.Dispose();
image2.Dispose();
}
}))
{
combinedImage.Save(outputStream, ImageFormat.Png);
}
}
return outputStream;
}
示例13: GetDefaultLayout
private static ILayoutInfo GetDefaultLayout(IReadOnlyCollection<ILayoutInfo> layoutList)
{
if (layoutList == null || layoutList.Count == 0)
return null;
var item =
layoutList.FirstOrDefault(
l => (l.IsDefault ?? false) && (l.AccountId == Utils.CurrentUserAccountId || (l.AccountId == 0 && Utils.CurrentUserAccountId == -1)));
if (item != null)
return item;
if (layoutList.Any(l => l.IsAdminDefault ?? false))
return layoutList.First(l => l.IsAdminDefault ?? false);
return layoutList.First();
}
示例14: IsStraight
private bool IsStraight(IReadOnlyCollection<int> list)
{
return list.Count == 5 && list.Distinct().Count() == 5 && list.First() == _start && list.Last() == _end;
}
示例15: CaptureHeaders
private Dictionary<string, string[]> CaptureHeaders(IReadOnlyCollection<string> captureHeaders, IHeaderDictionary headers)
{
Dictionary<string, string[]> capturedHeaders = null;
if (captureHeaders != null && captureHeaders.Any())
{
capturedHeaders = new Dictionary<string, string[]>();
if (captureHeaders.First() == "*")
{
foreach (KeyValuePair<string, string[]> kvp in headers)
{
string[] existingHeader;
if (capturedHeaders.TryGetValue(kvp.Key, out existingHeader))
{
existingHeader = existingHeader.Union(kvp.Value).ToArray();
}
else
{
existingHeader = kvp.Value;
}
capturedHeaders[kvp.Key] = existingHeader;
}
}
else
{
foreach (string headerName in captureHeaders)
{
string[] values;
if (headers.TryGetValue(headerName, out values))
{
capturedHeaders.Add(headerName, values);
}
}
}
}
return capturedHeaders;
}