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


C# CodeDom.CodeAttributeDeclaration类代码示例

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


CodeAttributeDeclaration类属于System.CodeDom命名空间,在下文中一共展示了CodeAttributeDeclaration类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: GetOneToOneAttributeForTarget

        public CodeAttributeDeclaration GetOneToOneAttributeForTarget()
        {
            CodeAttributeDeclaration attribute = null;

			if (!this.Lazy)
        	{
				attribute = new CodeAttributeDeclaration("OneToOne");

        		if (TargetAccess != PropertyAccess.Property)
        			attribute.Arguments.Add(AttributeHelper.GetNamedEnumAttributeArgument("Access", "PropertyAccess", TargetAccess));
        		if (TargetConstrained)
        			attribute.Arguments.Add(AttributeHelper.GetNamedAttributeArgument("Constrained", TargetConstrained));
        	}
			else
				attribute = new CodeAttributeDeclaration("BelongsTo");

			if (TargetCascade != CascadeEnum.None)
				attribute.Arguments.Add(AttributeHelper.GetNamedEnumAttributeArgument("Cascade", "CascadeEnum", TargetCascade));
			if (!string.IsNullOrEmpty(TargetCustomAccess))
                attribute.Arguments.Add(AttributeHelper.GetNamedAttributeArgument("CustomAccess", TargetCustomAccess));
            if (TargetOuterJoin != OuterJoinEnum.Auto)
                attribute.Arguments.Add(AttributeHelper.GetNamedEnumAttributeArgument("OuterJoin", "OuterJoinEnum", TargetOuterJoin));

            return attribute;
        }
开发者ID:mgagne-atman,项目名称:Projects,代码行数:25,代码来源:OneToOneRelation.cs

示例2: Execute

        public override void Execute(CodeNamespace codeNamespace)
        {
            // foreach datatype in the codeNamespace
            foreach (CodeTypeDeclaration type in codeNamespace.Types)
            {
                if (type.IsEnum) continue;

                foreach (CodeTypeMember member in type.Members)
                {
                    CodeMemberField codeField = member as CodeMemberField;
                    if (codeField == null)
                        continue;

                    // check if the Field is XmlElement
                    //"[System.ComponentModel.TypeConverter(typeof(ByteTypeConverter))]";
                    if (codeField.Type.BaseType == typeof(XmlElement).ToString())
                    {
                        // add the custom type editor attribute
                        CodeAttributeDeclaration attr = new CodeAttributeDeclaration("System.NonSerialized");
                        codeField.CustomAttributes.Add(attr);

                    }
                }

            }
        }
开发者ID:nujmail,项目名称:xsd-to-classes,代码行数:26,代码来源:AddNonSerialized.cs

示例3: AddAttributeDeclaration

        private void AddAttributeDeclaration(CodeTypeDeclaration typeDecl, string clrTypeName, string jsonName)
        {
            if (this.serializationModel == SerializationModel.DataContractJsonSerializer)
            {
                CodeAttributeDeclaration attr = new CodeAttributeDeclaration(
                        new CodeTypeReference(typeof(DataContractAttribute)));
                if (clrTypeName != jsonName)
                {
                    attr.Arguments.Add(new CodeAttributeArgument("Name", new CodePrimitiveExpression(jsonName)));
                }

                typeDecl.CustomAttributes.Add(attr);
            }
            else if (this.serializationModel == SerializationModel.JsonNet)
            {
                typeDecl.CustomAttributes.Add(
                    new CodeAttributeDeclaration(
                        new CodeTypeReference(typeof(JsonObjectAttribute)),
                        new CodeAttributeArgument(
                            "MemberSerialization",
                            new CodeFieldReferenceExpression(
                                new CodeTypeReferenceExpression(typeof(MemberSerialization)),
                                "OptIn"))));
            }
            else
            {
                throw new ArgumentException("Invalid serialization model");
            }
        }
开发者ID:wenrongwu,项目名称:WebAPI,代码行数:29,代码来源:JsonRootCompiler.cs

示例4: SetUp

 public void SetUp()
 {
     Generator = new StructureGenerator(Configuration);
     Configuration = new CodeGeneratorConfiguration().MediaTypes;
     attribute = new CodeAttributeDeclaration("MediaType");
     contentType = new MediaType();
 }
开发者ID:KayeeNL,项目名称:Umbraco.CodeGen,代码行数:7,代码来源:StructureGeneratorTests.cs

