コード例 #1
0
        public IEnumerable <Type> findGenericArgumentTypes(GenericTypeDefinition typeDefinition)
        {
            var genericArguments = new List <Type>();

            foreach (var argumentTypeName in typeDefinition.ArgumentTypeNames)
            {
                var argumentTypes = findTypes(argumentTypeName).ToArray();

                if (argumentTypes.Count() < 1)
                {
                    _parseErrors.Add("No generic argument type matching {0} was found.".ToFormat(argumentTypeName));
                    return(null);
                }
                if (argumentTypes.Count() > 1)
                {
                    var candidates = argumentTypes.Select(x => x.AssemblyQualifiedName).Join(", ");
                    _parseErrors.Add("More than one generic argument types matching {0} was found. Type ambiguity on: {1}".ToFormat(argumentTypeName, candidates));
                    return(null);
                }

                genericArguments.Add(argumentTypes.First());
            }

            return(genericArguments);
        }
コード例 #2
0
ファイル: GenericParserTester.cs プロジェクト: hartez/fubumvc
        public void finding_open_type_should_add_error_when_no_matching_type_is_found()
        {
            var typeDefinition = new GenericTypeDefinition {OpenTypeName = "NotFound", ArgumentTypeNames = new[] {"System.String"}};

            var result = ClassUnderTest.findOpenType(typeDefinition);

            result.ShouldBeNull();
            ClassUnderTest.ParseErrors.First().ShouldContain("No generic type matching");
        }
コード例 #3
0
ファイル: GenericParserTester.cs プロジェクト: hartez/fubumvc
        public void finding_open_type_should_add_error_when_multiple_matching_types_are_found()
        {
            var typeDefinition = new GenericTypeDefinition { OpenTypeName = "FubuMVC.Spark.Tests.SparkModel.Binding.DuplicatedGeneric`1", ArgumentTypeNames = new[] { "System.String" } };

            var result = ClassUnderTest.findOpenType(typeDefinition);

            result.ShouldBeNull();
            ClassUnderTest.ParseErrors.First().ShouldContain("More than one generic types matching");
        }
コード例 #4
0
ファイル: GenericParserTester.cs プロジェクト: hartez/fubumvc
        public void finding_generic_arguments_should_add_error_when_no_matching_type_is_found()
        {
            var typeDefinition = new GenericTypeDefinition { OpenTypeName = "FubuMVC.Spark.Tests.SparkModel.Binding.Generic`1", ArgumentTypeNames = new[] { "NOTFOUND" } };

            var result = ClassUnderTest.findGenericArgumentTypes(typeDefinition);

            result.ShouldBeNull();
            ClassUnderTest.ParseErrors.First().ShouldContain("No generic argument type matching");
        }
コード例 #5
0
        public Type findOpenType(GenericTypeDefinition typeDefinition)
        {
            var openTypes = findTypes(typeDefinition.OpenTypeName).ToArray();

            if (openTypes.Count() < 1)
            {
                _parseErrors.Add("No generic type matching {0} was found.".ToFormat(typeDefinition.OpenTypeName));
                return(null);
            }
            if (openTypes.Count() > 1)
            {
                var candidates = openTypes.Select(x => x.AssemblyQualifiedName).Join(", ");
                _parseErrors.Add("More than one generic types matching {0} was found. Type ambiguity on: {1}".ToFormat(typeDefinition.OpenTypeName, candidates));
                return(null);
            }

            return(openTypes.First());
        }
コード例 #6
0
ファイル: GenericParser.cs プロジェクト: jemacom/fubumvc
        public IEnumerable<Type> findGenericArgumentTypes(GenericTypeDefinition typeDefinition)
        {
            var genericArguments = new List<Type>();
            foreach (var argumentTypeName in typeDefinition.ArgumentTypeNames)
            {
                var argumentTypes = findTypes(argumentTypeName).ToArray();

                if (argumentTypes.Count() < 1)
                {
                    _parseErrors.Add("No generic argument type matching {0} was found.".ToFormat(argumentTypeName));
                    return null;
                }
                if (argumentTypes.Count() > 1)
                {
                    var candidates = argumentTypes.Select(x => x.AssemblyQualifiedName).Join(", ");
                    _parseErrors.Add("More than one generic argument types matching {0} was found. Type ambiguity on: {1}".ToFormat(argumentTypeName, candidates));
                    return null;
                }

                genericArguments.Add(argumentTypes.First());
            }

            return genericArguments;
        }
コード例 #7
0
ファイル: GenericParser.cs プロジェクト: jemacom/fubumvc
        public Type findOpenType(GenericTypeDefinition typeDefinition)
        {
            var openTypes = findTypes(typeDefinition.OpenTypeName).ToArray();

            if (openTypes.Count() < 1)
            {
                _parseErrors.Add("No generic type matching {0} was found.".ToFormat(typeDefinition.OpenTypeName));
                return null;
            }
            if (openTypes.Count() > 1)
            {
                var candidates = openTypes.Select(x => x.AssemblyQualifiedName).Join(", ");
                _parseErrors.Add("More than one generic types matching {0} was found. Type ambiguity on: {1}".ToFormat(typeDefinition.OpenTypeName, candidates));
                return null;
            }

            return openTypes.First();
        }