本文整理汇总了C#中ICollection.SingleOrDefault方法的典型用法代码示例。如果您正苦于以下问题:C# ICollection.SingleOrDefault方法的具体用法?C# ICollection.SingleOrDefault怎么用?C# ICollection.SingleOrDefault使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ICollection
的用法示例。
在下文中一共展示了ICollection.SingleOrDefault方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: AssertTlv
private void AssertTlv(ICollection<Tlv> tlvs)
{
Assert.NotNull(tlvs);
Assert.True(tlvs.Count == 1);
var _6F = tlvs.SingleOrDefault(t => t.HexTag == "6F");
Assert.NotNull(_6F);
Assert.True(_6F.Children.Count == 2);
var _6F84 = _6F.Children.SingleOrDefault(t => t.HexTag == "84");
Assert.NotNull(_6F84);
Assert.True(_6F84.Children.Count == 0);
Assert.True(_6F84.HexValue == "315041592E5359532E4444463031");
var _6FA5 = _6F.Children.SingleOrDefault(t => t.HexTag == "A5");
Assert.NotNull(_6FA5);
Assert.True(_6FA5.Children.Count == 2);
var _6FA588 = _6FA5.Children.SingleOrDefault(t => t.HexTag == "88");
Assert.NotNull(_6FA588);
Assert.True(_6FA588.HexValue == "02");
var _6FA55F2D = _6FA5.Children.SingleOrDefault(t => t.HexTag == "5F2D");
Assert.NotNull(_6FA55F2D);
Assert.True(_6FA55F2D.HexValue == "656E");
}
示例2: ConstructProvider
private static Object ConstructProvider(Type providerType, ICollection<ConstructorArgumentElement> arguments)
{
foreach (var constructor in providerType.GetConstructors())
{
var parameters = constructor.GetParameters().ToArray();
// not all arguments can be specified
if (parameters.Select(param => param.Name).Intersect(arguments.Select(a => a.Name)).Count() != arguments.Count)
continue;
// not enough arguments to call constructor
if (parameters.Any(param => !(param.IsOptional || param.DefaultValue != null || arguments.Any(arg => arg.Name == param.Name))))
continue;
// get correct arguments
var invocationArguments = parameters
.OrderBy(param => param.Position)
.Select(p => new { Parameter = p, Argument = arguments.SingleOrDefault(a => a.Name == p.Name) })
.Select(pair => pair.Argument == null ? pair.Parameter.DefaultValue : pair.Argument.Value)
.ToArray();
// invoke constructor
return constructor.Invoke(invocationArguments);
}
return null;
}
示例3: FillFees
public void FillFees(ICollection<AppraiserFee> fees, FeesViewModel feesViewModel)
{
if (fees == null)
{
throw new ArgumentNullException("fees");
}
if (feesViewModel == null)
{
throw new ArgumentNullException("fees view model");
}
var feesArray = fees.ToArray();
foreach (var fee in feesArray)
{
if (!feesViewModel.FeesItems.Any(f => f.Id == fee.Id.ToString()))
{
fees.Remove(fee);
}
}
foreach (var item in feesViewModel.FeesItems)
{
if (string.IsNullOrEmpty(_refManager.GetProductNameById(item.ProductType)))
{
throw new ArgumentException("product id");
}
var fee = fees.SingleOrDefault(e => e.Id.ToString() == item.Id);
if (fee == null)
{
fee = new AppraiserFee();
fees.Add(fee);
}
fee.Amount = item.Fee.Value;
fee.ProductId = item.ProductType;
}
}
示例4: RunTestWithDependencyHandling
private FeatureTestRun RunTestWithDependencyHandling(ICollection<FeatureTestRun> runs, MethodInfo test, Type adapterType, MethodInfo[] allTests) {
var run = runs.SingleOrDefault(r => r.Method == test && r.AdapterType == adapterType);
if (run != null) // already run as a dependency?
return run;
var dependencies = test.GetCustomAttributes<DependsOnFeatureAttribute>();
var requiredRuns = new List<FeatureTestRun>();
foreach (var dependency in dependencies) {
var dependencyDeclaringType = dependency.DeclaringType ?? test.DeclaringType;
var requiredTest = allTests.SingleOrDefault(t => t.Name == dependency.MethodName && t.DeclaringType == dependencyDeclaringType);
if (requiredTest == null)
throw new InvalidOperationException(string.Format("Could not find test '{0}' in type '{1}' (referenced by [FeatureDependsOn]).", dependency.MethodName, dependencyDeclaringType.Name));
var requiredRun = this.RunTestWithDependencyHandling(runs, requiredTest, adapterType, allTests);
requiredRuns.Add(requiredRun);
}
run = new FeatureTestRun(test, adapterType, this.RunTestAsync(test, adapterType, requiredRuns));
runs.Add(run);
return run;
}
示例5: MergeLists
private static void MergeLists(
ICollection<IndexAttribute> existingIndexes,
IEnumerable<IndexAttribute> newIndexes,
PropertyInfo propertyInfo)
{
foreach (var index in newIndexes)
{
if (index == null)
{
throw new ArgumentNullException("indexAttribute");
}
var existingIndex = existingIndexes.SingleOrDefault(i => i.Name == index.Name);
if (existingIndex == null)
{
existingIndexes.Add(index);
}
else
{
var isCompatible = index.IsCompatibleWith(existingIndex);
if (isCompatible)
{
existingIndexes.Remove(existingIndex);
existingIndexes.Add(index.MergeWith(existingIndex));
}
else
{
var errorMessage = Environment.NewLine + "\t" + isCompatible.ErrorMessage;
throw new InvalidOperationException(
propertyInfo == null
? Strings.ConflictingIndexAttribute(existingIndex.Name, errorMessage)
: Strings.ConflictingIndexAttributesOnProperty(
propertyInfo.Name, propertyInfo.ReflectedType.Name, existingIndex.Name, errorMessage));
}
}
}
}
示例6: SameInstanceAnnotations
private static void SameInstanceAnnotations(ICollection<ODataInstanceAnnotation> InstanceAnnotations1, ICollection<ODataInstanceAnnotation> InstanceAnnotations2)
{
InstanceAnnotations1.Count.Should().Equals(InstanceAnnotations2.Count);
foreach (ODataInstanceAnnotation instanceannotation in InstanceAnnotations1)
{
ODataInstanceAnnotation annotation = InstanceAnnotations2.SingleOrDefault(ia => ia.Name == instanceannotation.Name.ToString());
annotation.Should().NotBeNull();
TestUtils.AssertODataValueAreEqual(instanceannotation.Value, annotation.Value);
}
}
示例7: ApplySuggestedHours
private void ApplySuggestedHours(ICollection<PlannedHour> hours)
{
foreach (PlannedHour h in Item.PlannedHours) {
var suggested = hours.SingleOrDefault(s => s.Role.RoleShortName.ToLower() == h.Role.RoleShortName.ToLower());
if (suggested != null)
h.Hours = suggested.Hours;
}
OnPropertyChanged("PlannedHours");
}
示例8: SetProjectItems
public void SetProjectItems(ICollection<BacklogItem> items, ICollection<BacklogItemGroup> groups)
{
this.allItems = items;
this.groups = groups;
// sets the proposal item reference
foreach (ProposalItem pItem in Proposal.Items)
pItem.Item = items.SingleOrDefault(i => i.BacklogItemUId == pItem.BacklogItemUId);
// create proposal items view models
ICollection<ProposalItemViewModel> proposalItems = new List<ProposalItemViewModel>();
foreach (BacklogItem item in items)
proposalItems.Add(new ProposalItemViewModel(this, item, groups.SingleOrDefault(g => g.GroupUId==item.GroupUId)));
itemsViewSource.GroupDescriptions.Clear();
itemsViewSource.Source = proposalItems;
itemsViewSource.GroupDescriptions.Add(new System.Windows.Data.PropertyGroupDescription("ItemGroup.GroupName"));
Discount = Proposal.Discount;
UseCalcPrice = Proposal.UseCalcPrice;
// calcs proposal price
if (Proposal.ProposalStatus == (short) ProposalStatus.PROPOSAL_WAITING) {
ItemsPrice = Proposal.CalcItemsPrice(HourCosts);
FixedCostPrice = Proposal.CalcFixedCosts();
} else {
TotalPrice = Proposal.TotalValue;
}
OnPropertyChanged("ProjectItems");
}
示例9: CheckForMergedTable20141222
//.........这里部分代码省略.........
// else
// {
// tble.TableDesign = tble.TableDesign.Replace(match, match.Replace("class=\"", "class=\"isMerged ").Replace("<div", "<div style=\"background:" + randomColor + " !important;\""));
// }
// tble.TableDesign = tble.TableDesign.Replace(TableName, TableName + "<img alt=\"\" src=\"/images/red-s.png\" class=\"table-img\">");
// }
// //var floorTbl = new FloorTable();
// //CopyHelper.Copy(typeof(MergedFloorTable), res.MergedFloorTable, typeof(FloorTable), floorTbl);
// //floorTbl.TableDesign = controller.RenderPartialViewToString("~/Views/Floor/GetFloorItemTemplate.cshtml", floorTbl);
// //floorTbl.Reservations = new List<Reservation>();
// //res.FloorTable = floorTbl;
// //floorTbl.Reservations.Add(res);
// //tables.Add(floorTbl);
// }
// }
// }
//}
public static void CheckForMergedTable20141222(this UsersContext db, Controller controller,
ICollection<FloorTable> tables, Int64 floorId, DateTime? startTime, DateTime? endTime)
{
var defaultTimeZoneTime = DateTime.UtcNow.ToDefaultTimeZone(db.Database.Connection.Database);
//DateTime date = (startTime.HasValue ? startTime.Value.Date : DateTime.UtcNow.ToClientTime().Date);
DateTime date = (startTime.HasValue ? startTime.Value.Date : defaultTimeZoneTime.Date);
IQueryable<Reservation> reservations = db.tabReservations.Where(r => !r.IsDeleted && r.FloorPlanId == floorId && r.ReservationDate == date).AsQueryable();
if (startTime.HasValue)
{
if (startTime.HasValue && endTime.HasValue)
{
reservations = reservations.Where(r => r.TimeForm <= startTime.Value && r.TimeTo >= endTime.Value);
}
else
{
//var start = startTime.Value.Date.AddTicks(DateTime.UtcNow.ToClientTime().TimeOfDay.Ticks);
var start = startTime.Value.Date.AddTicks(defaultTimeZoneTime.TimeOfDay.Ticks);
reservations = reservations.Where(r => r.TimeForm <= start && r.TimeTo >= start);
}
}
else
{
//reservations = reservations.Where(r => r.TimeForm <= DateTime.UtcNow.ToClientTime() && r.TimeTo >= DateTime.UtcNow.ToClientTime());
reservations = reservations.Where(r => r.TimeForm <= defaultTimeZoneTime && r.TimeTo >= defaultTimeZoneTime);
}
// check if status is FINISHED, CANCELLED, CANCELLED2
var rejectedStatus = new List<long?>()
{
ReservationStatus.Finished,
ReservationStatus.Cancelled
//ReservationStatus.Cancelled_2
};
reservations = reservations.Where(r => !rejectedStatus.Contains(r.StatusId));
var reservationList = reservations.ToList();
if (reservationList != null && reservationList.Count > 0)
{
foreach (var res in reservationList)
{
if (res.FloorTableId == 0 && res.MergedFloorTableId > 0)
{
var randomColor = GetDullRandomColor();
foreach (var tbl in res.MergedFloorTable.OrigionalTables)
{
var tble = tables.SingleOrDefault(t => t.FloorTableId == tbl.FloorTable.FloorTableId);
var TableName = GetMatchedTagsFromHtml(tble.TableDesign, String.Format("<h3(.*?)>(.*?)</h3>")).FirstOrDefault();
var match = GetMatchedTagsFromHtml(tble.TableDesign, String.Format("<div[^>]*?class=([\"'])[^>]*{0}[^>]*\\1[^>]*>", "(quan-2-other1|quan-2-1|quan-4-1)")).First();
//tble.TableDesign = tble.TableDesign.Replace(match, match.Replace("class=\"", "class=\"isMerged "));
if (match.IndexOf("style") > 0)
{
tble.TableDesign = tble.TableDesign.Replace(match, match.Replace("class=\"", "class=\"isMerged ").Replace("style=\"", "style=\"background:" + randomColor + " !important; "));
}
else
{
tble.TableDesign = tble.TableDesign.Replace(match, match.Replace("class=\"", "class=\"isMerged ").Replace("<div", "<div style=\"background:" + randomColor + " !important;\""));
}
tble.TableDesign = tble.TableDesign.Replace(TableName, TableName + "<img alt=\"\" src=\"/images/red-s.png\" class=\"table-img\">");
}
//var floorTbl = new FloorTable();
//CopyHelper.Copy(typeof(MergedFloorTable), res.MergedFloorTable, typeof(FloorTable), floorTbl);
//floorTbl.TableDesign = controller.RenderPartialViewToString("~/Views/Floor/GetFloorItemTemplate.cshtml", floorTbl);
//floorTbl.Reservations = new List<Reservation>();
//res.FloorTable = floorTbl;
//floorTbl.Reservations.Add(res);
//tables.Add(floorTbl);
}
}
}
}
示例10: AssignTodayPlannedHoursToMembers
private void AssignTodayPlannedHoursToMembers(ICollection<MemberProfile> members, ICollection<TodayMemberPlannedHours> hours)
{
foreach (MemberProfile m in members) {
TodayMemberPlannedHours hour = hours.SingleOrDefault(h => h.TaskAssigneeUId == m.MemberUId);
if (hour != null)
m.PlannedHoursForToday = hour.PlannedHours;
if (m.PlannedHoursForToday == null)
m.PlannedHoursForToday = 0;
}
}
示例11: LoadProjectItemsGroups
private void LoadProjectItemsGroups()
{
//if (groups != null)
// return;
groups = backlogService.GetBacklogItemGroups(Project.ProjectUId); ;
foreach (BacklogItem i in projectItems)
i.Group = groups.SingleOrDefault(u => u.GroupUId == i.GroupUId);
}
示例12: CollectTestDataFromInstallChainerComponents
private static Collection<BaseTestData> CollectTestDataFromInstallChainerComponents(SetupConfig setupConfig, ICollection<InstallChainerComponent> components)
{
if (setupConfig == null)
{
throw new InstallerVerificationLibraryException("setupConfiguration can't be null");
}
var testDataCollection = new Collection<BaseTestData>();
foreach (var setupConfigcomponentData in setupConfig.ComponentList)
{
InstallChainerComponent component;
try
{
component = components.SingleOrDefault(x => x.Id == setupConfigcomponentData.Id);
}
catch (Exception)
{
throw new InstallerVerificationLibraryException("Multiple components with name '" + setupConfigcomponentData.Id + "' found. Component name need to be uniqe.");
}
if (component == null)
{
throw new InstallerVerificationLibraryException("Could not find data for component '" + setupConfigcomponentData.Id + "'. This could be because miss spelling of component name.");
}
if (component.TestData.Count == 0)
{
throw new InstallerVerificationLibraryException("Component '" + setupConfigcomponentData.Id + "' doesn't have any testdata data. This could be because miss spelling of component name.");
}
if (!setupConfigcomponentData.Installed)
{
continue;
}
foreach (var data in component.TestData)
{
if (setupConfig.TypeOfInstallation == TypeOfInstallation.Install ||
setupConfig.TypeOfInstallation == TypeOfInstallation.Repair)
{
AddTestData(true, data, testDataCollection);
}
else if (setupConfig.TypeOfInstallation == TypeOfInstallation.UnInstall)
{
AddTestData(false, data, testDataCollection);
}
}
}
return testDataCollection;
}
示例13: CollectTestDataFromFeatures
private static Collection<BaseTestData> CollectTestDataFromFeatures(SetupConfig setupConfig, ICollection<Feature> features)
{
if (setupConfig == null)
{
throw new InstallerVerificationLibraryException("setupConfiguration can't be null");
}
var testDataCollection = new Collection<BaseTestData>();
foreach (var setupConfigcomponentData in setupConfig.ComponentList)
{
Feature feature;
try
{
feature = features.SingleOrDefault(x => x.FeatureName == setupConfigcomponentData.Id);
}
catch (Exception)
{
throw new InstallerVerificationLibraryException("Multiple features with name '" + setupConfigcomponentData.Id + "' found. Feature name need to be uniqe.");
}
if (feature == null)
{
throw new InstallerVerificationLibraryException("Could not find data for feature '" + setupConfigcomponentData.Id + "'. This could be because miss spelling of feature name.");
}
if (feature.FeatureData.Count == 0)
{
throw new InstallerVerificationLibraryException("Feature '" + feature.FeatureName + "' doesn't have any feature data. This could be because miss spelling of feature name.");
}
if (!setupConfigcomponentData.Installed)
{
continue;
}
foreach (var data in feature.FeatureData)
{
data.ComponentID = feature.FeatureName;
if (setupConfig.TypeOfInstallation == TypeOfInstallation.Install ||
setupConfig.TypeOfInstallation == TypeOfInstallation.Repair)
{
AddTestData(true, data, testDataCollection);
}
else if (setupConfig.TypeOfInstallation == TypeOfInstallation.UnInstall)
{
AddTestData(false, data, testDataCollection);
}
}
}
return testDataCollection;
}
示例14: TerminateCall
protected void TerminateCall(ICollection<CallInfo> calls, Response response, IPort sender)
{
var terminateCall =
calls.SingleOrDefault(x => x.Source == response.IncomingRequest.SourceNumber &&
x.Target == response.IncomingRequest.TargetNumber);
if (terminateCall != null)
{
calls.Remove(terminateCall);
var senderPort = _RoutingPorts[response.IncomingRequest.SourceNumber];
var targetPort = _RoutingPorts[response.IncomingRequest.TargetNumber];
if (senderPort == sender)
{
targetPort.CallWasCompleted(response);
}
else
{
senderPort.CallWasCompleted(response);
}
if (terminateCall.Duration == new TimeSpan(0, 0, 0))
{
terminateCall.StartedAt = LocalDateTime.Now;
}
OnTerminateCall(this, terminateCall);
}
}
示例15: SetDescriptorsOnRoute
private static void SetDescriptorsOnRoute(IHttpRoute route, HttpConfiguration configuration, ICollection<HttpControllerDescriptor> controllerDescriptors)
{
var actionDescriptors = route.DataTokens["actions"] as IEnumerable<HttpActionDescriptor>;
if (actionDescriptors != null)
{
foreach (var descriptor in actionDescriptors)
{
descriptor.Configuration = configuration;
//IMPORTANT: We are making a new instance of a HttpControllerDescriptor to force
// the descriptor to initialize again so that IControllerConfiguration executes.
// if they are not the same webapi will throw an exception about ambiguous controllers.
//for any controller type, we need to have the exact same controller descriptor instance
var found = controllerDescriptors.SingleOrDefault(x => x.ControllerType == descriptor.ControllerDescriptor.ControllerType);
if (found == null)
{
found = new HttpControllerDescriptor(
configuration,
descriptor.ControllerDescriptor.ControllerName,
descriptor.ControllerDescriptor.ControllerType);
controllerDescriptors.Add(found);
}
descriptor.ControllerDescriptor = found;
}
}
}