本文整理汇总了C#中IReadOnlyList.FirstOrDefault方法的典型用法代码示例。如果您正苦于以下问题:C# IReadOnlyList.FirstOrDefault方法的具体用法?C# IReadOnlyList.FirstOrDefault怎么用?C# IReadOnlyList.FirstOrDefault使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类IReadOnlyList
的用法示例。
在下文中一共展示了IReadOnlyList.FirstOrDefault方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Load
public override void Load(IniFile ini, IReadOnlyList<IDirectInputDevice> devices) {
var section = ini["SHIFTER"];
var deviceId = section.GetInt("JOY", -1);
var device = devices.FirstOrDefault(x => x.OriginalIniIds.Contains(deviceId));
Input = device?.GetButton(section.GetInt(Id, -1));
}
示例2: NamespaceViewModel
public NamespaceViewModel(IReadOnlyList<DocumentedNamespace> namespaces)
{
if (namespaces.Count == 0)
{
throw new ArgumentException("No namespaces in list.");
}
Data = namespaces[0];
Name = Data.Name;
var namespaceWithSummary = namespaces.FirstOrDefault(x => x.Summary != null);
if (namespaceWithSummary != null)
{
Summary = namespaceWithSummary.Summary;
}
Classes = new List<DocumentedType>();
Interfaces = new List<DocumentedType>();
foreach (var @namespace in namespaces)
{
var classes = @namespace.Types.Where(x => x.Definition.IsClass && !IsExtensionMethodClass(x)).ToArray();
Classes.AddRange(classes);
var interfaces = @namespace.Types.Where(x => x.Definition.IsInterface).ToArray();
Interfaces.AddRange(interfaces);
}
// For child namespaces, just get them from the first one
// since they're going to be the same anyway.
Namespaces = new List<DocumentedNamespace>();
foreach (var childNamespace in Data.Tree.Children)
{
Namespaces.Add(childNamespace.Namespace);
}
}
示例3: Create
// static methods
public static BulkWriteBatchResult Create(
bool isOrdered,
IReadOnlyList<WriteRequest> requests,
BsonDocument writeCommandResponse,
IndexMap indexMap)
{
var writeErrors = CreateWriteErrors(writeCommandResponse);
var writeConcernError = CreateWriteConcernError(writeCommandResponse);
var processedRequests = CreateProcessedRequests(requests, writeErrors, isOrdered);
var unprocessedRequests = CreateUnprocessedRequests(requests, writeErrors, isOrdered);
var upserts = CreateUpserts(writeCommandResponse);
var n = writeCommandResponse.GetValue("n", 0).ToInt64();
var matchedCount = 0L;
var deletedCount = 0L;
var insertedCount = 0L;
long? modifiedCount = 0L;
var firstRequest = requests.FirstOrDefault();
if (firstRequest != null)
{
switch (firstRequest.RequestType)
{
case WriteRequestType.Delete:
deletedCount = n;
break;
case WriteRequestType.Insert:
insertedCount = n;
break;
case WriteRequestType.Update:
matchedCount = n - upserts.Count();
BsonValue nModified;
if (writeCommandResponse.TryGetValue("nModified", out nModified))
{
modifiedCount = nModified.ToInt64();
}
else
{
modifiedCount = null;
}
break;
}
}
return new BulkWriteBatchResult(
requests.Count,
processedRequests,
unprocessedRequests,
matchedCount,
deletedCount,
insertedCount,
modifiedCount,
upserts,
writeErrors,
writeConcernError,
indexMap);
}
示例4: GetTagAsync
public async Task<GitTag> GetTagAsync(string tagName)
{
_allTagReferences = _allTagReferences ?? await _client.GitDatabase.Reference
.GetAllForSubNamespace(_owner, _repository, "tags");
var targetRef = "refs/tags/" + tagName;
var desiredTag = _allTagReferences.FirstOrDefault(tag => tag.Ref == targetRef);
if (desiredTag == null)
throw new ApplicationException("Tag not found: " + tagName);
return await _client.GitDatabase.Tag.Get(_owner, _repository, desiredTag.Object.Sha);
}
示例5: CommandLine
protected CommandLine(IReadOnlyList<IRunnerReporter> reporters, string[] args, Predicate<string> fileExists = null)
{
this.reporters = reporters;
if (fileExists == null)
fileExists = File.Exists;
for (var i = args.Length - 1; i >= 0; i--)
arguments.Push(args[i]);
Project = Parse(fileExists);
Reporter = reporters.FirstOrDefault(r => r.IsEnvironmentallyEnabled) ?? Reporter ?? new DefaultRunnerReporter();
}
示例6: CommandLine
protected CommandLine(IReadOnlyList<IRunnerReporter> reporters, string[] args, Predicate<string> fileExists = null)
{
_reporters = reporters;
if (fileExists == null)
fileExists = fileName => File.Exists(fileName);
for (var i = args.Length - 1; i >= 0; i--)
_arguments.Push(args[i]);
DesignTimeTestUniqueNames = new List<string>();
Project = Parse(fileExists);
Reporter = reporters.FirstOrDefault(r => r.IsEnvironmentallyEnabled) ?? Reporter ?? new DefaultRunnerReporter();
}
示例7: SelectMusicFiles
public void SelectMusicFiles(IReadOnlyList<MusicFile> musicFiles)
{
// Do not wait for the operation to complete. Continue immediately.
SaveCurrentSelectedFileAsync().IgnoreResult();
if (musicFiles.Count() <= 1)
{
MusicPropertiesViewModel.MusicFile = musicFiles.FirstOrDefault();
}
else
{
MusicPropertiesViewModel.MusicFile = musicFileContext.CreateFromMultiple(musicFiles);
}
}
示例8: Run
public async Task Run(IReadOnlyList<AssemblyRunInfo> runInfos, string message = null)
{
using (await executionLock.LockAsync())
{
if (message == null)
message = runInfos.Count > 1 || runInfos.FirstOrDefault()
?.TestCases.Count > 1 ? "Run Multiple Tests" :
runInfos.FirstOrDefault()
?.TestCases.FirstOrDefault()
?.DisplayName;
if (!await resultChannel.OpenChannel(message))
return;
try
{
await RunTests(() => runInfos);
}
finally
{
await resultChannel.CloseChannel();
}
}
}
示例9: JsonOptionApplier
public JsonOptionApplier(
string featureName, IDictionary<string, JToken> jsonOptions, IReadOnlyList<IOption> supportedOptions)
{
this.optionValues = new Dictionary<OptionKey, object>();
foreach (KeyValuePair<string, JToken> jsonOption in jsonOptions)
{
IOption option = supportedOptions.FirstOrDefault(
o => o.Feature.Equals(featureName) && o.Name.Equals(jsonOption.Key));
if (option == null)
{
throw new StylizeConfigurationException(
$"Option {featureName}:{jsonOption.Key} in the configuration file does not match any exported options.");
}
this.optionValues.Add(new OptionKey(option), jsonOption.Value.ToObject(option.Type));
}
}
示例10: DetermineFilePath
string DetermineFilePath (DocumentId id, string name, string filePath, IReadOnlyList<string> docFolders, string defaultFolder, bool createDirectory = false)
{
var path = filePath;
if (string.IsNullOrEmpty (path)) {
var monoProject = GetMonoProject (id.ProjectId);
// If the first namespace name matches the name of the project, then we don't want to
// generate a folder for that. The project is implicitly a folder with that name.
IEnumerable<string> folders;
if (docFolders.FirstOrDefault () == monoProject.Name) {
folders = docFolders.Skip (1);
} else {
folders = docFolders;
}
if (folders.Any ()) {
string baseDirectory = Path.Combine (monoProject.BaseDirectory, Path.Combine (folders.ToArray ()));
try {
if (createDirectory && !Directory.Exists (baseDirectory))
Directory.CreateDirectory (baseDirectory);
} catch (Exception e) {
LoggingService.LogError ("Error while creating directory for a new file : " + baseDirectory, e);
}
path = Path.Combine (baseDirectory, name);
} else {
path = Path.Combine (defaultFolder, name);
}
}
return path;
}
示例11: GetDomainAndPopulateList
private void GetDomainAndPopulateList(IReadOnlyList<Field> fields, string fieldName, ObservableCollection<DomainCodedValuePair> memberCodedValueDomains, bool orderbyName = false)
{
ArcGIS.Core.Data.Field foundField = fields.FirstOrDefault(field => field.Name == fieldName);
//Clear out any old values
memberCodedValueDomains.Clear();
if (foundField != null)
{
Domain domain = foundField.GetDomain();
var codedValueDomain = domain as CodedValueDomain;
SortedList<object, string> codedValuePairs = codedValueDomain.GetCodedValuePairs();
foreach (KeyValuePair<object, string> pair in codedValuePairs)
{
DomainCodedValuePair domainObjectPair = new DomainCodedValuePair(pair.Key, pair.Value);
memberCodedValueDomains.Add(domainObjectPair);
}
if (orderbyName)
{
//Order the collection alphabetically by the names, rather than the default by the code
memberCodedValueDomains.Sort();
}
}
}
示例12: CheckLabelFieldsExistence
public void CheckLabelFieldsExistence(IReadOnlyList<ArcGIS.Core.Data.Field> fields)
{
DateTimeValidFieldExists = Visibility.Collapsed;
if (fields.FirstOrDefault(field => field.Name == "datetimevalid") != null)
{
DateTimeValidFieldExists = Visibility.Visible;
}
DateTimeExpiredFieldExists = Visibility.Collapsed;
if (fields.FirstOrDefault(field => field.Name == "datetimeexpired") != null)
{
DateTimeExpiredFieldExists = Visibility.Visible;
}
UniqueDesignationFieldExists = Visibility.Collapsed;
if (fields.FirstOrDefault(field => field.Name == "uniquedesignation") != null)
{
UniqueDesignationFieldExists = Visibility.Visible;
}
TypeFieldExists = Visibility.Collapsed;
if (fields.FirstOrDefault(field => field.Name == "type") != null)
{
TypeFieldExists = Visibility.Visible;
}
CommonIdentifierFieldExists = Visibility.Collapsed;
if (fields.FirstOrDefault(field => field.Name == "commonidentifier") != null)
{
CommonIdentifierFieldExists = Visibility.Visible;
}
SpeedFieldExists = Visibility.Collapsed;
if (fields.FirstOrDefault(field => field.Name == "speed") != null)
{
SpeedFieldExists = Visibility.Visible;
}
StaffCommentsFieldExists = Visibility.Collapsed;
if (fields.FirstOrDefault(field => field.Name == "staffcomment") != null)
{
StaffCommentsFieldExists = Visibility.Visible;
}
AdditionalInformationFieldExists = Visibility.Collapsed;
if (fields.FirstOrDefault(field => field.Name == "additionalinformation") != null)
{
AdditionalInformationFieldExists = Visibility.Visible;
}
HigherFormationFieldExists = Visibility.Collapsed;
if (fields.FirstOrDefault(field => field.Name == "higherformation") != null)
{
HigherFormationFieldExists = Visibility.Visible;
}
}
示例13: OnFilesOpenPicked
private async void OnFilesOpenPicked(IReadOnlyList<StorageFile> files)
{
// Load picked file
if (files.Count > 0)
{
// Check if image and pick first file to show
var imageFile = files.FirstOrDefault(f => SupportedImageFileTypes.Contains(f.FileType.ToLower()));
if (imageFile != null)
{
// Use WriteableBitmapEx to easily load from a stream
using (var stream = await imageFile.OpenReadAsync())
{
originalBitmap = await new WriteableBitmap(1, 1).FromStream(stream);
}
Image.Source = originalBitmap;
AppBarBtnEdit.IsEnabled = true;
AppBarBtnSave.IsEnabled = false;
}
}
}
示例14: AddProperty
/// <summary>
/// Adds a property for a styles.
/// </summary>
/// <param name="parameters">Calculation parameters.</param>
/// <param name="property">The property being added.</param>
/// <param name="styles">The styles, needed in case the current style has a BasedOn property.</param>
private void AddProperty(TokenTree parameters, TokenTree property, IReadOnlyList<TokenTree> styles)
{
if (property.Name == "BasedOn")
{
property = styles.FirstOrDefault(x => x["Name"] == property.Value.Text);
AddProperties(styles, parameters, property);
}
else
{
_sb.Append(" ")
.Append(property.Name.CamelCaseToHyphenated())
.Append(": ")
.Append(ProcessTokens(property.Value, new TokenTreeList(parameters)))
.Append(";")
.AppendLine();
}
}
示例15: GetValidationResult
/// <summary>
/// Validates a value according to the specified constraints.
/// </summary>
/// <param name="value">The value to validate.</param>
/// <param name="dataType">The data type of <paramref name="value"/>.</param>
/// <param name="constraints">A list of <see cref="Constraint"/>s to validate <paramref name="value"/> against.</param>
/// <param name="memberName">The name of the property or control containing the <paramref name="value"/> to validate.</param>
/// <param name="displayName">The display name of the control that contains or displays the <paramref name="value"/> to validate. May be <see langword="null"/>.</param>
/// <returns>An enumeration of <see cref="ParameterValidationResult"/>s. If the enumeration is empty, no validation error was found.</returns>
/// <exception cref="CodedArgumentOutOfRangeException"><paramref name="dataType"/> is <see cref="ParameterDataType.None"/>.</exception>
/// <exception cref="CodedArgumentNullOrEmptyException"><paramref name="memberName"/> is <see langword="null"/> or empty.</exception>
public IEnumerable<ParameterValidationResult> GetValidationResult(object value, ParameterDataType dataType, IReadOnlyList<Constraint> constraints, string memberName, string displayName)
{
if (dataType == ParameterDataType.None)
{
throw new CodedArgumentOutOfRangeException(Errors.CreateHResult(ErrorCodes.ParameterValidator_GetValidationResult_DataTypeNone), nameof(dataType), Properties.Resources.Global_ParameterDataType_None);
}
if (string.IsNullOrEmpty(memberName))
{
throw new CodedArgumentNullOrEmptyException(Errors.CreateHResult(ErrorCodes.ParameterValidator_GetValidationResult_NameNullEmpty), nameof(memberName));
}
if (constraints == null)
{
constraints = NoConstraints;
}
if (displayName == null)
{
displayName = memberName;
}
OnValidating(value, dataType, constraints, memberName, displayName);
List<ParameterValidationResult> ReturnValue = new List<ParameterValidationResult>();
// Use constraints only on non-null values
if (value == null)
{
if (constraints.FirstOrDefault(c => c.Name == Constraint.NullConstraintName) == null)
{
ReturnValue.Add(new ParameterValidationResult(Errors.CreateHResult(ErrorCodes.ParameterValidator_GetValidationResult_ValueNull), string.Format(Properties.Resources.ParameterValidator_Validate_ValueNull, displayName), memberName, new Constraints.NullConstraint()));
}
}
else
{
foreach (Constraint constraint in constraints)
{
ReturnValue.AddRange(constraint.Validate(value, dataType, memberName, displayName));
}
}
if (ReturnValue.Count != 0)
{
OnValidationError(value, dataType, constraints, memberName, displayName, ReturnValue);
}
return ReturnValue;
}