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


C# Arguments.All方法代码示例

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


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

示例1: GetConstructorData

        internal ConstructorData GetConstructorData(IList<ConstructorInfo> constructors, Arguments args)
        {
            /*
                0:  No Constructors : Throw Ex
                1:  Only Default Constructor, No Arguments : Invoke()
                2:  Only Default Constructor, Arguments supplied : Invoke()
                3:  Onlt Parameterised, No Arguments : Throw Ex()
                4:  Only Parameterised, Constructors with all args = 0 : Throw Ex
                5:  Only Parameterised, Constructors with exact args : Invoke()
                6:  Only Parameterised, Constructors with all args, registry cannot fill remainder : Throw Ex
                7:  Only Parameterised, Constructors with all args, registry can fill remainder : Invoke()
                8:  Mixed Constructors, No Arguments : Invoke()
                9:  Mixed Constructors, Constructors with all args = 0 : Throw Ex
                10: Mixed Constructors, Constructors with exact args : Invoke()
                11: Mixed Constructors, Constructors with all args, registry cannot fill remainder : Throw Ex
                12: Mixed Constructors, Constructors with all args, registry can fill remainder : Invoke()
            */

            //none
            if (constructors.Count == 0)
            {
                throw new ConstructorException();
            }

            //only Default
            if (constructors.All(c => c.GetParameters().Count() == 0))
            {

                //1
                if (args.Count != 0)
                {
                    throw new ConstructorException();
                }

                //2
                return new ConstructorData(constructors.First());
            }

            //Only Parameterised
            if (constructors.All(c => c.GetParameters().Count() > 0))
            {

                //3
                if (args.Count == 0)
                {
                    throw new ConstructorException();
                }

                //4
                if (!constructors.Any(c => args.All(a => c.GetParameters().Contains(a))))
                {
                    throw new ConstructorException();
                }

                var withAll = constructors.Where(c => args.All(a => c.GetParameters().Contains(a)));
                var exact = withAll.Where(c => c.GetParameters().Count() == args.Count);

                //5
                if (exact.Count() > 0)
                {
                    var best = GetBestMatch(exact, args, null);

                    return new ConstructorData(best.Constructor, best.Arguments);
                }

                //6
                var unmatchedArgs = GetUnmatchedArgs(withAll, args);
                if (!unmatchedArgs.Any(u => _registry.ContainsAll(u.Value.Select(p => p.ParameterType))))
                {
                    throw new ConstructorException();
                }

                //7
                var bestMatch = GetBestMatch(exact, args, unmatchedArgs);
                return new ConstructorData(bestMatch.Constructor , bestMatch.Arguments);
            }

            //mixed
            if (constructors.Any(c => c.GetParameters().Count() > 0) && constructors.Any(c => c.GetParameters().Count() == 0))
            {

                //8
                if (args.Count == 0)
                {
                    var ctor = constructors.First(c => c.GetParameters().Count() == 0);
                    return new ConstructorData(ctor);
                }

                //9
                if (!constructors.Any(c => args.All(a => c.GetParameters().Contains(a))))
                {
                    throw new ConstructorException();
                }

                var withAll = constructors.Where(c => args.All(a => c.GetParameters().Contains(a)));
                var exact = withAll.Where(c => c.GetParameters().Count() == args.Count);

                //10
                if (exact.Count() > 0)
                {
//.........这里部分代码省略.........
开发者ID:Pondidum,项目名称:Seivad,代码行数:101,代码来源:Selector.cs


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