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


C# Item.ThrowIfNull方法代码示例

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

示例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);
        }
开发者ID:RapidFiring,项目名称:evemon,代码行数:81,代码来源:EveObjectSelectControl.cs


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