当前位置: 首页>>代码示例>>C#>>正文


C# CodeTypeDeclaration.AddAutoImplementedProperty方法代码示例

本文整理汇总了C#中System.CodeDom.CodeTypeDeclaration.AddAutoImplementedProperty方法的典型用法代码示例。如果您正苦于以下问题:C# CodeTypeDeclaration.AddAutoImplementedProperty方法的具体用法?C# CodeTypeDeclaration.AddAutoImplementedProperty怎么用?C# CodeTypeDeclaration.AddAutoImplementedProperty使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在System.CodeDom.CodeTypeDeclaration的用法示例。


在下文中一共展示了CodeTypeDeclaration.AddAutoImplementedProperty方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: DeclareMemberProperty

 /// <summary>
 /// Adds a property to the given type declaration based on the given metadata
 /// </summary>
 /// <param name="memberProperty">The property's metadata</param>
 /// <param name="parentClass">The type declaration</param>
 protected override void DeclareMemberProperty(MemberProperty memberProperty, CodeTypeDeclaration parentClass)
 {
     if (memberProperty.IsStream())
     {
         this.DeclareNamedStreamProperty(memberProperty, parentClass);
     }
     else
     {
         parentClass.AddAutoImplementedProperty(this.GetPropertyType(memberProperty, CodeGenerationTypeUsage.Declaration), memberProperty.Name);
     }
 }
开发者ID:AlineGuan,项目名称:odata.net,代码行数:16,代码来源:StronglyTypedObjectLayerCodeGenerator.cs

示例2: DeclareNavigationProperty

 /// <summary>
 /// Adds a navigation property to the given type declaration based on the given metadata
 /// </summary>
 /// <param name="navigationProperty">The property's metadata</param>
 /// <param name="parentClass">The type declaration</param>
 protected override void DeclareNavigationProperty(NavigationProperty navigationProperty, CodeTypeDeclaration parentClass)
 {
     parentClass.AddAutoImplementedProperty(this.GetPropertyType(navigationProperty, CodeGenerationTypeUsage.Declaration), navigationProperty.Name);
 }
开发者ID:AlineGuan,项目名称:odata.net,代码行数:9,代码来源:StronglyTypedObjectLayerCodeGenerator.cs

示例3: AddProperties

        /// <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>());
                }
            }
        }
开发者ID:larsenjo,项目名称:odata.net,代码行数:35,代码来源:PocoEntityClassGenerator.cs

示例4: AddNavigationProperties

        /// <summary>
        /// Adds navigation properties to generated type class.
        /// </summary>
        /// <param name="codeClass">The <see cref="CodeTypeDeclaration"/> to which to add the navigation properties.</param>
        /// <param name="type">The <see cref="EntityType"/> from which to find navigation properties.</param>
        /// <param name="defaultConstructor">The <see cref="CodeConstructor"/>, used to initialize navigation properties to their default values.</param>
        /// <remarks>
        /// Because CodeDom only supports property-level attributes, the get access modifier will be used for the entire property
        /// </remarks>
        protected virtual void AddNavigationProperties(CodeTypeDeclaration codeClass, EntityType type, CodeConstructor defaultConstructor)
        {
            foreach (var prop in type.NavigationProperties)
            {
                string propTypeName = prop.ToAssociationEnd.EntityType.FullName;
                bool isVirtual = prop.Annotations.Any(a => a is VirtualAnnotation);

                CodeTypeReference propType;
                if (prop.ToAssociationEnd.Multiplicity == EndMultiplicity.Many)
                {
                    // Instantiate collection in constructor if it's not overrideable
                    if (!isVirtual)
                    {
                        var instantiateType = Code.GenericType("List", propTypeName);
                        defaultConstructor.Statements.Add(Code.This().Property(prop.Name).Assign(Code.New(instantiateType)));
                    }

                    propType = Code.GenericType("ICollection", propTypeName);
                }
                else
                {
                    propType = new CodeTypeReference(propTypeName);
                }

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

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

                if (prop.Annotations.Any(a => a is CodeAttributeAnnotation))
                {
                    this.AddCodeAttributeAnnotationAsCustomAttribute(codeProp, prop.Annotations.OfType<CodeAttributeAnnotation>());
                }

                if (isVirtual)
                {
                    codeProp.SetVirtual();
                }
            }
        }
开发者ID:larsenjo,项目名称:odata.net,代码行数:48,代码来源:PocoEntityClassGenerator.cs

示例5: GenerateHasStreamEntityTypeCodeElements

        /// <summary>
        /// Generates and adds stream related attributes and elements to the entity type
        /// </summary>
        /// <param name="entityType">The entity type's metadata</param>
        /// <param name="entityTypeClass">The entity types declaration</param>
        protected override void GenerateHasStreamEntityTypeCodeElements(EntityType entityType, CodeTypeDeclaration entityTypeClass)
        {
            ExceptionUtilities.Assert(entityType.HasStream(), "This method should not be called for entity types without stream.");
            
            ClientMediaEntryAnnotation clientMediaEntryAnnotation = entityType.Annotations.OfType<ClientMediaEntryAnnotation>().FirstOrDefault();
            if (clientMediaEntryAnnotation != null)
            {
                // generate MediaEntry and MimeTypeProperty properties and attributes for V1 style stream support
                var attributeArguments1 = new CodeAttributeArgument[]
                {
                    new CodeAttributeArgument(Code.Primitive(clientMediaEntryAnnotation.MediaEntryName)),
                };
                var attributeArguments2 = new CodeAttributeArgument[]
                {
                    new CodeAttributeArgument(Code.Primitive(clientMediaEntryAnnotation.MediaEntryName)),
                    new CodeAttributeArgument(Code.Primitive(clientMediaEntryAnnotation.MimeTypePropertyName))
                };

                entityTypeClass.AddCustomAttribute(Code.TypeRef("MediaEntry"), attributeArguments1);
                entityTypeClass.AddCustomAttribute(Code.TypeRef("MimeTypeProperty"), attributeArguments2);
                entityTypeClass.AddAutoImplementedProperty(Code.TypeRef<byte[]>(), clientMediaEntryAnnotation.MediaEntryName);
                entityTypeClass.AddAutoImplementedProperty(Code.TypeRef<string>(), clientMediaEntryAnnotation.MimeTypePropertyName);
            }
            else
            {
                // No ClientMediaEntryAnnotation is found, generate HasStream atttribute for V2 and up stream support
                entityTypeClass.AddCustomAttribute(Code.TypeRef("HasStream"));
            }
        }
开发者ID:larsenjo,项目名称:odata.net,代码行数:34,代码来源:PocoClientCodeLayerGenerator.cs

示例6: DeclareNamedStreamProperty

 /// <summary>
 /// Adds a named stream property to the given type declaration based on the given metadata
 /// </summary>
 /// <param name="namedStreamProperty">The named stream property's metadata</param>
 /// <param name="parentClass">The type declaration</param>
 protected override void DeclareNamedStreamProperty(MemberProperty namedStreamProperty, CodeTypeDeclaration parentClass)
 {
     parentClass.AddAutoImplementedProperty(Code.TypeRef("Microsoft.OData.Client.DataServiceStreamLink"), namedStreamProperty.Name);
 }
开发者ID:larsenjo,项目名称:odata.net,代码行数:9,代码来源:PocoClientCodeLayerGenerator.cs


注:本文中的System.CodeDom.CodeTypeDeclaration.AddAutoImplementedProperty方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。