Add() публичный Метод

public Add ( CodeAttributeDeclaration value ) : int
value CodeAttributeDeclaration
Результат int
Пример #1
0
 private void SetDescription(CodeAttributeDeclarationCollection customAttributes, string description)
 {
     customAttributes.Add(
         new CodeAttributeDeclaration(
             new CodeTypeReference(DESCRIPTION_ATTR),
             new CodeAttributeArgument(
                 new CodePrimitiveExpression(description))));
 }
 public static CodeAttributeDeclarationCollection Clone(this CodeAttributeDeclarationCollection collection)
 {
     if (collection == null) return null;
     CodeAttributeDeclarationCollection c = new CodeAttributeDeclarationCollection();
     foreach (CodeAttributeDeclaration attribute in collection)
         c.Add(attribute.Clone());
     return c;
 }
Пример #3
0
 private void SetProperty(CodeAttributeDeclarationCollection customAttributes, string name, string value)
 {
     customAttributes.Add(
         new CodeAttributeDeclaration(
             new CodeTypeReference(PROPERTY_ATTR),
             new CodeAttributeArgument(
                 new CodePrimitiveExpression(name)),
             new CodeAttributeArgument(
                 new CodePrimitiveExpression(value))));
 }
Пример #4
0
 private void SetCategories(CodeAttributeDeclarationCollection customAttributes, IEnumerable<string> categories)
 {
     foreach (var category in categories)
     {
         customAttributes.Add(
             new CodeAttributeDeclaration(
                 new CodeTypeReference(CATEGORY_ATTR),
                 new CodeAttributeArgument(
                     new CodePrimitiveExpression(category))));
     }
 }
 internal static void AddIncludeMetadata(CodeAttributeDeclarationCollection metadata, StructMapping mapping, Type type)
 {
     if (!mapping.IsAnonymousType)
     {
         for (StructMapping mapping2 = mapping.DerivedMappings; mapping2 != null; mapping2 = mapping2.NextDerivedMapping)
         {
             CodeAttributeDeclaration declaration = new CodeAttributeDeclaration(type.FullName);
             declaration.Arguments.Add(new CodeAttributeArgument(new CodeTypeOfExpression(mapping2.TypeDesc.FullName)));
             metadata.Add(declaration);
             AddIncludeMetadata(metadata, mapping2, type);
         }
     }
 }
Пример #6
0
        private static CodeAttributeDeclarationCollection BuildParameterAttributes(ParameterInfo parameterInfo)
        {
            var collection = new CodeAttributeDeclarationCollection();

            object defaultValue = parameterInfo.RawDefaultValue;

            if (defaultValue != DBNull.Value)
            {
                var optionalAttribute = new CodeAttributeDeclaration(new CodeTypeReference(typeof(OptionalAttribute)));
                var defaultParameterAttribute = new CodeAttributeDeclaration(new CodeTypeReference(typeof(DefaultParameterValueAttribute)), new CodeAttributeArgument(new CodePrimitiveExpression(defaultValue)));

                collection.Add(optionalAttribute);
                collection.Add(defaultParameterAttribute);
            }

            if (parameterInfo.GetCustomAttributes(typeof (ParamArrayAttribute), true).Any())
            {
                collection.Add(new CodeAttributeDeclaration(new CodeTypeReference(typeof (ParamArrayAttribute))));
            }

            return collection;
        }
 private void AddElementMetadata(CodeAttributeDeclarationCollection metadata, string elementName, TypeDesc typeDesc, bool isNullable)
 {
     CodeAttributeDeclaration declaration = new CodeAttributeDeclaration(typeof(SoapElementAttribute).FullName);
     if (elementName != null)
     {
         declaration.Arguments.Add(new CodeAttributeArgument(new CodePrimitiveExpression(elementName)));
     }
     if ((typeDesc != null) && typeDesc.IsAmbiguousDataType)
     {
         declaration.Arguments.Add(new CodeAttributeArgument("DataType", new CodePrimitiveExpression(typeDesc.DataType.Name)));
     }
     if (isNullable)
     {
         declaration.Arguments.Add(new CodeAttributeArgument("IsNullable", new CodePrimitiveExpression(true)));
     }
     metadata.Add(declaration);
 }
