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


C# IReadOnlyList.FirstOrDefault方法代码示例

本文整理汇总了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));
        }
开发者ID:gro-ove,项目名称:actools,代码行数:7,代码来源:WheelHShifterButtonEntry.cs

示例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);
            }
        }
开发者ID:reicheltp,项目名称:website,代码行数:35,代码来源:NamespaceViewmodel.cs

示例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);
        }
开发者ID:narutoswj,项目名称:mongo-csharp-driver,代码行数:57,代码来源:BulkWriteBatchResult.cs

示例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);
        }
开发者ID:rdumont,项目名称:changey,代码行数:12,代码来源:GitHubClient.cs

示例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();
        }
开发者ID:Halifa,项目名称:xunit,代码行数:13,代码来源:CommandLine.cs

示例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();
        }
开发者ID:andschwa,项目名称:coreclr.xunit,代码行数:14,代码来源:CommandLine.cs

示例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);
     }
 }
开发者ID:electrobreath,项目名称:musicmanager,代码行数:14,代码来源:MusicPropertiesController.cs

示例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();
                }
            }
        }
开发者ID:roubachof,项目名称:devices.xunit,代码行数:24,代码来源:DeviceRunner.cs

示例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));
            }
        }
开发者ID:nicholjy,项目名称:stylize,代码行数:17,代码来源:JsonOptionApplier.cs

示例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;
		}
开发者ID:mono,项目名称:monodevelop,代码行数:31,代码来源:MonoDevelopWorkspace.cs

示例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();
                }
            }
        }
开发者ID:Esri,项目名称:military-symbol-editor-addin-wpf,代码行数:26,代码来源:MilitaryFieldsInspectorModel.cs

示例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;
            }
        }
开发者ID:Esri,项目名称:military-symbol-editor-addin-wpf,代码行数:56,代码来源:MilitaryFieldsInspectorModel.cs

示例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;
         }
     }
 }
开发者ID:lorenzofar,项目名称:SLI,代码行数:20,代码来源:Interpret.xaml.cs

示例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();
     }
 }
开发者ID:MotorViper,项目名称:FormGenerator,代码行数:23,代码来源:HtmlGenerator.cs

示例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;
		}
开发者ID:NerdyDuck,项目名称:NerdyDuck.ParameterValidation,代码行数:57,代码来源:ParameterValidator.cs


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