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


C# ICollection.Single方法代码示例

本文整理汇总了C#中ICollection.Single方法的典型用法代码示例。如果您正苦于以下问题:C# ICollection.Single方法的具体用法?C# ICollection.Single怎么用?C# ICollection.Single使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在ICollection的用法示例。


在下文中一共展示了ICollection.Single方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: Compute

 private void Compute(string expression, string key, ICollection<IGrouping<string, ParentChildCategory>> grouping, ICollection<string> categoryList)
 {
     if (grouping.All(g => g.Key != key) && expression.StartsWith(Separator))
         categoryList.Add(expression.TrimStart(Separator.ToArray()));
     else if(grouping.Any(g => g.Key == key))
         grouping.Single(g => g.Key == key).ToList().ForEach(c => Compute(expression + Separator + c.Child, c.Child, grouping, categoryList));
 }
开发者ID:dmcliver,项目名称:DonateMe,代码行数:7,代码来源:CategoryHierarchyServiceImpl.cs

示例2: VerifyGoodScriptWasReturned

 private static void VerifyGoodScriptWasReturned(ICollection<ScriptFile> scripts)
 {
     Assert.AreEqual(1, scripts.Count, "Expected 1 valid script");
     var scriptFile = scripts.Single();
     Assert.AreEqual(DatabaseObjectType.Procedure, scriptFile.ScriptObject.ObjectType);
     Assert.AreEqual(goodPrcFileName.Replace(".sql", ""), scriptFile.ScriptObject.ObjectName);
     Assert.AreEqual(databaseName, scriptFile.ScriptObject.DatabaseName);
 }
开发者ID:Zocdoc,项目名称:ZocBuild.Database,代码行数:8,代码来源:GitScriptRepositoryTests.cs

示例3: CacheRoutes

 private static void CacheRoutes(ICollection<Route> routes)
 {
     var retrievedRouteIds = from r in routes select r.Id;
     using(var db = MadMetroDataContext.NewInstance())
     {
         var existingRouteIds = from r in db.Routes where !retrievedRouteIds.Contains(r.Id) select r.Id;
         foreach(var newRouteId in retrievedRouteIds.Except(existingRouteIds))
         {
             db.Routes.InsertOnSubmit(routes.Single(r => r.Id == newRouteId));
         }
         db.SubmitChanges();
     }
 }
开发者ID:bgourlie,项目名称:MadCity-Metro-Times,代码行数:13,代码来源:RouteService.cs

示例4: FillPhones

		public void FillPhones(ICollection<Phone> phones, PhonesViewModel phonesViewModel)
		{
			if (phonesViewModel != null)
			{
				var phonesArray = phones.ToArray();
				foreach (var phone in phonesArray)
				{
					if (!phonesViewModel.PhoneItems.Any(pi => pi.Id == phone.Id.ToString()))
					{
						phones.Remove(phone);
					}
				}
				foreach (var phoneItem in phonesViewModel.PhoneItems)
				{
					int phoneItemId;
					if (Int32.TryParse(phoneItem.Id, out phoneItemId))
					{
						var phone = phones.Single(p => p.Id == phoneItemId);
						if (!String.IsNullOrWhiteSpace(phoneItem.Number))
						{
							phone.Number = phoneItem.Number;
							phone.Type = phoneItem.PhoneType;
						}
						else
						{
							phones.Remove(phone);
						}
					}
					else
					{
						if (!String.IsNullOrWhiteSpace(phoneItem.Number))
						{
							var phone = new Phone();
							phone.Number = phoneItem.Number;
							phone.Type = phoneItem.PhoneType;
							phones.Add(phone);
						}
					}
				}
			}
		}
开发者ID:evkap,项目名称:DVS,代码行数:41,代码来源:PhoneManager.cs