Пример #8
0
        static CodeMemberProperty CreateProperty(PropertyNameType nameType, string constantsClassName, string defaultValuesClassName)
        {
            CodeMemberProperty publicProp = new CodeMemberProperty();
            publicProp.Name = nameType.propertyName;
            publicProp.Attributes = CodeDomHelperObjects.PublicFinal;
            publicProp.HasGet = true;
            publicProp.HasSet = true;
            publicProp.Type = new CodeTypeReference(nameType.propertyType);

            CodeAttributeDeclarationCollection attributes = new CodeAttributeDeclarationCollection();
            CodeAttributeArgument arg1 = new CodeAttributeArgument(
                                            new CodeFieldReferenceExpression(
                                                new CodeTypeReferenceExpression(constantsClassName),
                                                nameType.propertyName));
            CodeAttributeArgument arg2 = new CodeAttributeArgument(
                                            PropertyNameConstants.DefaultValueProperty,
                                            new CodeFieldReferenceExpression(
                                                new CodeTypeReferenceExpression(defaultValuesClassName),
                                                Constants.DefaultPrefix + nameType.propertyName));
            // Future TODO: Provide a library with attributes that custom channel writes 
            // can use to adorn their properties with default values and validators, we can
            // then add it here.
            attributes.Add(new CodeAttributeDeclaration(
                            new CodeTypeReference(TypeNameConstants.ConfigurationProperty),
                            arg1, arg2));
            publicProp.CustomAttributes = new CodeAttributeDeclarationCollection(attributes);
            string nameInConfig = constantsClassName + "." + nameType.propertyName;
            CodeArrayIndexerExpression baseIndexedProperty
                                        = new CodeArrayIndexerExpression(
                                            CodeDomHelperObjects.BaseRef,
                                            new CodeFieldReferenceExpression(
                                                new CodeTypeReferenceExpression(constantsClassName),
                                                nameType.propertyName));
            publicProp.GetStatements.Add(new CodeMethodReturnStatement(
                                                new CodeCastExpression(
                                                    nameType.propertyType,
                                                    baseIndexedProperty)));
            publicProp.SetStatements.Add(new CodeAssignStatement(
                                                baseIndexedProperty,
                                                new CodePropertySetValueReferenceExpression()));
            return publicProp;
        }
        void AddDefaultValueAttribute(CodeMemberField field, CodeAttributeDeclarationCollection metadata, object defaultValue, TypeMapping mapping, CodeCommentStatementCollection comments, TypeDesc memberTypeDesc, Accessor accessor, CodeConstructor ctor) {
            string attributeName = accessor.IsFixed ? "fixed" : "default";
            if (!memberTypeDesc.HasDefaultSupport) {
                if (comments != null && defaultValue is string) {
                    DropDefaultAttribute(accessor, comments, memberTypeDesc.FullName);
                    // do not generate intializers for the user prefered types if they do not have default capability
                    AddWarningComment(comments, Res.GetString(Res.XmlDropAttributeValue, attributeName, mapping.TypeName, defaultValue.ToString()));
                }
                return;
            }
            if (memberTypeDesc.IsArrayLike && accessor is ElementAccessor) {
                if (comments != null && defaultValue is string) {
                    DropDefaultAttribute(accessor, comments, memberTypeDesc.FullName);
                    // do not generate intializers for array-like types
                    AddWarningComment(comments, Res.GetString(Res.XmlDropArrayAttributeValue, attributeName, defaultValue.ToString(), ((ElementAccessor)accessor).Name));
                }
                return;
            }
            if (mapping.TypeDesc.IsMappedType && field != null && defaultValue is string) {
                SchemaImporterExtension extension = mapping.TypeDesc.ExtendedType.Extension;
                CodeExpression init = extension.ImportDefaultValue((string)defaultValue, mapping.TypeDesc.FullName);

                if (init != null) {
                    if (ctor != null) {
                        AddInitializationStatement(ctor, field, init);
                    }
                    else {
                        field.InitExpression = extension.ImportDefaultValue((string)defaultValue, mapping.TypeDesc.FullName);
                    }
                }
                if (comments != null) {
                    DropDefaultAttribute(accessor, comments, mapping.TypeDesc.FullName);
                    if (init == null) {
                        AddWarningComment(comments, Res.GetString(Res.XmlNotKnownDefaultValue, extension.GetType().FullName, attributeName, (string)defaultValue, mapping.TypeName, mapping.Namespace));
                    }
                }
                return;
            }
            object value = null;
            if (defaultValue is string || defaultValue == null) {
                value = ImportDefault(mapping, (string)defaultValue);
            }
            if (value == null) return;
            if (!(mapping is PrimitiveMapping)) {
                DropDefaultAttribute(accessor, comments, memberTypeDesc.FullName);
                AddWarningComment(comments, Res.GetString(Res.XmlDropNonPrimitiveAttributeValue, attributeName, defaultValue.ToString()));
                return;
            }
            PrimitiveMapping pm = (PrimitiveMapping)mapping;

            if (comments != null && !pm.TypeDesc.HasDefaultSupport && pm.TypeDesc.IsMappedType) {
                // do not generate intializers for the user prefered types if they do not have default capability
                DropDefaultAttribute(accessor, comments, pm.TypeDesc.FullName);
                return;
            }
            if (value == DBNull.Value) {
                if (comments != null) {
                    AddWarningComment(comments, Res.GetString(Res.XmlDropAttributeValue, attributeName, pm.TypeName, defaultValue.ToString()));
                }
                return;
            }
            CodeAttributeArgument[] arguments = null;
            CodeExpression initExpression = null;
            
            if (pm.IsList) {
                #if DEBUG
                    // use exception in the place of Debug.Assert to avoid throwing asserts from a server process such as aspnet_ewp.exe
                    if (value.GetType() != typeof(object[])) throw new InvalidOperationException(Res.GetString(Res.XmlInternalErrorDetails, "Default value for list should be object[], not " + value.GetType().Name));
                #endif

                object[] vals = (object[])value;
                CodeExpression[] initializers = new CodeExpression[vals.Length];
                for (int i = 0; i < vals.Length; i++) {
                    GetDefaultValueArguments(pm, vals[i], out initializers[i]);
                }
                initExpression = new CodeArrayCreateExpression(field.Type, initializers);
                
            }
            else {
                arguments = GetDefaultValueArguments(pm, value, out initExpression);
            }

            if (field != null) {
                if (ctor != null) {
                    AddInitializationStatement(ctor, field, initExpression);
                }
                else {
                    field.InitExpression = initExpression;
                }
            }
            if (arguments != null && pm.TypeDesc.HasDefaultSupport && accessor.IsOptional && !accessor.IsFixed) {
                // Add [DefaultValueAttribute]
                CodeAttributeDeclaration attribute = new CodeAttributeDeclaration(typeof(DefaultValueAttribute).FullName, arguments);
                metadata.Add(attribute);
            }
            else if (comments != null) {
                DropDefaultAttribute(accessor, comments, memberTypeDesc.FullName);
            }
        }
 private static void PopulateCustomAttributes(ICustomAttributeProvider type,
     CodeAttributeDeclarationCollection attributes, Func<CodeTypeReference, CodeTypeReference> codeTypeModifier)
 {
     foreach (var customAttribute in type.CustomAttributes.Where(ShouldIncludeAttribute).OrderBy(a => a.AttributeType.FullName).ThenBy(a => ConvertAttrbuteToCode(codeTypeModifier, a)))
     {
         var attribute = GenerateCodeAttributeDeclaration(codeTypeModifier, customAttribute);
         attributes.Add(attribute);
     }
 }
