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); }
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"); }
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"); }
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"); }
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()); }
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; }
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(); }