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


C# CodeTypeDeclaration.AddCustomAttribute方法代码示例

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


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

示例1: GenerateKeyAttribute

 /// <summary>
 /// Generates the [DataServiceKey] attribute on a given client type
 /// </summary>
 /// <param name="entityType">The complex type's metadata</param>
 /// <param name="entityTypeClass">The complex types declaration</param>
 protected virtual void GenerateKeyAttribute(EntityType entityType, CodeTypeDeclaration entityTypeClass)
 {
     if (entityType.BaseType == null)
     {
         var keyAttribute = entityTypeClass.AddCustomAttribute(Code.TypeRef("Key"));
         keyAttribute.Arguments.AddRange(entityType.AllKeyProperties.Select(p => new CodeAttributeArgument(Code.Primitive(p.Name))).ToArray());
     }
 }
开发者ID:AlineGuan,项目名称:odata.net,代码行数:13,代码来源:StronglyTypedObjectLayerCodeGenerator.cs

示例2: GenerateNamedStreamAttribute

 private void GenerateNamedStreamAttribute(CodeTypeDeclaration entityTypeClass, MemberProperty streamProperty)
 {
     var epmAttribute = entityTypeClass.AddCustomAttribute(Code.TypeRef("NamedStream"));
     epmAttribute.Arguments.Add(new CodeAttributeArgument(Code.Primitive(streamProperty.Name)));
 }
开发者ID:AlineGuan,项目名称:odata.net,代码行数:5,代码来源:StronglyTypedObjectLayerCodeGenerator.cs

示例3: BuildType

        /// <summary>
        /// Builds a code representation of an <see cref="EnumType"/>.
        /// </summary>
        /// <param name="type">The <see cref="EnumType"/> from which to generate code.</param>
        /// <returns>A <see cref="CodeTypeDeclaration"/> which represents the <see cref="EnumType"/>.</returns>
        protected virtual CodeTypeDeclaration BuildType(EnumType type)
        {
            var codeEnum = new CodeTypeDeclaration(type.Name);

            codeEnum.IsEnum = true;

            if (type.UnderlyingType != null)
            {
                codeEnum.BaseTypes.Add(type.UnderlyingType);
            }

            if (type.IsFlags == true)
            {
                codeEnum.AddCustomAttribute(typeof(FlagsAttribute));
            }

            ApplyTypeAccessModifier(codeEnum, type.Annotations.OfType<TypeAccessModifierAnnotation>().SingleOrDefault());

            if (type.Annotations.Any(a => a is SerializableAnnotation))
            {
                codeEnum.AddCustomAttribute(typeof(SerializableAttribute));
            }

            this.AddEnumMembers(codeEnum, type);

            return codeEnum;
        }
开发者ID:larsenjo,项目名称:odata.net,代码行数:32,代码来源:PocoEntityClassGenerator.cs

示例4: 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 virtual void GenerateHasStreamEntityTypeCodeElements(EntityType entityType, CodeTypeDeclaration entityTypeClass)
 {
     ExceptionUtilities.Assert(entityType.HasStream(), "This method should not be called for entity types without stream.");
     entityTypeClass.AddCustomAttribute(Code.TypeRef("HasStream"));
 }
开发者ID:AlineGuan,项目名称:odata.net,代码行数:10,代码来源:StronglyTypedObjectLayerCodeGenerator.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: GenerateEntitySetAttribute

 /// <summary>
 /// Adds the [EntitySet('setName')] attribute on the client type
 /// </summary>
 /// <param name="entityTypeClass">The class declaration for the client type</param>
 /// <param name="entitySetAnnotation">The DataServiceEntitySetAnnotation which contains the name of the set</param>
 private void GenerateEntitySetAttribute(CodeTypeDeclaration entityTypeClass, DataServiceEntitySetAnnotation entitySetAnnotation)
 {
     var entitySetAttribute = entityTypeClass.AddCustomAttribute(Code.TypeRef("EntitySet"));
     entitySetAttribute.Arguments.Add(new CodeAttributeArgument(Code.Primitive(entitySetAnnotation.EntitySetName)));
 }
开发者ID:larsenjo,项目名称:odata.net,代码行数:10,代码来源:PocoClientCodeLayerGenerator.cs

示例7: GenerateDataServiceEntityAttribute

 /// <summary>
 /// Adds the [DataServiceEntity] attribute on the client type
 /// </summary>
 /// <param name="entityTypeClass">The class declaration for the client type</param>
 private void GenerateDataServiceEntityAttribute(CodeTypeDeclaration entityTypeClass)
 {
     entityTypeClass.AddCustomAttribute(Code.TypeRef("DataServiceEntity"));
 }
开发者ID:larsenjo,项目名称:odata.net,代码行数:8,代码来源:PocoClientCodeLayerGenerator.cs


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