Пример #11
0
		static void AddAttribute (CodeAttributeDeclarationCollection atts, CodeTypeReference type, string val)
		{
			atts.Add (new CodeAttributeDeclaration (type, new CodeAttributeArgument (new CodePrimitiveExpression (val))));
		}
 void ExportAnyAttribute(CodeAttributeDeclarationCollection metadata) {
     metadata.Add(new CodeAttributeDeclaration(typeof(XmlAnyAttributeAttribute).FullName));
 }
 void ExportAnyElement(CodeAttributeDeclarationCollection metadata, string name, string ns, int sequenceId) {
     CodeAttributeDeclaration attribute = new CodeAttributeDeclaration(typeof(XmlAnyElementAttribute).FullName);
     if (name != null && name.Length > 0) {
         attribute.Arguments.Add(new CodeAttributeArgument("Name", new CodePrimitiveExpression(name)));
     }
     if (ns != null && ns.Length > 0) {
         attribute.Arguments.Add(new CodeAttributeArgument("Namespace", new CodePrimitiveExpression(ns)));
     }
     if (sequenceId >= 0) {
         attribute.Arguments.Add(new CodeAttributeArgument("Order", new CodePrimitiveExpression(sequenceId)));
     }
     metadata.Add(attribute);
 }
        void ExportMetadata(CodeAttributeDeclarationCollection metadata, Type attributeType, string name, string ns, TypeDesc typeDesc, TypeDesc dataTypeDesc, object isNullable, XmlSchemaForm form, int nestingLevel, int sequenceId) {
            CodeAttributeDeclaration attribute = new CodeAttributeDeclaration(attributeType.FullName);
            if (name != null) {
                attribute.Arguments.Add(new CodeAttributeArgument(new CodePrimitiveExpression(name)));
            }
            if (typeDesc != null) {
                if (isNullable != null && (bool)isNullable && typeDesc.IsValueType && !typeDesc.IsMappedType && CodeProvider.Supports(GeneratorSupport.GenericTypeReference)) {
                    attribute.Arguments.Add(new CodeAttributeArgument(new CodeTypeOfExpression("System.Nullable`1[" + typeDesc.FullName + "]")));
                    isNullable = null;
                }
                else {
                    attribute.Arguments.Add(new CodeAttributeArgument(new CodeTypeOfExpression(typeDesc.FullName)));
                }
            }
            if (form != XmlSchemaForm.None) {
                attribute.Arguments.Add(new CodeAttributeArgument("Form", new CodeFieldReferenceExpression(new CodeTypeReferenceExpression(typeof(XmlSchemaForm).FullName), Enum.Format(typeof(XmlSchemaForm), form, "G"))));

                if (form == XmlSchemaForm.Unqualified && ns != null && ns.Length == 0) {
                    ns = null;
                }
            }
            if (ns != null ) {
                attribute.Arguments.Add(new CodeAttributeArgument("Namespace", new CodePrimitiveExpression(ns)));
            }
            if (dataTypeDesc != null && dataTypeDesc.IsAmbiguousDataType && !dataTypeDesc.IsMappedType) {
                attribute.Arguments.Add(new CodeAttributeArgument("DataType", new CodePrimitiveExpression(dataTypeDesc.DataType.Name)));
            }
            if (isNullable != null) {
                attribute.Arguments.Add(new CodeAttributeArgument("IsNullable", new CodePrimitiveExpression((bool)isNullable)));
            }
            if (nestingLevel > 0) {
                attribute.Arguments.Add(new CodeAttributeArgument("NestingLevel", new CodePrimitiveExpression(nestingLevel)));
            }
            if (sequenceId >= 0) {
                attribute.Arguments.Add(new CodeAttributeArgument("Order", new CodePrimitiveExpression(sequenceId)));
            }
            if (attribute.Arguments.Count == 0 && attributeType == typeof(XmlElementAttribute)) return;
            metadata.Add(attribute);
        }