示例5: BuildVacationRequests

        public static List<VacationRequestEntity> BuildVacationRequests(ICollection<EmployeeEntity> employees)
        {
            var mihai = employees.Single(x => x.Firstname == "Mihai");
            var costin = employees.Single(x => x.Firstname == "Costin");
            var ioana = employees.Single(x => x.Firstname == "Ioana");

            return new List<VacationRequestEntity>
            {
                // mihai's requests
                new VacationRequestEntity
                {
                    State = VacationRequestState.Approved,
                    Employee = mihai,
                    CreationDate = StaticMonth<January>.The1st,
                    StartDate = StaticMonth<January>.The3rd,
                    EndDate = StaticMonth<January>.The3rd,
                },
                new VacationRequestEntity
                {
                    State = VacationRequestState.Submitted,
                    Employee = mihai,
                    CreationDate = StaticMonth<August>.The10th,
                    StartDate = StaticMonth<August>.The13th,
                    EndDate = StaticMonth<August>.The14th,
                },
                // costin's requests
                new VacationRequestEntity
                {
                    State = VacationRequestState.Approved,
                    Employee = costin,
                    CreationDate = StaticMonth<January>.The3rd,
                    StartDate = StaticMonth<January>.The3rd,
                    EndDate = StaticMonth<January>.The3rd,
                },
                new VacationRequestEntity
                {
                    State = VacationRequestState.Submitted,
                    Employee = costin,
                    CreationDate = StaticMonth<September>.The24th,
                    StartDate = StaticMonth<September>.The28th,
                    EndDate = StaticMonth<October>.The1st,
                },
                // ioana's requests
                new VacationRequestEntity
                {
                    State = VacationRequestState.Approved,
                    Employee = ioana,
                    CreationDate = StaticMonth<January>.The21st,
                    StartDate = StaticMonth<February>.The4th,
                    EndDate = StaticMonth<February>.The4th,
                },
            };
        }
开发者ID:stonemonkey,项目名称:VacationManager,代码行数:53,代码来源:TestDataBuilder.cs

示例6: SetCacheVaryByParams

 public void SetCacheVaryByParams(ICollection<string> varyByParams)
 {
     if (varyByParams.Count == 1 && "none".Equals(varyByParams.Single(), StringComparison.OrdinalIgnoreCase))
     {
         _httpResponse.Cache.VaryByParams.IgnoreParams = true;
         return;
     }
     foreach (var param in varyByParams)
     {
         _httpResponse.Cache.VaryByParams[param] = true;
     }
 }
开发者ID:ChrisAnn,项目名称:Simple.Web,代码行数:12,代码来源:ResponseWrapper.cs

示例7: Sample

 /// <summary>
 /// Returns a sample of the first ten items in the given collection,
 /// or "empty." if there are no items in the collection.
 /// </summary>
 protected virtual string Sample(ICollection<object> items)
 {
     switch (items.Count)
     {
         case 0:
             return "empty.";
         case 1:
             return "[" + items.Single() + "]";
         default:
             return "[{SampleItems:{0.BR}    {}|,}{BR}]".FormatSmart(new { SampleItems = SampleItems(items), BR });
     }
 }
开发者ID:soxtoby,项目名称:EasyAssertions,代码行数:16,代码来源:CollectionFailureMessage.cs

示例8: GetActivityRecordsRepositoryFake

        private static IActivityRecordsRepository GetActivityRecordsRepositoryFake(ICollection<ActivityRecord> records)
        {
            var activityRecordsRepository = A.Fake<IActivityRecordsRepository>();

            A.CallTo(() => activityRecordsRepository.GetLastRecord()).ReturnsLazily(records.LastOrDefault);

            A.CallTo(() => activityRecordsRepository.Add(A<ActivityRecord>._))
                .Invokes(call => records.Add(call.Arguments.Get<ActivityRecord>(0)));

            A.CallTo(() => activityRecordsRepository.Update(A<ActivityRecord>._)).Invokes(
                call =>
                {
                    var record = call.Arguments.Get<ActivityRecord>(0);
                    var existingRecord = records.Single(r => r.ActivityRecordId == record.ActivityRecordId);

                    existingRecord.Activity = record.Activity;
                    existingRecord.StartTime = record.StartTime;
                    existingRecord.EndTime = record.EndTime;
                    existingRecord.Idle = record.Idle;
                });

            return activityRecordsRepository;
        }
开发者ID:NightyCode,项目名称:GoHome,代码行数:23,代码来源:UserActivityTrackerTests.cs

