public void Constructor1_NullItem () { CodeAttributeDeclaration[] declarations = new CodeAttributeDeclaration[] { new CodeAttributeDeclaration (), null }; CodeAttributeDeclarationCollection coll = new CodeAttributeDeclarationCollection ( declarations); }
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; }
public void Constructor0 () { CodeAttributeDeclarationCollection coll = new CodeAttributeDeclarationCollection (); Assert.IsFalse (((IList) coll).IsFixedSize, "#1"); Assert.IsFalse (((IList) coll).IsReadOnly, "#2"); Assert.AreEqual (0, coll.Count, "#3"); Assert.IsFalse (((ICollection) coll).IsSynchronized, "#4"); Assert.IsNotNull (((ICollection) coll).SyncRoot, "#5"); }
private AttributeList Translate(CodeAttributeDeclarationCollection attributes, AttributeList attributeList){ if (attributes == null) return null; int n = attributes.Count; if (attributeList == null) if (n == 0) return null; else attributeList = new AttributeList(n); for (int i = 0; i < n; i++) attributeList.Add(this.Translate(attributes[i])); return attributeList; }
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)))); }
public void AddMappingMetadata (CodeAttributeDeclarationCollection metadata, XmlTypeMapping member, string ns) { if (member.Namespace != ns && member.Namespace != "") { CodeAttributeDeclaration ratt = new CodeAttributeDeclaration ("System.Xml.Serialization.XmlRoot"); ratt.Arguments.Add (MapCodeGenerator.GetArg (member.ElementName)); ratt.Arguments.Add (MapCodeGenerator.GetArg ("Namespace", member.Namespace)); ratt.Arguments.Add (MapCodeGenerator.GetArg ("IsNullable", member.IsNullable)); metadata.Add (ratt); } }
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)))); } }
public void AddRange(CodeAttributeDeclarationCollection value) { if (value == null) { throw new ArgumentNullException("value"); } int count = value.Count; for (int i = 0; i < count; i++) { this.Add(value[i]); } }
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); } } }
public void Constructor1 () { CodeAttributeDeclaration cad1 = new CodeAttributeDeclaration (); CodeAttributeDeclaration cad2 = new CodeAttributeDeclaration (); CodeAttributeDeclaration[] declarations = new CodeAttributeDeclaration[] { cad1, cad2 }; CodeAttributeDeclarationCollection coll = new CodeAttributeDeclarationCollection ( declarations); Assert.AreEqual (2, coll.Count, "#1"); Assert.AreEqual (0, coll.IndexOf (cad1), "#2"); Assert.AreEqual (1, coll.IndexOf (cad2), "#3"); }
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); }
private void AddMemberMetadata(CodeAttributeDeclarationCollection metadata, MemberMapping member, bool forceUseMemberName) { if (member.Elements.Length != 0) { ElementAccessor accessor = member.Elements[0]; TypeMapping mapping = accessor.Mapping; string str = Accessor.UnescapeName(accessor.Name); bool flag = (str == member.Name) && !forceUseMemberName; if ((!flag || mapping.TypeDesc.IsAmbiguousDataType) || accessor.IsNullable) { this.AddElementMetadata(metadata, flag ? null : str, mapping.TypeDesc.IsAmbiguousDataType ? mapping.TypeDesc : null, accessor.IsNullable); } } }
public CodeMemberProperty CreateAutoPropertyWithDataMemberAttribute(string type, string propertyName) { var attributes = new CodeAttributeDeclarationCollection { new CodeAttributeDeclaration("DataMember") }; var codeMemberProperty = new CodeMemberProperty { Name = propertyName, HasGet = true, HasSet = true, CustomAttributes = attributes, Attributes = MemberAttributes.Public, Type = new CodeTypeReference(type) }; return codeMemberProperty; }
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); }
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; }
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; }
internal void AddTypeMetadata(CodeAttributeDeclarationCollection metadata, Type type, string defaultName, string name, string ns, bool includeInSchema) { CodeAttributeDeclaration declaration = new CodeAttributeDeclaration(type.FullName); if ((name == null) || (name.Length == 0)) { declaration.Arguments.Add(new CodeAttributeArgument("AnonymousType", new CodePrimitiveExpression(true))); } else if (defaultName != name) { declaration.Arguments.Add(new CodeAttributeArgument("TypeName", new CodePrimitiveExpression(name))); } if ((ns != null) && (ns.Length != 0)) { declaration.Arguments.Add(new CodeAttributeArgument("Namespace", new CodePrimitiveExpression(ns))); } if (!includeInSchema) { declaration.Arguments.Add(new CodeAttributeArgument("IncludeInSchema", new CodePrimitiveExpression(false))); } if (declaration.Arguments.Count > 0) { metadata.Add(declaration); } }
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); } }
internal static CodeAttributeDeclaration FindAttributeDeclaration(Type type, CodeAttributeDeclarationCollection metadata) { foreach (CodeAttributeDeclaration attribute in metadata) { if (attribute.Name == type.FullName || attribute.Name == type.Name) { return attribute; } } return null; }
/// <summary> /// check whether code attribuate has already been declared. /// </summary> /// <param name="type"></param> /// <param name="metadata"></param> /// <return></return> /// <remarks></remarks> private static bool IsDefinedInCodeAttributeCollection(Type type, CodeAttributeDeclarationCollection metadata) { foreach (CodeAttributeDeclaration attribute in metadata) { if (String.Equals(attribute.Name, type.FullName, StringComparison.Ordinal) || String.Equals(attribute.Name, type.Name, StringComparison.Ordinal)) { return true; } } return false; }
/// <devdoc> /// <para> /// Initializes a new instance of <see cref='System.CodeDom.CodeAttributeDeclarationCollection'/> based on another <see cref='System.CodeDom.CodeAttributeDeclarationCollection'/>. /// </para> /// </devdoc> public CodeAttributeDeclarationCollection(CodeAttributeDeclarationCollection value) { this.AddRange(value); }
protected override void GenerateAttributeDeclarationsStart(System.CodeDom.CodeAttributeDeclarationCollection attributes) { throw new Exception("The method or operation is not implemented."); }
public void AddMappingMetadata (CodeAttributeDeclarationCollection metadata, XmlMemberMapping member) { AddMappingMetadata (metadata, member, false); }
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); }
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); }
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 GenerateAttributeDeclarationsEnd(CodeAttributeDeclarationCollection attributes) { Output.WriteLine("[CodeAttributeDeclarationCollection: {0}]", attributes.ToString()); }
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; }
private static bool IsDefined(Type type, CodeAttributeDeclarationCollection metadata) { foreach (CodeAttributeDeclaration declaration in metadata) { if (declaration.Name == type.FullName || declaration.Name == type.Name) { return true; } } return false; }
private void SetDescription(CodeAttributeDeclarationCollection customAttributes, string description) { // xUnit doesn't have a DescriptionAttribute so using a TraitAttribute instead SetProperty(customAttributes, "Description", description); }
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); }