Пример #15
0
 void AddCustomAttribute(CodeAttributeDeclarationCollection metadata, Type type, CodeAttributeArgument[] arguments) {
     CodeAttributeDeclaration attribute = new CodeAttributeDeclaration(type.FullName, arguments);
     metadata.Add(attribute);
 }
Пример #16
0
		void GetProfileProviderAttribute (ProfileSection ps, CodeAttributeDeclarationCollection collection,
						  string providerName)
		{
			if (String.IsNullOrEmpty (providerName))
				providerTypeName = FindProviderTypeName (ps, ps.DefaultProvider);
			else
				providerTypeName = FindProviderTypeName (ps, providerName);
			if (providerTypeName == null)
				throw new HttpException (String.Format ("Profile provider type not defined: {0}",
									providerName));
			
			collection.Add (
				new CodeAttributeDeclaration (
					"ProfileProvider",
					new CodeAttributeArgument (
						new CodePrimitiveExpression (providerTypeName)
					)
				)
			);
		}
Пример #17
0
 internal static void AddIncludeMetadata(CodeAttributeDeclarationCollection metadata, StructMapping mapping, Type type) {
     if (mapping.IsAnonymousType)
         return;
     for (StructMapping derived = mapping.DerivedMappings; derived != null; derived = derived.NextDerivedMapping) {
         CodeAttributeDeclaration attribute = new CodeAttributeDeclaration(type.FullName);
         attribute.Arguments.Add(new CodeAttributeArgument(new CodeTypeOfExpression(derived.TypeDesc.FullName)));
         metadata.Add(attribute);
         AddIncludeMetadata(metadata, derived, type);
     }
 }