示例9: DownloadSubtitles

        private static void DownloadSubtitles(ICollection<SubtitleSelection> subs)
        {
            if (subs.Count == 0)
            {
                return;
            }

            var files = client.DownloadSubtitles(subs.Select(s => s.Selection.Id).ToArray());

            foreach (var file in files)
            {
                var sub = subs.Single(s => s.Selection.Id == file.Id);
                var path = Path.ChangeExtension(sub.File, sub.Selection.FileFormat);
                var data = Convert.FromBase64String(file.Base64Data);

                File.WriteAllBytes(path, Gzip.Decompress(data));
                Console.WriteLine([email protected]"Downloaded ""{path}""");
            }
        }
开发者ID:softctrl,项目名称:subtle-1,代码行数:19,代码来源:Program.cs

示例10: IsWatchListChanged

        /// <summary>
        /// Determines whether a watch list has changed based upon the
        /// specified current selections.
        /// </summary>
        /// <param name="currentSelections">The current selections.</param>
        /// <param name="databaseSelections">The database selections.</param>
        /// <returns>A boolean indicating if the current selections are different from those in the database.</returns>
        private static bool IsWatchListChanged(ICollection<NameValuesType> currentSelections, ICollection<NameValuesType> databaseSelections)
        {
            // the watch list has not been saved to the database so return
            // false
            if (databaseSelections == null)
                return false;

            // if the number of selected metrics are different then the list
            // has changed
            if (currentSelections.Count != databaseSelections.Count)
                return true;

            // if there is an item name in the current selections that is not
            // contained in the database selections then the list has changed
            if (currentSelections.Any(currentSelection => databaseSelections.Any(data => data.Name != currentSelection.Name)))
            {
                return true;
            }

            // now that we know the names in each collection are the same the
            // count of the values for each name needs to be checked
            if (currentSelections.Any(currentSelection => databaseSelections.Single(selection => selection.Name == currentSelection.Name).Values.Count != currentSelection.Values.Count))
            {
                return true;
            }

            // we will only get here if the number of selections are the same,
            // and the names in each list are the same, and the counts of the
            // selected values in each list are the same
            // when this is the case each value needs to be checked to
            // determine if any of the values are different
            return
                currentSelections.Any(
                    currentSelection =>
                        databaseSelections.Single(selection => selection.Name == currentSelection.Name)
                            .Values.Any(databaseValue => currentSelection.Values.All(value => value != databaseValue)));
        }
开发者ID:sybrix,项目名称:EdFi-App,代码行数:44,代码来源:MetricsBasedWatchListDataProvider.cs

示例11: BasicViewApplicable

        private bool BasicViewApplicable(ICollection<XElement> functionCallsEvaluated)
        {
            // Basic view is enabled if
            // - Only one function is being edited
            // - here's no parameters defined as function calls
            // - And there no required parameters without widgets

            if (MultiMode || IsWidgetSelection || functionCallsEvaluated.Count != 1)
            {
                return false;
            }

            var functionMarkup = functionCallsEvaluated.Single();

            if (functionMarkup
                 .Elements()
                 .Any(childElement => childElement.Elements().Any(e => e.Name.LocalName == "function")))
            {
                return false;
            }

            string functionName = (string)functionMarkup.Attribute("name");
            var function = FunctionFacade.GetFunction(functionName);

            if (function == null)
            {
                return false;
            }

            return !function.ParameterProfiles.Any(p => p.IsRequired && p.WidgetFunction == null && !p.IsInjectedValue);
        }
开发者ID:DBailey635,项目名称:C1-CMS,代码行数:31,代码来源:editFunctionCall.aspx.cs

