public void ArgumentTranslator_SimpleDoubleParse_GenericDoubleExpected() { var num = 10.0; var expected = new GenericArgument <double>(num); var result = _translator.Process(new object[] { num }); Assert.Equal(expected.Content, ((GenericArgument <double>)result.First()).Content); }
public void ArgumentTranslator_IntArgumentToString_InvariantStringExpected() { var num = 10.256; var result = new GenericArgument <double>(num); var cultureInfo = new CultureInfo("cs-CZ"); CultureInfo.DefaultThreadCurrentCulture = cultureInfo; CultureInfo.DefaultThreadCurrentUICulture = cultureInfo; Assert.Equal("10.256", result.ToString()); }
private MemberProperty ResolveProperty(GenericTypeLookupGraph graph, MemberProperty property, EntityType newOwner) { GenericPropertyTypeAnnotation propertyTypeAnnotation = property.Annotations.OfType <GenericPropertyTypeAnnotation>().FirstOrDefault(); if (propertyTypeAnnotation != null) { // Have to find where the property type comes from var parameter = propertyTypeAnnotation.GenericTypeParameterName; EntityType oldOwner = null; for (oldOwner = newOwner.BaseType; oldOwner != null; oldOwner = oldOwner.BaseType) { if (oldOwner.Properties.Contains(property)) { break; } } Dictionary <EntityType, GenericArgument> lookups = graph[new GenericTypeParameter(oldOwner, parameter)]; GenericArgument genericArgument = null; EntityType resolvingType = null; for (resolvingType = newOwner; resolvingType != null && !lookups.TryGetValue(resolvingType, out genericArgument); resolvingType = resolvingType.BaseType) { } // Means we found a concrete generic argument for this property type. if (resolvingType != null) { return(new MemberProperty(property.Name, genericArgument.DataType) { IsPrimaryKey = property.IsPrimaryKey }); } return(new MemberProperty(property.Name) { IsPrimaryKey = property.IsPrimaryKey, Annotations = { new GenericPropertyTypeAnnotation(parameter) } }); } return(new MemberProperty(property.Name, property.PropertyType) { IsPrimaryKey = property.IsPrimaryKey }); }
private void WalkChildren(GenericTypeLookupGraph graph, EntityModelSchema model, EntityType baseType, string typeParameterName, Dictionary <EntityType, GenericArgument> lookups) { foreach (var childType in model.EntityTypes.Where(e => e.BaseType == baseType)) { var genericTypeAnnotation = childType.Annotations.OfType <GenericTypeAnnotation>().FirstOrDefault(); var genericArgumentsAnnotation = childType.Annotations.OfType <GenericArgumentsAnnotation>().FirstOrDefault(); GenericArgument argument = null; bool argumentMissing = genericArgumentsAnnotation == null || (argument = genericArgumentsAnnotation.GenericArguments.SingleOrDefault(ga => ga.TypeParameterName == typeParameterName)) == null; if (argumentMissing) { var exception = new TaupoArgumentException( string.Format( CultureInfo.InvariantCulture, "Entity type {0} cannot derive from entity type {1} because {0} does not have a type parameter {2} specified by a {3}.", childType.Name, baseType.Name, typeParameterName, typeof(GenericTypeAnnotation).Name)); if (genericTypeAnnotation == null) { throw exception; } var childTypeParameterPosition = genericTypeAnnotation.TypeParameters.IndexOf(typeParameterName); if (childTypeParameterPosition == -1) { throw exception; } var childLookups = new Dictionary <EntityType, GenericArgument>(); graph.Add(new GenericTypeParameter(childType, typeParameterName), childLookups); this.WalkChildren(graph, model, childType, typeParameterName, childLookups); // Merge the child lookups back into lookups foreach (var kvp in childLookups) { lookups[kvp.Key] = kvp.Value; } } else { lookups[childType] = argument; } } }
private static TreeNode BuildGenericArgumentNodeFor(GenericArgument genericArgument) { var valueBuilder = new StringBuilder(genericArgument.Type.Name); var treeNode = new TreeNode { Id = genericArgument.DefinitionType.Name, Name = "->" }; if (genericArgument.GenericArguments != null) { foreach (var childTreeNode in genericArgument.GenericArguments.Select(BuildGenericArgumentNodeFor)) { treeNode.Children.Add(childTreeNode); } valueBuilder.Append($"<{string.Join(", ", treeNode.Children.Select(ch => ch.Value))}>"); } treeNode.Value = valueBuilder.ToString().RemoveNumberOfGenericArguments(); return(treeNode); }
public GenericArgumentTypeDependency(IType origin, GenericArgument genericArgument) : base(origin, genericArgument) { }
public GenericArgumentMemberDependency(IMember originMember, GenericArgument genericArgument) : base(originMember, genericArgument) { }