Пример #18
0
 internal void AddTypeMetadata(CodeAttributeDeclarationCollection metadata, Type type, string defaultName, string name, string ns, bool includeInSchema) {
     CodeAttributeDeclaration attribute = new CodeAttributeDeclaration(type.FullName);
     if (name == null || name.Length == 0) {
         attribute.Arguments.Add(new CodeAttributeArgument("AnonymousType", new CodePrimitiveExpression(true)));
     }
     else {
         if (defaultName != name) {
             attribute.Arguments.Add(new CodeAttributeArgument("TypeName", new CodePrimitiveExpression(name)));
         }
     }
     if (ns != null && ns.Length != 0) {
         attribute.Arguments.Add(new CodeAttributeArgument("Namespace", new CodePrimitiveExpression(ns)));
     }
     if (!includeInSchema) {
         attribute.Arguments.Add(new CodeAttributeArgument("IncludeInSchema", new CodePrimitiveExpression(false)));
     }
     if (attribute.Arguments.Count > 0) {
         metadata.Add(attribute);
     }
 }
        void AddMemberMetadata(CodeMemberField field, CodeAttributeDeclarationCollection metadata, MemberMapping member, string ns, bool forceUseMemberName, CodeCommentStatementCollection comments, CodeConstructor ctor) {
            if (member.Xmlns != null) {
                CodeAttributeDeclaration attribute = new CodeAttributeDeclaration(typeof(XmlNamespaceDeclarationsAttribute).FullName);
                metadata.Add(attribute);
            }
            else if (member.Attribute != null) {
                AttributeAccessor attribute = member.Attribute;
                if (attribute.Any)
                    ExportAnyAttribute(metadata);
                else {
                    TypeMapping mapping = (TypeMapping)attribute.Mapping;
                    string attrName = Accessor.UnescapeName(attribute.Name);
                    bool sameType = mapping.TypeDesc == member.TypeDesc ||
                        (member.TypeDesc.IsArrayLike && mapping.TypeDesc == member.TypeDesc.ArrayElementTypeDesc);
                    bool sameName = attrName == member.Name && !forceUseMemberName;
                    bool sameNs = attribute.Namespace == ns;
                    bool defaultForm = attribute.Form != XmlSchemaForm.Qualified;
                    ExportAttribute(metadata, 
                        sameName ? null : attrName, 
                        sameNs ? null : attribute.Namespace, 
                        sameType ? null : mapping.TypeDesc,
                        mapping.TypeDesc, 
                        defaultForm ? XmlSchemaForm.None : attribute.Form);
                
                    AddDefaultValueAttribute(field, metadata, attribute.Default, mapping, comments, member.TypeDesc, attribute, ctor);
                }
            }
            else {
                if (member.Text != null) {
                    TypeMapping mapping = (TypeMapping)member.Text.Mapping;
                    bool sameType = mapping.TypeDesc == member.TypeDesc ||
                        (member.TypeDesc.IsArrayLike && mapping.TypeDesc == member.TypeDesc.ArrayElementTypeDesc);
                    ExportText(metadata, sameType ? null : mapping.TypeDesc, mapping.TypeDesc.IsAmbiguousDataType ? mapping.TypeDesc.DataType.Name : null);
                }
                if (member.Elements.Length == 1) {
                    ElementAccessor element = member.Elements[0];
                    TypeMapping mapping = (TypeMapping)element.Mapping;
                    string elemName = Accessor.UnescapeName(element.Name);
                    bool sameName = ((elemName == member.Name) && !forceUseMemberName);                    
                    bool isArray = mapping is ArrayMapping;
                    bool sameNs = element.Namespace == ns;
                    bool defaultForm = element.Form != XmlSchemaForm.Unqualified;

                    if (element.Any)
                        ExportAnyElement(metadata, elemName, element.Namespace, member.SequenceId);
                    else if (isArray) {
                        bool sameType = mapping.TypeDesc == member.TypeDesc;
                        ArrayMapping array = (ArrayMapping)mapping;
                        if (!sameName || !sameNs || element.IsNullable || !defaultForm || member.SequenceId != -1)
                            ExportArray(metadata, sameName ? null : elemName, sameNs ? null : element.Namespace, element.IsNullable, defaultForm ? XmlSchemaForm.None : element.Form, member.SequenceId);
                        else if (mapping.TypeDesc.ArrayElementTypeDesc == new TypeScope().GetTypeDesc(typeof(byte))) {
                            // special case for byte[]. It can be a primitive (base64Binary or hexBinary), or it can
                            // be an array of bytes. Our default is primitive; specify [XmlArray] to get array behavior.
                            ExportArray(metadata, null, null, false, XmlSchemaForm.None, member.SequenceId);
                        }
                        ExportArrayElements(metadata, array, element.Namespace, member.TypeDesc.ArrayElementTypeDesc, 0);
                    }
                    else {
                        bool sameType = mapping.TypeDesc == member.TypeDesc ||
                            (member.TypeDesc.IsArrayLike && mapping.TypeDesc == member.TypeDesc.ArrayElementTypeDesc);
                        if (member.TypeDesc.IsArrayLike)
                            sameName = false;
                        ExportElement(metadata, sameName ? null : elemName, sameNs ? null : element.Namespace, sameType ? null : mapping.TypeDesc, mapping.TypeDesc, element.IsNullable, defaultForm ? XmlSchemaForm.None : element.Form, member.SequenceId);
                    }
                    AddDefaultValueAttribute(field, metadata, element.Default, mapping, comments, member.TypeDesc, element, ctor);
                }
                else {
                    for (int i = 0; i < member.Elements.Length; i++) {
                        ElementAccessor element = member.Elements[i];
                        string elemName = Accessor.UnescapeName(element.Name);
                        bool sameNs = element.Namespace == ns;
                        if (element.Any)
                            ExportAnyElement(metadata, elemName, element.Namespace, member.SequenceId);
                        else {
                            bool defaultForm = element.Form != XmlSchemaForm.Unqualified;
                            ExportElement(metadata, elemName, sameNs ? null : element.Namespace, ((TypeMapping)element.Mapping).TypeDesc, ((TypeMapping)element.Mapping).TypeDesc, element.IsNullable, defaultForm ? XmlSchemaForm.None : element.Form, member.SequenceId);
                        }
                    }
                }
                if (member.ChoiceIdentifier != null) {
                    CodeAttributeDeclaration attribute = new CodeAttributeDeclaration(typeof(XmlChoiceIdentifierAttribute).FullName);
                    attribute.Arguments.Add(new CodeAttributeArgument(new CodePrimitiveExpression(member.ChoiceIdentifier.MemberName)));
                    metadata.Add(attribute);
                }
                if (member.Ignore) {
                    CodeAttributeDeclaration attribute = new CodeAttributeDeclaration(typeof(XmlIgnoreAttribute).FullName);
                    metadata.Add(attribute);
                }
            }
        }
		protected override void GenerateElementInfoMember (CodeAttributeDeclarationCollection attributes, XmlTypeMapMemberElement member, XmlTypeMapElementInfo einfo, TypeData defaultType, string defaultNamespace, bool addAlwaysAttr, bool forceUseMemberName)
		{
			CodeAttributeDeclaration att = new CodeAttributeDeclaration ("System.Xml.Serialization.SoapElement");
			if (forceUseMemberName || einfo.ElementName != member.Name) att.Arguments.Add (GetArg (einfo.ElementName));
//			if (einfo.IsNullable) att.Arguments.Add (GetArg ("IsNullable", true));	MS seems to ignore this
			if (!TypeTranslator.IsDefaultPrimitiveTpeData(einfo.TypeData)) att.Arguments.Add (GetArg ("DataType",einfo.TypeData.XmlType));
			if (addAlwaysAttr || att.Arguments.Count > 0) attributes.Add (att);
		}
		public void AddMappingMetadata (CodeAttributeDeclarationCollection metadata, XmlMemberMapping member, bool forceUseMemberName)
		{
			TypeData memType = member.TypeMapMember.TypeData;
			
			CodeAttributeDeclaration att = new CodeAttributeDeclaration ("System.Xml.Serialization.SoapElement");
			if (forceUseMemberName || (member.ElementName != member.MemberName))
				att.Arguments.Add (new CodeAttributeArgument (new CodePrimitiveExpression(member.ElementName)));
			if (!TypeTranslator.IsDefaultPrimitiveTpeData (memType))
				att.Arguments.Add (new CodeAttributeArgument ("DataType", new CodePrimitiveExpression(member.TypeName)));
				
			if (att.Arguments.Count > 0) 
				metadata.Add (att);
		}
		protected override void GenerateClassInclude (CodeAttributeDeclarationCollection attributes, XmlTypeMapping map)
		{
			CodeAttributeDeclaration iatt = new CodeAttributeDeclaration ("System.Xml.Serialization.SoapInclude");
			iatt.Arguments.Add (new CodeAttributeArgument (new CodeTypeOfExpression(map.TypeData.FullTypeName)));
			attributes.Add (iatt);
		}
		protected override void GenerateAttributeMember (CodeAttributeDeclarationCollection attributes, XmlTypeMapMemberAttribute attinfo, string defaultNamespace, bool forceUseMemberName)
		{
			CodeAttributeDeclaration att = new CodeAttributeDeclaration ("System.Xml.Serialization.SoapAttribute");
			if (attinfo.Name != attinfo.AttributeName) att.Arguments.Add (GetArg (attinfo.AttributeName));
			if (attinfo.Namespace != defaultNamespace) att.Arguments.Add (GetArg ("Namespace", attinfo.Namespace));
			if (!TypeTranslator.IsDefaultPrimitiveTpeData(attinfo.TypeData)) att.Arguments.Add (GetArg ("DataType",attinfo.TypeData.XmlType));
			attributes.Add (att);
		}
