本文整理汇总了C#中Data.List.Select方法的典型用法代码示例。如果您正苦于以下问题:C# List.Select方法的具体用法?C# List.Select怎么用?C# List.Select使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Data.List
的用法示例。
在下文中一共展示了List.Select方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Deal
public Deal(List<Player> players, Player dealer)
{
Players = players;
Players.Select(p => p.Role = null);
Dealer = Players.Single(p => p.Name == dealer.Name);
Dealer.Role = CreateRole(players);
}
示例2: CreateMenuRepresentation
private static MenuRepresentation CreateMenuRepresentation(List<Product> products)
{
var itemRepresentations = products
.Select(p => new ItemRepresentation {Name = p.Name, Price = p.Price})
.ToArray();
return new MenuRepresentation {Items = itemRepresentations};
}
示例3: SaveToFile
public void SaveToFile(List<IFeed> feed)
{
List<SerializerItem> Items = feed.Select(x => new SerializerItem(x)).ToList();
var xml = new System.Xml.Serialization.XmlSerializer(typeof(List<SerializerItem>));
using(var f = System.IO.File.Open(filepath, System.IO.FileMode.Create))
{
xml.Serialize(f, Items);
f.Flush();
f.Close();
}
}
示例4: UpdatePlanningElementData
/// <summary>
/// The update planning element data.
/// </summary>
/// <param name="factory">
/// The factory.
/// </param>
/// <param name="project">
/// The project.
/// </param>
/// <param name="planningElementList">
/// The planning element list.
/// </param>
/// <exception cref="InvalidOperationException">
/// Thrown when the database source is unknown.
/// </exception>
public void UpdatePlanningElementData( string factory, string project, List<PlanningElementDataUpdate> planningElementList )
{
project = Util.CorrectProjectName( project );
switch( ImpactDatabase.DataSource )
{
case DataSource.Ingres92:
case DataSource.Ingres100:
{
// Create a query that return all the id's of those elements that aldready has planning data.
ImpactQuery query = new ImpactQuery()
{
From = { ImpModelPlanning.As( "T1" ) },
Select = { ImpModelPlanning.ElementId },
Where =
{
ImpModelPlanning.Factory.Equal(factory),
ImpModelPlanning.Project.Equal(project),
ImpModelPlanning.ElementId.In<int>( planningElementList.Select( element => element.ElementId ) )
}
};
using( var database = new ImpactDatabase() )
{
var existingIds = database.GetAll( query.ToString(), reader => reader[0].Cast<int>() );
var statementList = new List<string>( planningElementList.Count );
foreach( var element in planningElementList )
{
string producingFactory;
if( 0 == string.Compare( Factory.External.Number, element.ProducingFactory, StringComparison.OrdinalIgnoreCase ) )
{
producingFactory = ProjectBrowserLoader.ProducingFactoryExternalValue;
}
else
{
producingFactory = element.ProducingFactory;
}
if( existingIds.Contains( element.ElementId ) )
{
// We have an update.
var update = new ImpactUpdate( ImpModelPlanning.Instance )
{
Where =
{
ImpModelPlanning.Factory.Equal( factory ),
ImpModelPlanning.Project.Equal( project ),
ImpModelPlanning.ElementId.Equal( element.ElementId ),
},
Columns =
{
{ ImpModelPlanning.ProductionFactory, producingFactory ?? string.Empty },
{ ImpModelPlanning.DivisionProduction, element.Division ?? string.Empty },
{ ImpModelPlanning.ProductionDate, element.ProductionDate },
{ ImpModelPlanning.DeliveryDate, element.DeliveryDate },
{ ImpModelPlanning.ErectionSequenceNo, element.ErectionSequenceNo },
{ ImpModelPlanning.PlannedDrawingDate, element.PlannedDrawingDate },
{ ImpModelPlanning.PlannedProductionDate, element.PlannedProductionDate },
{ ImpModelPlanning.PlannedReadyForDeliveryDate, element.PlannedStorageDate },
{ ImpModelPlanning.PlannedDeliveryDate, element.PlannedDeliveryDate },
{ ImpModelPlanning.PlannedErectionDate, element.PlannedErectionDate },
{ ImpModelPlanning.ElementIdStatus, element.Status },
}
};
statementList.Add( update.ToString() );
}
else
{
// We must insert a new row.
var insert = new ImpactInsert( ImpModelPlanning.Instance )
{
Columns =
{
{ ImpModelPlanning.Factory, factory },
{ ImpModelPlanning.Project, project },
{ ImpModelPlanning.ElementId, element.ElementId },
{ ImpModelPlanning.ProductionFactory, producingFactory ?? string.Empty },
{ ImpModelPlanning.DivisionProduction, element.Division ?? string.Empty },
{ ImpModelPlanning.ProductionDate, element.ProductionDate },
{ ImpModelPlanning.DeliveryDate, element.DeliveryDate },
{ ImpModelPlanning.ErectionSequenceNo, element.ErectionSequenceNo },
//.........这里部分代码省略.........
示例5: UpdateErectionSequence
/// <summary>
/// The update erection sequence.
/// </summary>
/// <param name="factory">
/// The factory.
/// </param>
/// <param name="project">
/// The project.
/// </param>
/// <param name="erectionSequenceList">
/// The erection sequence list.
/// </param>
/// <returns>
/// The System.Boolean.
/// </returns>
public bool UpdateErectionSequence( string factory, string project, List<KeyValuePair<int, int>> erectionSequenceList )
{
project = project.PadLeft( 12 );
List<string> statementList = new List<string>( erectionSequenceList.Count );
using( var database = new ImpactDatabase() )
{
var allIdArray = erectionSequenceList.Select( x => (object)x.Key ).ToArray();
ImpactQuery query = new ImpactQuery
{
Select = {
ImpModelPlanning.ElementId
},
From = {
ImpModelPlanning.As( "T1" )
},
Where =
{
ImpModelPlanning.Factory.Equal( factory ),
ImpModelPlanning.Project.Equal( project ),
ImpModelPlanning.ElementId.In( allIdArray ),
},
};
string statement = query.ToString();
var existingPlanningList = database.GetAll( statement, column => column[0].Cast<int>() );
var groupedByInsertUpdate = erectionSequenceList.GroupBy( x => existingPlanningList.Remove( x.Key ) ).ToList();
var updateList = groupedByInsertUpdate.Find( x => x.Key );
var insertList = groupedByInsertUpdate.Find( x => !x.Key );
if( null != updateList )
{
foreach( var item in updateList )
{
var update = new ImpactUpdate( ImpModelPlanning.Instance )
{
Columns = {
{ ImpModelPlanning.ErectionSequenceNo, item.Value }
},
Where =
{
ImpModelPlanning.Factory.Equal( factory ),
ImpModelPlanning.Project.Equal( project ),
ImpModelPlanning.ElementId.Equal( item.Key ),
}
};
statementList.Add( update.ToString() );
}
}
if( null != insertList )
{
foreach( var item in insertList )
{
var insert = new ImpactInsert( ImpModelPlanning.Instance )
{
Columns =
{
{ ImpModelPlanning.Factory, factory },
{ ImpModelPlanning.Project, project },
{ ImpModelPlanning.ElementId, item.Key },
{ ImpModelPlanning.ErectionSequenceNo, item.Value },
},
};
statementList.Add( insert.ToString() );
}
}
int result = database.ExecuteNonQuery( statementList.ToArray() );
return result > 0;
}
}
示例6: GetChildrenByCriteria
internal PageCollection GetChildrenByCriteria(Guid parentId, Predicate<PageIndexItem> match) {
PageIndexItem pageIndexItem;
if (parentId == SiteSettings.RootPage) {
pageIndexItem = GetRootPageIndexItem();
}
else {
pageIndexItem = GetPageIndexItem(parentId);
}
if (pageIndexItem == null) {
throw new ArgumentException("Page with id " + parentId + " not found!");
}
var pages = new List<PageIndexItem>();
var currentId = pageIndexItem.FirstChild;
while (currentId > -1) {
var item = _pageIndex[currentId];
if (match(item)) {
pages.Add(item);
}
currentId = _pageIndex[currentId].NextPage;
}
pages = SortPages(pages, pageIndexItem.ChildSortOrder, pageIndexItem.ChildSortDirection);
var pageIds = pages.Select(p => p.PageId).ToList();
return new PageCollection(pageIds);
}
示例7: CanCreateAt
/// <summary>
/// Determines whether an <see cref="Appointment"/> can be created at the specified <paramref name="start"/> time until the specified <paramref name="end"/> time.
/// </summary>
/// <param name="moduleId">The ID of the module in which the appointment is to be created.</param>
/// <param name="start">The start of the new <see cref="Appointment"/>.</param>
/// <param name="end">The end of the new <see cref="Appointment"/>.</param>
/// <param name="max">The maximum appointments allowed for the specified time range</param>
/// <returns>
/// <c>true</c> if an <see cref="Appointment"/> can be created at the specified <paramref name="start"/> time until the specified <paramref name="end"/> time; otherwise, <c>false</c>.
/// </returns>
public static bool CanCreateAt(int moduleId, DateTime start, DateTime end, int? max)
{
var appointments = AppointmentSqlDataProvider.GetConcurrentAppointments(moduleId, start, end);
var appointmentsInRange = new List<Appointment>(max ?? 10);
while (appointments.Read())
{
appointmentsInRange.Add(Fill(appointments));
}
var uniqueStartTimes = appointmentsInRange.Select(apt => apt.StartDateTime).Distinct();
return uniqueStartTimes.All(time => max > appointmentsInRange.Count(apt => time >= apt.StartDateTime && time < apt.EndDateTime));
}
示例8: GetShoppingLists
public ShoppingList[] GetShoppingLists(AuthIdentity identity, IList<ShoppingList> lists, GetShoppingListOptions options)
{
using (var session = this.GetSession())
{
var loadDef = true;
var query = session.QueryOver<ShoppingLists>()
.Where(p => p.UserId == identity.UserId);
if (lists != null)
{
loadDef = lists.Contains(ShoppingList.Default);
var ids = lists.Where(l => l.Id.HasValue).Select(l => l.Id.Value).ToArray();
query = query.AndRestrictionOn(x => x.ShoppingListId).IsInG(ids);
}
var shoppingListses = query.List();
var ret = new List<ShoppingList>();
if (loadDef)
{
ret.Add(ShoppingList.Default);
}
ret.AddRange(shoppingListses.Select(l => l.AsShoppingList()));
if (!options.LoadItems)
{
return ret.ToArray();
}
// Load items into each list
ICriterion filter = loadDef
? Restrictions.Or(Restrictions.IsNull("ShoppingList"), Restrictions.InG("ShoppingList", shoppingListses)) // Menu can be null, or in loaded menu list
: Restrictions.InG("ShoppingList", shoppingListses); // Menu must be in loaded menu list
var shoppingListItemses = session.QueryOver<ShoppingListItems>()
.Fetch(prop => prop.Ingredient).Eager
.Fetch(prop => prop.Recipe).Eager
.Where(p => p.UserId == identity.UserId)
.Where(filter)
.List();
return ret.Select(m =>
new ShoppingList(
m.Id,
m.Title,
(m.Id.HasValue
? shoppingListItemses.Where(f => f.ShoppingList != null && f.ShoppingList.ShoppingListId == m.Id)
: shoppingListItemses.Where(f => f.ShoppingList == null)).Select(r => r.AsShoppingListItem()))).ToArray();
}
}
示例9: GetMenus
public Menu[] GetMenus(AuthIdentity identity, IList<Menu> menus, GetMenuOptions options)
{
using (var session = this.GetSession())
{
// menus will be null if all menus should be loaded, or a list of Menu objects to specify individual menus to load
if (options == null)
{
throw new ArgumentNullException("options");
}
if (identity == null)
{
throw new ArgumentNullException("identity");
}
var loadFav = true;
var query = session.QueryOver<Menus>()
.Where(p => p.UserId == identity.UserId);
if (menus != null)
{
loadFav = menus.Contains(Menu.Favorites);
var ids = menus.Where(m => m.Id.HasValue).Select(m => m.Id.Value).ToArray();
query = query.AndRestrictionOn(p => p.MenuId).IsInG(ids);
}
var databaseMenues = query.List();
var ret = new List<Menu>();
if (loadFav)
{
ret.Add(Menu.Favorites);
}
ret.AddRange(databaseMenues.Select(m => m.AsMenu()));
if (!options.LoadRecipes)
{
return ret.ToArray();
}
// Load recipes into each menu
ICriterion filter = loadFav
? Restrictions.Or(Restrictions.IsNull("Menu"), Restrictions.InG("Menu", databaseMenues)) // Menu can be null, or in loaded menu list
: Restrictions.InG("Menu", databaseMenues); // Menu must be in loaded menu list
var favorites = session.QueryOver<Favorites>()
.Fetch(prop => prop.Recipe).Eager
.Where(p => p.UserId == identity.UserId)
.Where(filter)
.List();
return ret.Select(m =>
new Menu(m)
{
Recipes = (m.Id.HasValue
? favorites.Where(f => f.Menu != null && f.Menu.MenuId == m.Id)
: favorites.Where(f => f.Menu == null)).Select(r => r.Recipe.AsRecipeBrief())
.ToArray()
}).ToArray();
}
}
示例10: GetUnitsByDicipline
public IEnumerable<UnitWrapper> GetUnitsByDicipline(List<DiciplineWrapper> diciplines)
{
List<int> ids = diciplines.Select(d => d.DiciplineId).ToList();
return GetUnits().Where(unit => ids.Contains(unit.Dicipline.DiciplineId));
}