示例5: BuildPoc

        public CodeTypeDeclaration BuildPoc(TableViewBase rootModel)
        {
            CodeTypeDeclaration ctd = new CodeTypeDeclaration();
            ConstructorGraph ctorGraph = new ConstructorGraph();

            ctd.Name = rootModel.Name;
            ctd.TypeAttributes = System.Reflection.TypeAttributes.Public;
            ctd.Attributes = MemberAttributes.Public;
            ctd.IsPartial = true;
            CodeAttributeDeclaration cad_DataContract = new CodeAttributeDeclaration(" System.Runtime.Serialization.DataContractAttribute");
            ctd.CustomAttributes.Add(cad_DataContract);

            // Members
            foreach (Column c in rootModel.Columns)
            {
                MemberGraph mGraph = new MemberGraph(c);

                CodeMemberField c_field = mGraph.GetField();
                CodeMemberProperty c_prop = mGraph.GetProperty();

                CodeAttributeDeclaration cad_DataMember = new CodeAttributeDeclaration("System.Runtime.Serialization.DataMemberAttribute");
                c_prop.CustomAttributes.Add(cad_DataMember);

                ctd.Members.Add(c_field);
                ctd.Members.Add(c_prop);
            }

            foreach (CodeConstructor cc in ctorGraph.GraphConstructors(rootModel))
            {
                ctd.Members.Add(cc);
            }

            return ctd;
        }
开发者ID:rexwhitten,项目名称:MGenerator,代码行数:34,代码来源:POCOGenerator.cs

示例6: Clone

 //CodeAttributeDeclarationCollection
 //public static CodeAttributeDeclarationCollection Clone(CodeAttributeDeclarationCollection attributeCol) {
 //    foreach(CodeAttributeDeclaration attr in attributeCol) {
 //    }
 //    //CodeDirectiveCollection clone = new CodeDirectiveCollection(directivecol);
 //    //return clone;
 //}
 public static CodeAttributeDeclaration Clone(CodeAttributeDeclaration attributeDecl)
 {
     return new CodeAttributeDeclaration(((CodeTypeReferenceEx)attributeDecl.AttributeType).Clone() as CodeTypeReferenceEx)
     {
         Name = attributeDecl.Name,
     };
 }
开发者ID:RaptorOne,项目名称:SmartDevelop,代码行数:14,代码来源:CloneHelper.cs

示例7: AddCustomAttributesToMethod

 private void AddCustomAttributesToMethod(CodeMemberMethod dbMethod)
 {
     bool primitive = false;
     DataObjectMethodType fill = DataObjectMethodType.Fill;
     if (base.methodSource.EnableWebMethods && base.getMethod)
     {
         CodeAttributeDeclaration declaration = new CodeAttributeDeclaration("System.Web.Services.WebMethod");
         declaration.Arguments.Add(new CodeAttributeArgument("Description", CodeGenHelper.Str(base.methodSource.WebMethodDescription)));
         dbMethod.CustomAttributes.Add(declaration);
     }
     if (!base.GeneratePagingMethod && (base.getMethod || (base.ContainerParameterType == typeof(DataTable))))
     {
         if (base.MethodSource == base.DesignTable.MainSource)
         {
             primitive = true;
         }
         if (base.getMethod)
         {
             fill = DataObjectMethodType.Select;
         }
         else
         {
             fill = DataObjectMethodType.Fill;
         }
         dbMethod.CustomAttributes.Add(new CodeAttributeDeclaration(CodeGenHelper.GlobalType(typeof(DataObjectMethodAttribute)), new CodeAttributeArgument[] { new CodeAttributeArgument(CodeGenHelper.Field(CodeGenHelper.GlobalTypeExpr(typeof(DataObjectMethodType)), fill.ToString())), new CodeAttributeArgument(CodeGenHelper.Primitive(primitive)) }));
     }
 }
开发者ID:pritesh-mandowara-sp,项目名称:DecompliedDotNetLibraries,代码行数:27,代码来源:QueryGenerator.cs

示例8: GetOneToOneAttributeForTarget

        public CodeAttributeDeclaration GetOneToOneAttributeForTarget()
        {
            CodeAttributeDeclaration attribute;

			if (!Lazy)
        	{
				attribute = new CodeAttributeDeclaration("OneToOne");

        		if (TargetConstrained)
        			attribute.Arguments.Add(AttributeHelper.GetNamedAttributeArgument("Constrained", TargetConstrained));
        	}
			else
				attribute = new CodeAttributeDeclaration("BelongsTo");

			if (TargetCascade != CascadeEnum.None)
				attribute.Arguments.Add(AttributeHelper.GetNamedEnumAttributeArgument("Cascade", "CascadeEnum", TargetCascade));

            if (!string.IsNullOrEmpty(TargetCustomAccess))
                attribute.Arguments.Add(AttributeHelper.GetNamedAttributeArgument("CustomAccess", TargetCustomAccess));
            // This was moved out of the above if(Lazy) block.  The properties themselves can be virtual and we can fill in the fields when the NHibernate object is loaded.
            else if (EffectiveTargetAccess != PropertyAccess.Property)
                attribute.Arguments.Add(AttributeHelper.GetNamedEnumAttributeArgument("Access", "PropertyAccess", EffectiveTargetAccess));

            if (TargetOuterJoin != OuterJoinEnum.Auto)
                attribute.Arguments.Add(AttributeHelper.GetNamedEnumAttributeArgument("OuterJoin", "OuterJoinEnum", TargetOuterJoin));

            return attribute;
        }
