/// <summary>
        /// Returns the type to use when declaring or instantiating the property
        /// </summary>
        /// <param name="property">The property being declared/instantiated</param>
        /// <param name="usage">The usage for the type (either for instantiation or declaration)</param>
        /// <returns>The type of the property</returns>
        protected CodeTypeReference GetPropertyType(NavigationProperty property, CodeGenerationTypeUsage usage)
        {
            var type = DataTypes.EntityType.WithDefinition(property.ToAssociationEnd.EntityType);

            if (property.ToAssociationEnd.Multiplicity == EndMultiplicity.Many)
            {
                return(this.GetCollectionType(usage, property.Annotations, type));
            }

            return(this.BackingTypeResolver.ResolveClrTypeReference(type));
        }
        /// <summary>
        /// Returns the type to use when declaring or instantiating the property
        /// </summary>
        /// <param name="property">The property being declared/instantiated</param>
        /// <param name="usage">Whether the type is for declaration or instantiation</param>
        /// <returns>The type of the property</returns>
        protected CodeTypeReference GetPropertyType(MemberProperty property, CodeGenerationTypeUsage usage)
        {
            var collectionDataType = property.PropertyType as CollectionDataType;

            if (collectionDataType != null)
            {
                return(this.GetCollectionType(usage, property.Annotations, collectionDataType.ElementDataType));
            }

            return(this.BackingTypeResolver.ResolveClrTypeReference(property.PropertyType));
        }
        /// <summary>
        /// Gets a type reference to use when declaring or instantiation a collection property
        /// </summary>
        /// <param name="usage">Whether the type is for declaration or instantiation</param>
        /// <param name="propertyAnnotations">The annotations of the property</param>
        /// <param name="elementDataType">The element type of the collection</param>
        /// <returns>The type of the property</returns>
        protected virtual CodeTypeReference GetCollectionType(CodeGenerationTypeUsage usage, IEnumerable <Annotation> propertyAnnotations, DataType elementDataType)
        {
            // look up the type annotation in the given annotations for this usage
            var annotation = propertyAnnotations.OfType <CollectionTypeAnnotation>().SingleOrDefault(t => t.Usage == usage);

            ExceptionUtilities.CheckObjectNotNull(annotation, "Property did not have a collection type defined with usage: {0}", usage);

            // if it is generic, then use the backing type of the given element type as the generic argument
            if (annotation.IsGeneric)
            {
                return(Code.GenericType(annotation.FullTypeName, this.BackingTypeResolver.ResolveClrTypeReference(elementDataType)));
            }
            else
            {
                return(Code.TypeRef(annotation.FullTypeName));
            }
        }
 /// <summary>
 /// Gets a type reference to use when declaring or instantiation a collection property
 /// </summary>
 /// <param name="usage">Whether the type is for declaration or instantiation</param>
 /// <param name="propertyAnnotations">The annotations of the property</param>
 /// <param name="elementDataType">The element type of the collection</param>
 /// <returns>The type of the property</returns>
 protected override CodeTypeReference GetCollectionType(CodeGenerationTypeUsage usage, IEnumerable<Annotation> propertyAnnotations, DataType elementDataType)
 {
     return Code.GenericType("ObservableCollection", this.BackingTypeResolver.ResolveClrTypeReference(elementDataType));
 }
        /// <summary>
        /// Gets a type reference to use when declaring or instantiation a collection property
        /// </summary>
        /// <param name="usage">Whether the type is for declaration or instantiation</param>
        /// <param name="propertyAnnotations">The annotations of the property</param>
        /// <param name="elementDataType">The element type of the collection</param>
        /// <returns>The type of the property</returns>
        protected virtual CodeTypeReference GetCollectionType(CodeGenerationTypeUsage usage, IEnumerable<Annotation> propertyAnnotations, DataType elementDataType)
        {
            // look up the type annotation in the given annotations for this usage
            var annotation = propertyAnnotations.OfType<CollectionTypeAnnotation>().SingleOrDefault(t => t.Usage == usage);
            ExceptionUtilities.CheckObjectNotNull(annotation, "Property did not have a collection type defined with usage: {0}", usage);

            // if it is generic, then use the backing type of the given element type as the generic argument
            if (annotation.IsGeneric)
            {
                return Code.GenericType(annotation.FullTypeName, this.BackingTypeResolver.ResolveClrTypeReference(elementDataType));
            }
            else
            {
                return Code.TypeRef(annotation.FullTypeName);
            }
        }
        /// <summary>
        /// Returns the type to use when declaring or instantiating the property
        /// </summary>
        /// <param name="property">The property being declared/instantiated</param>
        /// <param name="usage">The usage for the type (either for instantiation or declaration)</param>
        /// <returns>The type of the property</returns>
        protected CodeTypeReference GetPropertyType(NavigationProperty property, CodeGenerationTypeUsage usage)
        {
            var type = DataTypes.EntityType.WithDefinition(property.ToAssociationEnd.EntityType);
            if (property.ToAssociationEnd.Multiplicity == EndMultiplicity.Many)
            {
                return this.GetCollectionType(usage, property.Annotations, type);
            }

            return this.BackingTypeResolver.ResolveClrTypeReference(type);
        }
        /// <summary>
        /// Returns the type to use when declaring or instantiating the property
        /// </summary>
        /// <param name="property">The property being declared/instantiated</param>
        /// <param name="usage">Whether the type is for declaration or instantiation</param>
        /// <returns>The type of the property</returns>
        protected CodeTypeReference GetPropertyType(MemberProperty property, CodeGenerationTypeUsage usage)
        {
            var collectionDataType = property.PropertyType as CollectionDataType;
            if (collectionDataType != null)
            {
                return this.GetCollectionType(usage, property.Annotations, collectionDataType.ElementDataType);
            }

            return this.BackingTypeResolver.ResolveClrTypeReference(property.PropertyType);
        }
Пример #8
0
 /// <summary>
 /// Gets a type reference to use when declaring or instantiation a collection property
 /// </summary>
 /// <param name="usage">Whether the type is for declaration or instantiation</param>
 /// <param name="propertyAnnotations">The annotations of the property</param>
 /// <param name="elementDataType">The element type of the collection</param>
 /// <returns>The type of the property</returns>
 protected override CodeTypeReference GetCollectionType(CodeGenerationTypeUsage usage, IEnumerable <Annotation> propertyAnnotations, DataType elementDataType)
 {
     return(Code.GenericType("ObservableCollection", this.BackingTypeResolver.ResolveClrTypeReference(elementDataType)));
 }