本文整理汇总了C#中Item.ThrowIfNull方法的典型用法代码示例。如果您正苦于以下问题:C# Item.ThrowIfNull方法的具体用法?C# Item.ThrowIfNull怎么用?C# Item.ThrowIfNull使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Item
的用法示例。
在下文中一共展示了Item.ThrowIfNull方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: CannotUse
/// <summary>
/// Filter for items which can not be used (prereqs not met).
/// </summary>
/// <param name="item"></param>
/// <returns></returns>
/// <exception cref="System.ArgumentNullException">item</exception>
protected bool CannotUse(Item item)
{
item.ThrowIfNull(nameof(item));
Blueprint blueprint = item as Blueprint;
bool hasActivity = blueprint == null || ActivityFilter == ObjectActivityFilter.All
|| blueprint.Prerequisites.Any(x => x.Activity == Activity)
|| blueprint.MaterialRequirements.Any(x => x.Activity == Activity);
// Special condition check for activity 'Any'
// as negative logic returns incorrect results
if (!(this is BlueprintSelectControl) || ActivityFilter != ObjectActivityFilter.Any)
return !CanUse(item) && hasActivity;
List<StaticSkillLevel> prerequisites =
item.Prerequisites.Where(x => x.Activity != BlueprintActivity.ReverseEngineering).ToList();
IEnumerable<Boolean> prereqTrained = prerequisites
.Where(prereq => prereq.Skill != null)
.Select(prereq => new
{
prereq,
level = m_character.GetSkillLevel(prereq.Skill)
})
.Select(y => y.level >= y.prereq.Level);
// Has the character trained all prereq skills for this activity ?
return prerequisites.Any() && !prereqTrained.All(x => x);
}
示例2: CanUse
/// <summary>
/// Filter for items which can be used (prereqs met).
/// </summary>
/// <param name="item"></param>
/// <returns></returns>
/// <exception cref="System.ArgumentNullException">item</exception>
protected bool CanUse(Item item)
{
item.ThrowIfNull(nameof(item));
IList<StaticSkillLevel> prerequisites =
item.Prerequisites.Where(x => x.Activity != BlueprintActivity.ReverseEngineering).ToList();
BlueprintSelectControl blueprintSelectControl = this as BlueprintSelectControl;
// Is item a blueprint and supports the selected activity ?
if (blueprintSelectControl != null)
{
bool hasSelectedActivity = prerequisites.Any(x => x.Activity == Activity)
|| ((Blueprint)item).MaterialRequirements.Any(x => x.Activity == Activity);
// Can not be used when item doesn't support the selected activity
if ((ActivityFilter == ObjectActivityFilter.Manufacturing || ActivityFilter == ObjectActivityFilter.Invention)
&& !hasSelectedActivity)
return false;
// Enumerates the prerequisites skills to the selected activity
if (ActivityFilter != ObjectActivityFilter.All && ActivityFilter != ObjectActivityFilter.Any)
prerequisites = prerequisites.Where(x => x.Activity == Activity).ToList();
}
// Item doesn't have prerequisites
if (!prerequisites.Any())
return true;
// Is this the "Blueprint Browser" and the activity filter is set to "Any" ?
List<Boolean> prereqTrained = new List<Boolean>();
if (blueprintSelectControl != null && ActivityFilter == ObjectActivityFilter.Any)
{
List<BlueprintActivity> prereqActivity = new List<BlueprintActivity>();
// Create a list with the activities this item supports
foreach (StaticSkillLevel prereq in prerequisites.Where(x => !prereqActivity.Contains(x.Activity)))
{
prereqActivity.Add(prereq.Activity);
}
// Create a list with each prereq skill trained status for the questioned activity
foreach (BlueprintActivity activity in prereqActivity)
{
prereqTrained.Clear();
prereqTrained.AddRange(prerequisites
.Where(prereq => prereq.Skill != null && prereq.Activity == activity)
.Select(prereq => new
{
prereq,
level = m_character.GetSkillLevel(prereq.Skill)
})
.Select(y => y.level >= y.prereq.Level));
// Has the character trained all prereq skills for this activity ?
if (prereqTrained.All(x => x))
return true;
}
return false;
}
// Do a simple predication and create a list with each prereq skill trained status
prereqTrained.AddRange(prerequisites
.Where(prereq => prereq.Skill != null)
.Select(prereq => new
{
prereq,
level = m_character.GetSkillLevel(prereq.Skill)
})
.Select(y => y.level >= y.prereq.Level));
// Has the character trained all prereq skills ?
return prereqTrained.All(x => x);
}