Exemplo n.º 1
0
        /// <summary>
        /// Constructs a named stream segment for a property with the given name on the given type
        /// </summary>
        /// <param name="type">The metadata for the type</param>
        /// <param name="propertyName">The property name</param>
        /// <returns>A named streamsegment</returns>
        public static ODataUriSegment NamedStream(StructuralType type, string propertyName)
        {
            ExceptionUtilities.CheckArgumentNotNull(type, "type");
            ExceptionUtilities.CheckStringArgumentIsNotNullOrEmpty(propertyName, "propertyName");

            return new NamedStreamSegment(propertyName);
        }
Exemplo n.º 2
0
        /// <summary>
        /// Constructs a segment for a property with the given name on the given type, or an unknown segment if one cannot be found
        /// </summary>
        /// <param name="type">The metadata for the type</param>
        /// <param name="propertyName">The property name</param>
        /// <returns>A property, navigation, named stream, or unknown segment</returns>
        public static ODataUriSegment Property(StructuralType type, string propertyName)
        {
            ExceptionUtilities.CheckArgumentNotNull(type, "type");
            ExceptionUtilities.CheckStringArgumentIsNotNullOrEmpty(propertyName, "propertyName");

            MemberProperty property;
            var entityType = type as EntityType;
            if (entityType != null)
            {
                var navigation = entityType.AllNavigationProperties.SingleOrDefault(p => p.Name == propertyName);
                if (navigation != null)
                {
                    return new NavigationSegment(navigation);
                }

                property = entityType.AllProperties.SingleOrDefault(p => p.Name == propertyName);
            }
            else
            {
                var complexType = type as ComplexType;
                ExceptionUtilities.CheckObjectNotNull(complexType, "Structural type was neither an entity type nor a complex type");
                property = complexType.Properties.SingleOrDefault(p => p.Name == propertyName);
            }

            if (property != null)
            {
                return new PropertySegment(property);
            }

            return new UnrecognizedSegment(propertyName);
        }
 private void RemoveObjectLayerOnlyProperties(StructuralType structuralType)
 {
     for (int i = structuralType.Properties.Count - 1; i >= 0; i--)
     {
         if (structuralType.Properties[i].Annotations.OfType<ObjectLayerOnlyAnnotation>().Any())
         {
             structuralType.Properties.RemoveAt(i);
         }
     }
 }
 /// <summary>
 /// Returns whether or not to generate a clr type for the given model type
 /// </summary>
 /// <param name="type">The model type</param>
 /// <returns>Whether or not to generate a clr type</returns>
 protected virtual bool ShouldGenerateTypeDefinition(StructuralType type)
 {
     return true;
 }
        /// <summary>
        /// Adds scalar and complex properties to the generated type class.
        /// </summary>
        /// <param name="codeClass">The <see cref="CodeTypeDeclaration"/> to which to add the properties.</param>
        /// <param name="type">The <see cref="StructuralType"/> from which to find properties.</param>
        protected virtual void AddProperties(CodeTypeDeclaration codeClass, StructuralType type)
        {
            foreach (var prop in type.Properties)
            {
                CodeTypeReference propertyType = null;
                var genericPropertyTypeAnnotation = prop.Annotations.OfType<GenericPropertyTypeAnnotation>().FirstOrDefault();
                if (genericPropertyTypeAnnotation != null)
                {
                    propertyType = Code.TypeRef(genericPropertyTypeAnnotation.GenericTypeParameterName);
                }
                else
                {
                    propertyType = codeTypeReferenceResolver.Resolve(prop.PropertyType);
                }

                var codeProp = codeClass.AddAutoImplementedProperty(propertyType, prop.Name);

                ApplyPropertyAccessModifier(codeProp, prop.Annotations.OfType<PropertyAccessModifierAnnotation>().SingleOrDefault());

                if (prop.Annotations.Any(a => a is VirtualAnnotation))
                {
                    codeProp.SetVirtual();
                }

                if (prop.Annotations.Any(a => a is CodeAttributeAnnotation))
                {
                    this.AddCodeAttributeAnnotationAsCustomAttribute(codeProp, prop.Annotations.OfType<CodeAttributeAnnotation>());
                }
            }
        }
 private IEnumerable<XElement> GenerateProperties(StructuralType structuralType, XNamespace xmlNamespace)
 {
     var content = from prop in structuralType.Properties
                   select this.GenerateProperty(xmlNamespace, prop);
     return content;
 }