示例12: BuildEmployeeSituations

        public static void BuildEmployeeSituations(ICollection<EmployeeEntity> employees)
        {
            var cornel = employees.Single(x => x.Firstname == "Cornel");
            cornel.Situation = new EmployeeSituationEntity
            {
                Employee = cornel,
                ConsumedDays = 0,
                AvailableDays = 0,
                PaidDays = 0,
                Year = 2013,
            };

            var mihai = employees.Single(x => x.Firstname == "Mihai");
            mihai.Situation = new EmployeeSituationEntity
            {
                Employee = mihai,
                ConsumedDays = 1,
                AvailableDays = 27,
                PaidDays = 0,
                Year = 2013,
            };

            var cosmin = employees.Single(x => x.Firstname == "Cosmin");
            cosmin.Situation = new EmployeeSituationEntity
            {
                Employee = cosmin,
                ConsumedDays = 0,
                AvailableDays = 0,
                PaidDays = 0,
                Year = 2013,
            };

            var daniel = employees.Single(x => x.Firstname == "Daniel");
            daniel.Situation = new EmployeeSituationEntity
            {
                Employee = daniel,
                ConsumedDays = 0,
                AvailableDays = 21,
                PaidDays = 0,
                Year = 2013,
            };

            var costin = employees.Single(x => x.Firstname == "Costin");
            costin.Situation = new EmployeeSituationEntity
            {
                Employee = costin,
                ConsumedDays = 1,
                AvailableDays = 20,
                PaidDays = 0,
                Year = 2013,
            };

            var ioana = employees.Single(x => x.Firstname == "Ioana");
            ioana.Situation = new EmployeeSituationEntity
            {
                Employee = ioana,
                ConsumedDays = 2,
                AvailableDays = 19,
                PaidDays = 0,
                Year = 2013,
            };
        }
开发者ID:stonemonkey,项目名称:VacationManager,代码行数:62,代码来源:TestDataBuilder.cs

示例13: DeserializeSetting

        private object DeserializeSetting(ICollection<Setting> values, bool isItemized, Type settingType)
        {
            var convert = new Func<object, Type, object>((obj, type) =>
            {
                if (obj.GetType() == type)
                {
                    return obj;
                }
                var result = Converter.Convert(obj, type, CultureInfo.InvariantCulture);
                return result;
            });

            if (isItemized)
            {
                var data = (object)null;

                if (settingType.IsArray)
                {
                    data = values.Select(x => x.Value);
                }

                if (settingType.IsList())
                {
                    data = values.Select(x => x.Value);
                }

                if (settingType.IsHashSet())
                {
                    data = values.Select(x => x.Value);
                }

                if (settingType.IsDictionary())
                {
                    data = values.ToDictionary(x => x.Name.Key, x => x.Value);
                }

                return convert(data, settingType);
            }
            else
            {
                return convert(values.Single().Value, settingType);
            }
        }
开发者ID:he-dev,项目名称:SmartConfig,代码行数:43,代码来源:SettingDeserializer.cs

示例14: AssertMatchesAsExpected

 private static void AssertMatchesAsExpected(ICollection<OrderMatch> expectedMatches,
                                             ICollection<OrderMatch> actualMatches)
 {
     Assert.AreEqual(expectedMatches.Count,
                     actualMatches.Count,
                     "Number of actual matches different from number of expected matches");
     foreach (var expectedMatch in expectedMatches)
     {
         try
         {
             var actual = actualMatches.Single(a => a.OrderID == expectedMatch.OrderID);
             AssertEqual(expectedMatch, actual);
         }
         catch (InvalidOperationException e)
         {
             Assert.Fail("Unable to find single actual match for expected match " + e);
         }
     }
 }
开发者ID:naziway,项目名称:testtask,代码行数:19,代码来源:TestDefaultSortedMatching.cs

示例15: SetupMockComponents

        }        private Mock<VBComponents> SetupMockComponents(ICollection<Mock<VBComponent>> items, VBProject project)
        {
            var components = MockFactory.CreateComponentsMock(items, project);
            components.SetupGet(m => m.Parent).Returns(project);
            components.SetupGet(m => m.VBE).Returns(_ide.Object);
            components.Setup(m => m.Item(It.IsAny<int>())).Returns((int index) => items.ElementAt(index).Object);
            components.Setup(m => m.Item(It.IsAny<string>())).Returns((string name) => items.Single(e => e.Object.Name == name).Object);

            return components;
        }
开发者ID:retailcoder,项目名称:Rubberduck,代码行数:10,代码来源:VbeTestBase.cs


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