public DataType FreshenGenericTypeVariables() { var genericTypeVariables = FindTypeVariables().Where(x => x.IsGeneric); var substitutions = new Dictionary <TypeVariable, DataType>(); foreach (var genericTypeVariable in genericTypeVariables) { substitutions[genericTypeVariable] = TypeVariable.CreateGeneric(); } return(ReplaceTypeVariables(substitutions)); }
public void HasFactoryThatProvidesStreamOfUniqueTypeVariables() { var x = TypeVariable.CreateGeneric(); var y = TypeVariable.CreateGeneric(); var xName = ulong.Parse(x.Name); x.ShouldEqual(new TypeVariable(xName)); y.ShouldEqual(new TypeVariable(xName + 1)); TypeVariable.CreateGeneric().ShouldEqual(new TypeVariable(xName + 2)); TypeVariable.CreateNonGeneric().ShouldEqual(new TypeVariable(xName + 3, false)); TypeVariable.CreateGeneric().ShouldEqual(new TypeVariable(xName + 4)); }
public void CanFreshenGenericTypeVariables() { using (TypeVariable.TestFactory()) { //Prevent type '1' from being freshened by marking it as non-generic: var typeVariable0 = TypeVariable.CreateGeneric(); var typeVariable1 = TypeVariable.CreateNonGeneric(); var expectedTypeAfterLookup = new NamedType("A", new TypeVariable(2), typeVariable1, new NamedType("B", new TypeVariable(2), typeVariable1)); var definedType = new NamedType("A", typeVariable0, typeVariable1, new NamedType("B", typeVariable0, typeVariable1)); definedType.FreshenGenericTypeVariables().ShouldEqual(expectedTypeAfterLookup); } }
public void HasFactoryThatCanBeTemporarilyReplacedForTestingPursposes() { using (TypeVariable.TestFactory()) { var x = TypeVariable.CreateGeneric(); var y = TypeVariable.CreateGeneric(); x.ShouldEqual(new TypeVariable(0)); y.ShouldEqual(new TypeVariable(1)); TypeVariable.CreateGeneric().ShouldEqual(new TypeVariable(2)); TypeVariable.CreateNonGeneric().ShouldEqual(new TypeVariable(3, false)); TypeVariable.CreateGeneric().ShouldEqual(new TypeVariable(4)); } }
public NamedType(Type type) { if (type.IsGenericParameter) { throw new ArgumentException("NamedType cannot be constructed for generic parameter: " + type); } var genericArguments = type.GetGenericArguments(); name = type.QualifiedName(); isGenericTypeDefinition = type.IsGenericTypeDefinition; this.genericArguments = isGenericTypeDefinition ? genericArguments.Select(x => (DataType)TypeVariable.CreateGeneric()).ToVector() : genericArguments.Select(x => (DataType) new NamedType(x)).ToVector(); fullName = new Lazy <string>(GetFullName); }
public void CanNeverBeAGenericTypeDefinition() { TypeVariable.CreateGeneric().IsGenericTypeDefinition.ShouldBeFalse(); TypeVariable.CreateNonGeneric().IsGenericTypeDefinition.ShouldBeFalse(); }
public void CanBeEitherGenericOrNonGeneric() { TypeVariable.CreateGeneric().IsGeneric.ShouldBeTrue(); TypeVariable.CreateNonGeneric().IsGeneric.ShouldBeFalse(); }