Пример #24
0
 //[JsonProperty("extension")]
 private static void AddJsonPropertyAttritbute(CodeAttributeDeclarationCollection attributes, string name)
 {
     attributes.Add(new CodeAttributeDeclaration("JsonProperty", new CodeAttributeArgument(new CodePrimitiveExpression(name))));
 }
Пример #25
0
 internal static CodeAttributeDeclaration AddAttribute(CodeAttributeDeclarationCollection col,
     CodeTypeReference type,
     CodeExpression[] arguments)
 {
     CodeAttributeArgument[] attributeArguments = new CodeAttributeArgument[arguments.Length];
     for (int i = 0; i < arguments.Length; i++) {
         attributeArguments[i] = new CodeAttributeArgument(arguments[i]);
     }
     CodeAttributeDeclaration cad = new CodeAttributeDeclaration(type, attributeArguments);
     col.Add(cad);
     return cad;
 }
Пример #26
0
 //[EnumMember(Value = "flash")]
 private static void AddEnumMemberAttribute(CodeAttributeDeclarationCollection attributes, string name)
 {
     attributes.Add(new CodeAttributeDeclaration("EnumMember", new CodeAttributeArgument("Value",new CodePrimitiveExpression(name) )));
 }
 private void GenerateProperties(CodeTypeDeclaration taskClass, LinkedList<Property> propertyList)
 {
     foreach (Property property in propertyList)
     {
         if (!string.Equals(property.Name, "import", StringComparison.OrdinalIgnoreCase) && this.ContainsCurrentPlatform(property))
         {
             CodeAttributeDeclarationCollection declarations = new CodeAttributeDeclarationCollection();
             CodeMemberProperty propertyName = new CodeMemberProperty {
                 Name = property.Name,
                 HasGet = true,
                 HasSet = true,
                 Attributes = MemberAttributes.Public
             };
             if (!string.IsNullOrEmpty(property.DefaultValue))
             {
                 this.taskParser.DefaultSet.AddLast(property);
             }
             if (!string.IsNullOrEmpty(property.Required) && (property.Required == "true"))
             {
                 declarations.Add(new CodeAttributeDeclaration("Required"));
             }
             if (property.Output)
             {
                 declarations.Add(new CodeAttributeDeclaration("Output"));
             }
             if (string.IsNullOrEmpty(property.Argument) && !string.IsNullOrEmpty(property.Fallback))
             {
                 this.taskParser.FallbackSet.Add(property.Name, property.Fallback);
             }
             if (property.Type == PropertyType.StringArray)
             {
                 this.GenerateStringArrays(property, propertyName);
             }
             else if (property.Type == PropertyType.String)
             {
                 this.GenerateStrings(property, propertyName);
             }
             else if (property.Type == PropertyType.Boolean)
             {
                 this.GenerateBooleans(property, propertyName);
             }
             else if (property.Type == PropertyType.Integer)
             {
                 this.GenerateIntegers(property, propertyName);
             }
             else if (property.Type == PropertyType.ItemArray)
             {
                 this.GenerateITaskItemArray(property, propertyName);
             }
             else
             {
                 this.LogError("ImproperType", new object[] { property.Name, property.Type });
             }
             foreach (Property property3 in property.Dependencies)
             {
                 if (!this.dependencyList.ContainsKey(property3.Name))
                 {
                     this.dependencyList.Add(property3.Name, property3);
                     property3.Parents.AddLast(property.Name);
                 }
                 else if (!this.dependencyList[property3.Name].Parents.Contains(property.Name))
                 {
                     this.dependencyList[property3.Name].Parents.AddLast(property.Name);
                 }
             }
             this.GenerateOverrides(property, propertyName);
             propertyName.CustomAttributes = declarations;
             taskClass.Members.Add(propertyName);
         }
     }
 }