开发者ID:mgagne-atman,项目名称:Projects,代码行数:28,代码来源:OneToOneRelation.cs

示例9: AddAttribute

		public static void AddAttribute(this CodeAttributeDeclarationCollection codeAttributeDeclarationCollection, CodeAttributeDeclaration codeAttributeDeclaration)
		{
			if (codeAttributeDeclaration != null)
			{
				codeAttributeDeclarationCollection.Add(codeAttributeDeclaration);
			}
		}
开发者ID:Happy-Ferret,项目名称:dotgecko,代码行数:7,代码来源:CodeDomExtensions.cs

示例10: GenerateClassAttributes

    /*
     * Add metadata attributes to the class
     */
    protected override void GenerateClassAttributes() {

        base.GenerateClassAttributes();

        // If the user control has an OutputCache directive, generate
        // an attribute with the information about it.
        if (_sourceDataClass != null && Parser.OutputCacheParameters != null) {
            OutputCacheParameters cacheSettings = Parser.OutputCacheParameters;
            if (cacheSettings.Duration > 0) {
                CodeAttributeDeclaration attribDecl = new CodeAttributeDeclaration(
                    "System.Web.UI.PartialCachingAttribute");
                CodeAttributeArgument attribArg = new CodeAttributeArgument(
                    new CodePrimitiveExpression(cacheSettings.Duration));
                attribDecl.Arguments.Add(attribArg);
                attribArg = new CodeAttributeArgument(new CodePrimitiveExpression(cacheSettings.VaryByParam));
                attribDecl.Arguments.Add(attribArg);
                attribArg = new CodeAttributeArgument(new CodePrimitiveExpression(cacheSettings.VaryByControl));
                attribDecl.Arguments.Add(attribArg);
                attribArg = new CodeAttributeArgument(new CodePrimitiveExpression(cacheSettings.VaryByCustom));
                attribDecl.Arguments.Add(attribArg);
                attribArg = new CodeAttributeArgument(new CodePrimitiveExpression(cacheSettings.SqlDependency));
                attribDecl.Arguments.Add(attribArg);
                attribArg = new CodeAttributeArgument(new CodePrimitiveExpression(Parser.FSharedPartialCaching));
                attribDecl.Arguments.Add(attribArg);
                // Use the providerName argument only when targeting 4.0 and above.
                if (MultiTargetingUtil.IsTargetFramework40OrAbove) {
                    attribArg = new CodeAttributeArgument("ProviderName", new CodePrimitiveExpression(Parser.Provider));
                    attribDecl.Arguments.Add(attribArg);
                }

                _sourceDataClass.CustomAttributes.Add(attribDecl);
            }
        }
    }
开发者ID:iskiselev,项目名称:JSIL.NetFramework,代码行数:37,代码来源:UserControlCodeDomTreeGenerator.cs

示例11: GetKeyPropertyAttribute

 public CodeAttributeDeclaration GetKeyPropertyAttribute()
 {
     // Why KeyPropertyAttribute doesn't have the same constructor signature as it's base class PropertyAttribute?
     CodeAttributeDeclaration attribute = new CodeAttributeDeclaration("KeyProperty");
     PopulateKeyPropertyAttribute(attribute);
     return attribute;
 }
开发者ID:mgagne-atman,项目名称:Projects,代码行数:7,代码来源:ModelProperty.cs

