/// <summary> /// Visits a QueryStructuralValue and returns the clr value of the structural value /// </summary> /// <param name="value">The QueryStructuralValue which contains the clr value of the structural type : complex/entity type</param> /// <returns>The clr instance of the structural value</returns> public object Visit(QueryStructuralValue value) { object clrInstance = null; if (this.objectLookup.TryGetValue(value, out clrInstance)) { return(clrInstance); } ExceptionUtilities.CheckObjectNotNull(value.Type as IQueryClrType, "Structural type does not implement IQueryClrType"); IQueryClrType clrTypeQueryable = value.Type as IQueryClrType; Type clrType = clrTypeQueryable.ClrType; ExceptionUtilities.CheckObjectNotNull(clrType, "ClrType should not be null"); clrInstance = clrType.GetConstructor(Type.EmptyTypes).Invoke(null); this.objectLookup.Add(value, clrInstance); foreach (var member in value.MemberNames) { QueryValue queryValue = value.GetValue(member); var memberValue = queryValue.Accept(this); PropertyInfo memberProperty = clrType.GetProperty(member); memberProperty.SetValue(clrInstance, memberValue, null); } return(clrInstance); }
/// <summary> /// Visits a query collection value and returns an IList with the clr values of the elements /// </summary> /// <param name="value">The collection value which contains the elements</param> /// <returns>An IList with the clr values of the elements</returns> public object Visit(QueryCollectionValue value) { object clrInstance = null; if (this.objectLookup.TryGetValue(value, out clrInstance)) { return(clrInstance); } IQueryClrType queryEntityType = value.Type.ElementType as IQueryClrType; Type clrQueryType = queryEntityType.ClrType; var dummyListType = typeof(List <>).MakeGenericType(clrQueryType); var stronglyTypedListConstructor = dummyListType.GetConstructor(Type.EmptyTypes); clrInstance = stronglyTypedListConstructor.Invoke(null); IList stronglyTypedList = clrInstance as IList; this.objectLookup.Add(value, stronglyTypedList); foreach (var entity in value.Elements) { stronglyTypedList.Add(entity.Accept <object>(this)); } return(clrInstance); }
private CodeTypeReference GetTypeReference(QueryType queryType) { IQueryClrType type = queryType as IQueryClrType; ExceptionUtilities.CheckObjectNotNull(type, "IsOf is only valid for types that inherit from IQueryClrType, the passed type is {0}", queryType.StringRepresentation); return(Code.TypeRef(type.ClrType.FullName)); }
/// <summary> /// Is the query clr type nullable or not /// </summary> /// <param name="queryClrType">Query Clr Type to test for condition</param> /// <returns>true if its nullable</returns> public static bool IsNullable(this IQueryClrType queryClrType) { ExceptionUtilities.CheckArgumentNotNull(queryClrType, "queryClrType"); if (queryClrType.ClrType.IsValueType() && Nullable.GetUnderlyingType(queryClrType.ClrType) == null) { return(false); } return(true); }
/// <summary> /// Creates a QueryCollectionType which implements IQueryClrType so that codegen creates the right list type /// </summary> /// <typeparam name="TQueryType">The element type of the Collection</typeparam> /// <param name="queryType">The query type of the Collection</param> /// <param name="clrTypeDefinition">The generic type definition of the collection type, e.g.: List<> </param> /// <returns>A QueryClrCollectionType which is used as a hint by Code Generation</returns> public static QueryClrCollectionType <TQueryType> CreateClrType <TQueryType>(TQueryType queryType, Type clrTypeDefinition) where TQueryType : QueryType { IQueryClrType queryClrType = queryType as IQueryClrType; ExceptionUtilities.CheckArgumentNotNull(clrTypeDefinition, "clrTypeDefinition"); ExceptionUtilities.Assert(clrTypeDefinition.IsGenericTypeDefinition(), "clrTypeDefinition is not a generic type definition"); ExceptionUtilities.CheckObjectNotNull(queryClrType, "queryType should implement IQueryClrType"); Type clrTypeOfElement = clrTypeDefinition.MakeGenericType(queryClrType.ClrType); return(new QueryClrCollectionType <TQueryType>(clrTypeOfElement, queryType, queryType.EvaluationStrategy)); }
/// <summary> /// Helper method for determining if a type is spatial /// </summary> /// <param name="queryType">The query type to check</param> /// <returns>Whether or not the type is spatial</returns> protected internal bool IsSpatialType(IQueryClrType queryType) { if (queryType is QueryClrSpatialType) { return(true); } if (this.SpatialTypeResolver != null) { return(this.SpatialTypeResolver.IsSpatial(queryType.ClrType)); } return(false); }
/// <summary> /// Gets EDM type for primtive, entity and complex types /// </summary> /// <param name="type">The Query Type.</param> /// <returns>The EDM Type in string format.</returns> protected string GetEdmTypeName(QueryType type) { QueryComplexType complexType = type as QueryComplexType; QueryEntityType entityType = type as QueryEntityType; IQueryClrType clrBackedType = type as IQueryClrType; if (complexType != null) { return(complexType.ComplexType.FullName); } else if (entityType != null) { return(entityType.EntityType.FullName); } else if (clrBackedType != null) { ExceptionUtilities.CheckObjectNotNull(this.PrimitiveDataTypeConverter, "Cannot get edm type name for primitive clr type without converter"); return(this.PrimitiveDataTypeConverter.ToDataType(clrBackedType.ClrType).GetEdmTypeName()); } else { throw new TaupoNotSupportedException("Unable to find EDM type name for type which is not an entity type or a primitive type"); } }