Пример #28
0
		void GetProfileSettingsSerializeAsAttribute (ProfileSection ps, CodeAttributeDeclarationCollection collection,
							     SerializationMode mode)
		{
			string parameter = String.Concat ("SettingsSerializeAs.", mode.ToString ());
			collection.Add (
				new CodeAttributeDeclaration (
					"SettingsSerializeAs",
					new CodeAttributeArgument (
						new CodeSnippetExpression (parameter)
					)
				)
			);
					
		}
 void ExportText(CodeAttributeDeclarationCollection metadata, TypeDesc typeDesc, string dataType) {
     CodeAttributeDeclaration attribute = new CodeAttributeDeclaration(typeof(XmlTextAttribute).FullName);
     if (typeDesc != null) {
         attribute.Arguments.Add(new CodeAttributeArgument(new CodeTypeOfExpression(typeDesc.FullName)));
     }
     if (dataType != null) {
         attribute.Arguments.Add(new CodeAttributeArgument("DataType", new CodePrimitiveExpression(dataType)));
     }
     metadata.Add(attribute);
 }
		public void Constructor1_Deny_Unrestricted ()
		{
			CodeAttributeDeclarationCollection coll = new CodeAttributeDeclarationCollection (array);
			coll.CopyTo (array, 0);
			Assert.AreEqual (1, coll.Add (cad), "Add");
			Assert.AreSame (cad, coll[0], "this[int]");
			coll.AddRange (array);
			coll.AddRange (coll);
			Assert.IsTrue (coll.Contains (cad), "Contains");
			Assert.AreEqual (0, coll.IndexOf (cad), "IndexOf");
			coll.Insert (0, cad);
			coll.Remove (cad);
		}