示例12: GetBelongsToAttribute

        public CodeAttributeDeclaration GetBelongsToAttribute()
        {
            CodeAttributeDeclaration attribute = new CodeAttributeDeclaration("BelongsTo");
            if (!string.IsNullOrEmpty(SourceColumn))
                attribute.Arguments.Add(AttributeHelper.GetPrimitiveAttributeArgument(SourceColumn));
            if (SourceCascade != CascadeEnum.None)
                attribute.Arguments.Add(AttributeHelper.GetNamedEnumAttributeArgument("Cascade", "CascadeEnum", SourceCascade));
            if (!string.IsNullOrEmpty(SourceCustomAccess))
                attribute.Arguments.Add(AttributeHelper.GetNamedAttributeArgument("CustomAccess", SourceCustomAccess));
            if (!SourceInsert)
                attribute.Arguments.Add(AttributeHelper.GetNamedAttributeArgument("Insert", SourceInsert));
            if (SourceNotNull)
                attribute.Arguments.Add(AttributeHelper.GetNamedAttributeArgument("NotNull", SourceNotNull));
            if (SourceOuterJoin != OuterJoinEnum.Auto)
                attribute.Arguments.Add(
                    AttributeHelper.GetNamedEnumAttributeArgument("OuterJoin", "OuterJoinEnum", SourceOuterJoin));
            if (!string.IsNullOrEmpty(SourceType))
                attribute.Arguments.Add(AttributeHelper.GetNamedTypeAttributeArgument("Type", SourceType));
            if (SourceUnique)
                attribute.Arguments.Add(AttributeHelper.GetNamedAttributeArgument("Unique", SourceUnique));
            if (!SourceUpdate)
                attribute.Arguments.Add(AttributeHelper.GetNamedAttributeArgument("Update", SourceUpdate));
            if (SourceNotFoundBehaviour != NotFoundBehaviour.Default)
                attribute.Arguments.Add(AttributeHelper.GetNamedEnumAttributeArgument("NotFoundBehaviour", "NotFoundBehaviour", SourceNotFoundBehaviour));

            return attribute;
        }
开发者ID:mgagne-atman,项目名称:Projects,代码行数:27,代码来源:ManyToOneRelation.cs

示例13: AddAttribute

        public static void AddAttribute(ITypeDefinition cls, string name, params object[] parameters)
        {
            bool isOpen;
            string fileName = cls.Region.FileName;
            var buffer = TextFileProvider.Instance.GetTextEditorData (fileName, out isOpen);

            var attr = new CodeAttributeDeclaration (name);
            foreach (var parameter in parameters) {
                attr.Arguments.Add (new CodeAttributeArgument (new CodePrimitiveExpression (parameter)));
            }

            var type = new CodeTypeDeclaration ("temp");
            type.CustomAttributes.Add (attr);
            Project project;
            if (!cls.TryGetSourceProject (out project)) {
                LoggingService.LogError ("Error can't get source project for:" + cls.FullName);
            }

            var provider = ((DotNetProject)project).LanguageBinding.GetCodeDomProvider ();
            var sw = new StringWriter ();
            provider.GenerateCodeFromType (type, sw, new CodeGeneratorOptions ());
            string code = sw.ToString ();
            int start = code.IndexOf ('[');
            int end = code.LastIndexOf (']');
            code = code.Substring (start, end - start + 1) + Environment.NewLine;

            int pos = buffer.LocationToOffset (cls.Region.BeginLine, cls.Region.BeginColumn);

            code = buffer.GetLineIndent (cls.Region.BeginLine) + code;
            buffer.Insert (pos, code);
            if (!isOpen) {
                File.WriteAllText (fileName, buffer.Text);
                buffer.Dispose ();
            }
        }
开发者ID:Kalnor,项目名称:monodevelop,代码行数:35,代码来源:CodeGenerationService.cs

示例14: DynaAttributeDeclaration

 public DynaAttributeDeclaration(string AttributeName, object[] AttributeArguements)
 {
     CodeAttributeArgument[] caa = new CodeAttributeArgument[AttributeArguements.Length];
     for (int i = 0; i < caa.Length; i++)
         caa[i] = new CodeAttributeArgument(new CodePrimitiveExpression(AttributeArguements[i]));
     cad = new CodeAttributeDeclaration(AttributeName, caa);
 }
开发者ID:tenshino,项目名称:RainstormStudios,代码行数:7,代码来源:DynaSupplimental.cs

示例15: Execute

        public override void Execute(CodeNamespace codeNamespace)
        {
            if (Options == null || Options.Property == null || Options.Property.Count == 0)
                return;

            // foreach datatype in the codeNamespace
            foreach (CodeTypeDeclaration type in codeNamespace.Types)
            {
                // get a list of the propertytypes that start with the class name
                List<PropertyType> propertyTypes = Options.Property.FindAll(x => x.QualifiedName.StartsWith(type.Name));
                if (propertyTypes == null || propertyTypes.Count == 0)
                    continue;

                foreach (PropertyType propertyType in propertyTypes)
                {
                    CodeMemberProperty member = type
                        .Members
                        .OfType<CodeMemberProperty>()
                        .FirstOrDefault(x => propertyType.QualifiedName.EndsWith(x.Name) || propertyType.QualifiedName.EndsWith("*"));
                    if (member == null)
                        continue;

                    // add the custom type editor attribute
                    CodeAttributeDeclaration attr = new CodeAttributeDeclaration("System.ComponentModel.Browsable");
                    attr.Arguments.Add(new CodeAttributeArgument(new CodePrimitiveExpression(false)));
                    member.CustomAttributes.Add(attr);

                }   

            }
        }
开发者ID:nujmail,项目名称:xsd-to-classes,代码行数:31,代码来源:BrowsableProperty.cs


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