static CodeAttributeArgument[] _ToArray(CodeAttributeArgumentCollection args) { var result = new CodeAttributeArgument[args.Count]; args.CopyTo(result, 0); return(result); }
public void AddRange() { CodeAttributeArgument caa1 = new CodeAttributeArgument(); CodeAttributeArgument caa2 = new CodeAttributeArgument(); CodeAttributeArgument caa3 = new CodeAttributeArgument(); CodeAttributeArgumentCollection coll1 = new CodeAttributeArgumentCollection(); coll1.Add(caa1); coll1.Add(caa2); CodeAttributeArgumentCollection coll2 = new CodeAttributeArgumentCollection(); coll2.Add(caa3); coll2.AddRange(coll1); Assert.AreEqual(3, coll2.Count, "#1"); Assert.AreEqual(1, coll2.IndexOf(caa1), "#2"); Assert.AreEqual(2, coll2.IndexOf(caa2), "#3"); Assert.AreEqual(0, coll2.IndexOf(caa3), "#4"); CodeAttributeArgumentCollection coll3 = new CodeAttributeArgumentCollection(); coll3.Add(caa3); coll3.AddRange(new CodeAttributeArgument[] { caa1, caa2 }); Assert.AreEqual(3, coll2.Count, "#5"); Assert.AreEqual(1, coll2.IndexOf(caa1), "#6"); Assert.AreEqual(2, coll2.IndexOf(caa2), "#7"); Assert.AreEqual(0, coll2.IndexOf(caa3), "#8"); }
static CodeAttributeArgumentCollection _ParseCustomAttributeArguments(_PC pc) { var result = new CodeAttributeArgumentCollection(); if (ST.lparen != pc.SymbolId) { return(result); } if (!pc.Advance()) { throw new ArgumentException("Unterminated argument list", "input"); } var named = false; while (ST.rparen != pc.SymbolId) { var arg = new CodeAttributeArgument(); if (ST.identifier == pc.SymbolId) { var s = pc.Value; var pc2 = pc.GetLookAhead(); pc2.EnsureStarted(); pc2.Advance(); _SkipComments(pc2); if (ST.eq == pc2.SymbolId) { pc.Advance(); _SkipComments(pc); pc.Advance(); arg.Name = s; arg.Value = _ParseExpression(pc); result.Add(arg); named = true; continue; } } if (named) { throw new ArgumentException("Named custom attribute arguments must follow the unnamed arguments.", "input"); } var exp = _ParseExpression(pc); _SkipComments(pc); arg.Value = exp; result.Add(arg); if (ST.comma == pc.SymbolId) { if (!pc.Advance()) { throw new ArgumentException("Unterminated argument list.", "input"); } } } if (ST.rparen != pc.SymbolId) { throw new ArgumentException("Unterminated argument list.", "input"); } pc.Advance(); return(result); }
public void CloneAttributeArguments(CodeAttributeArgumentCollection source, CodeAttributeArgumentCollection dest) { dest.Clear(); foreach (CodeAttributeArgument arg in source) { dest.Add(CloneAttributeArgument(arg)); } }
public void Constructor1_NullItem() { CodeAttributeArgument[] arguments = new CodeAttributeArgument[] { new CodeAttributeArgument(), null }; CodeAttributeArgumentCollection coll = new CodeAttributeArgumentCollection( arguments); }
public void AddRange_Self() { CodeAttributeArgumentCollection coll = new CodeAttributeArgumentCollection(); coll.Add(new CodeAttributeArgument()); Assert.AreEqual(1, coll.Count, "#1"); coll.AddRange(coll); Assert.AreEqual(2, coll.Count, "#2"); }
/// <summary> /// Adds "Item" property if not exists already /// Adds attributes to "Item" property /// </summary> /// <param name="classToAddItem">Class in which "Item" property to be added</param> /// <param name="XmlAttributeName">Xml attribute to be added to "Item" property</param> private void HandleChoiceElement(CodeTypeDeclaration classToAddItem, string XmlAttributeName) { bool itemPropertyFound = false; bool attrFound = false; foreach (CodeTypeMember codeTypeMember in classToAddItem.Members) { CodeMemberProperty codeMemField = codeTypeMember as CodeMemberProperty; if (codeMemField != null) { if ((codeMemField != null) && (string.Equals(codeMemField.Name.ToUpper(CultureInfo.InvariantCulture), DataObjectConstants.ITEM.ToUpper(CultureInfo.InvariantCulture)))) { // check whether attributes already added or not CodeAttributeDeclarationCollection attributes = codeMemField.CustomAttributes; foreach (CodeAttributeDeclaration attribute in attributes) { CodeAttributeArgumentCollection arguments = attribute.Arguments; // find arguments for each attributes foreach (CodeAttributeArgument argument in arguments) { CodePrimitiveExpression primitiveExp = argument.Value as CodePrimitiveExpression; if (primitiveExp != null && (primitiveExp.Value != null) && string.Equals(primitiveExp.Value.ToString(), XmlAttributeName) && !string.IsNullOrEmpty(XmlAttributeName)) { attrFound = true; break; } } } if (!attrFound && !string.IsNullOrEmpty(XmlAttributeName)) { // Add attributes to Item property CodeAttributeDeclaration codeAttrDec = new CodeAttributeDeclaration(new CodeTypeReference(typeof(System.Xml.Serialization.XmlElementAttribute))); CodeAttributeArgument nameAttr = new CodeAttributeArgument(new CodePrimitiveExpression(XmlAttributeName)); CodeAttributeArgument typeOfAttr = new CodeAttributeArgument(new CodeTypeOfExpression(XmlAttributeName)); codeAttrDec.Arguments.Add(nameAttr); codeAttrDec.Arguments.Add(typeOfAttr); codeMemField.CustomAttributes.Add(codeAttrDec); } itemPropertyFound = true; break; } } } // Add Item proerpty if not exists already if (!itemPropertyFound && !string.IsNullOrEmpty(XmlAttributeName)) { this.AddItemProperty(classToAddItem, XmlAttributeName); } }
public void Constructor0() { CodeAttributeArgumentCollection coll = new CodeAttributeArgumentCollection(); 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 void RefactorCodeTypeReferencesInAttributeArguments(CodeAttributeArgumentCollection arguments, string oldName, string newName) { foreach (CodeAttributeArgument argument in arguments) { CodeTypeReference typeRef = GetCodeTypeReferenceInCodeExpression(argument.Value); if (typeRef != null) { RefactorCodeTypeReference(typeRef, oldName, newName); } } }
void ParseArguments(CodeAttributeArgumentCollection oArguments, GenMember oGenMember) { CodePrimitiveExpression oPrimitiveExpression = null; CodeTypeOfExpression oTypeOfExpression = null; string sNamespace = null; bool? bForm = null; foreach (CodeAttributeArgument argument in oArguments) { if ("" == argument.Name) { if (argument.Value is CodePrimitiveExpression) { oPrimitiveExpression = argument.Value as CodePrimitiveExpression; } else if (argument.Value is CodeTypeOfExpression) { oTypeOfExpression = argument.Value as CodeTypeOfExpression; } } else if ("Namespace" == argument.Name) { sNamespace = ((CodePrimitiveExpression)argument.Value).Value.ToString(); } else if ("Form" == argument.Name) { string sValue = ((CodeFieldReferenceExpression)argument.Value).FieldName; if ("Qualified" == sValue) { bForm = true; } else if ("Unqualified" == sValue) { bForm = false; } } } if (null != oPrimitiveExpression) { oGenMember.sName = oPrimitiveExpression.Value.ToString(); } if (null != oTypeOfExpression) { InitMemberType(oGenMember, oTypeOfExpression.Type.BaseType); } if (null != sNamespace) { oGenMember.sNamespace = sNamespace; } if (bForm.HasValue) { oGenMember.bQualified = bForm.Value; } }
public static void ReplaceType(this CodeAttributeArgumentCollection collection, string oldType, string newType) { if (collection == null) { return; } foreach (CodeAttributeArgument argument in collection) { argument.ReplaceType(oldType, newType); } }
public static CodeAttributeArgument FindArgumentByName(this CodeAttributeArgumentCollection arguments, string name) { foreach (CodeAttributeArgument argument in arguments) { if (argument.Name == name) { return(argument); } } return(null); }
public void Constructor1() { CodeAttributeArgument caa1 = new CodeAttributeArgument(); CodeAttributeArgument caa2 = new CodeAttributeArgument(); CodeAttributeArgument[] arguments = new CodeAttributeArgument[] { caa1, caa2 }; CodeAttributeArgumentCollection coll = new CodeAttributeArgumentCollection( arguments); Assert.AreEqual(2, coll.Count, "#1"); Assert.AreEqual(0, coll.IndexOf(caa1), "#2"); Assert.AreEqual(1, coll.IndexOf(caa2), "#3"); }
public static CodeAttributeArgumentCollection Clone(this CodeAttributeArgumentCollection collection) { if (collection == null) { return(null); } CodeAttributeArgumentCollection c = new CodeAttributeArgumentCollection(); foreach (CodeAttributeArgument argument in collection) { c.Add(argument.Clone()); } return(c); }
public void Constructor1_Deny_Unrestricted() { CodeAttributeArgumentCollection coll = new CodeAttributeArgumentCollection(array); coll.CopyTo(array, 0); Assert.AreEqual(1, coll.Add(caa), "Add"); Assert.AreSame(caa, coll[0], "this[int]"); coll.AddRange(array); coll.AddRange(coll); Assert.IsTrue(coll.Contains(caa), "Contains"); Assert.AreEqual(0, coll.IndexOf(caa), "IndexOf"); coll.Insert(0, caa); coll.Remove(caa); }
public void Insert() { CodeAttributeArgument caa1 = new CodeAttributeArgument(); CodeAttributeArgument caa2 = new CodeAttributeArgument(); CodeAttributeArgumentCollection coll = new CodeAttributeArgumentCollection(); coll.Add(caa1); Assert.AreEqual(1, coll.Count, "#1"); Assert.AreEqual(0, coll.IndexOf(caa1), "#2"); coll.Insert(0, caa2); Assert.AreEqual(2, coll.Count, "#3"); Assert.AreEqual(1, coll.IndexOf(caa1), "#4"); Assert.AreEqual(0, coll.IndexOf(caa2), "#5"); }
void AddOutputCacheAttribute() { CodeAttributeDeclaration cad; cad = new CodeAttributeDeclaration("System.Web.UI.PartialCachingAttribute"); CodeAttributeArgumentCollection arguments = cad.Arguments; AddPrimitiveArgument(arguments, parser.OutputCacheDuration); AddPrimitiveArgument(arguments, parser.OutputCacheVaryByParam); AddPrimitiveArgument(arguments, parser.OutputCacheVaryByControls); AddPrimitiveArgument(arguments, parser.OutputCacheVaryByCustom); AddPrimitiveArgument(arguments, parser.OutputCacheSqlDependency); AddPrimitiveArgument(arguments, parser.OutputCacheShared); arguments.Add(new CodeAttributeArgument("ProviderName", new CodePrimitiveExpression(parser.ProviderName))); mainClass.CustomAttributes.Add(cad); }
public void Constructor2() { CodeAttributeArgument caa1 = new CodeAttributeArgument(); CodeAttributeArgument caa2 = new CodeAttributeArgument(); CodeAttributeArgumentCollection c = new CodeAttributeArgumentCollection(); c.Add(caa1); c.Add(caa2); CodeAttributeArgumentCollection coll = new CodeAttributeArgumentCollection(c); Assert.AreEqual(2, coll.Count, "#1"); Assert.AreEqual(0, coll.IndexOf(caa1), "#2"); Assert.AreEqual(1, coll.IndexOf(caa2), "#3"); }
/// <summary> /// Removes attributes from Items property /// </summary> /// <param name="classToAddItem">Class in which "Items" property is present</param> /// <param name="XmlAttributeName">Xml attribute to be revemod from class</param> private void RemoveXmlAttributeFromItems(CodeTypeDeclaration classToAddItem, string XmlAttributeName) { int attrCount = 0; bool attrFound = false; foreach (CodeTypeMember codeTypeMember in classToAddItem.Members) { CodeMemberProperty codeMemField = codeTypeMember as CodeMemberProperty; if (codeMemField != null) { // Check whether class has "Items" property if ((codeMemField != null) && (string.Equals(codeMemField.Name.ToUpper(), DataObjectConstants.ITEMS.ToUpper()))) { CodeAttributeDeclarationCollection attributes = codeMemField.CustomAttributes; // Check Attribute to be removed is present foreach (CodeAttributeDeclaration attribute in attributes) { CodeAttributeArgumentCollection arguments = attribute.Arguments; foreach (CodeAttributeArgument argument in arguments) { CodePrimitiveExpression primitiveExp = argument.Value as CodePrimitiveExpression; if (primitiveExp != null && string.Equals(primitiveExp.Value.ToString(), XmlAttributeName)) { attrFound = true; break; } } if (attrFound) { break; } attrCount++; } // closing Check Attribute to be removed is present if (attrFound) { attributes.RemoveAt(attrCount); attrFound = false; } } // closing Check whether class has "Items" property } } }
private static bool ArgumentAreEquivalents(CodeAttributeArgumentCollection testCaseAttributeArguments, CodeAttributeArgument[] arguments) { if (testCaseAttributeArguments.Count != arguments.Length) { return(false); } if (testCaseAttributeArguments.Count == 0) { return(true); } for (int i = 0; i < testCaseAttributeArguments.Count; i++) { if (!AreEqual(arguments[i].Value, testCaseAttributeArguments[i].Value)) { return(false); } } return(true); }
/// <summary> /// Replaces DataType="date" with DataType="dateTime" in System.Xml.Serialization.XmlElementAttribute /// </summary> /// <param name="codedomElement">Codedom element to be modified</param> private void ReplaceDateTime(CodeTypeDeclaration codedomElement) { CodeTypeMemberCollection typeMembers = codedomElement.Members; // Loop thru each member/property of the class for (int memberCount = 0; memberCount < typeMembers.Count; memberCount++) { CodeMemberProperty typeProperty = typeMembers[memberCount] as CodeMemberProperty; if (typeProperty != null) { // Loop for each xml attribute in the propery foreach (CodeAttributeDeclaration xmlAttribute in typeProperty.CustomAttributes) { if (string.Equals(xmlAttribute.Name, DataObjectConstants.XMLSERIALIZEATTRIBUTE)) { CodeAttributeArgumentCollection argColl = xmlAttribute.Arguments; // loop for each arguments in the attribute foreach (CodeAttributeArgument avaiArg in argColl) { CodePrimitiveExpression dateExpression = avaiArg.Value as CodePrimitiveExpression; if (dateExpression != null && dateExpression.Value != null) { if (string.Equals(dateExpression.Value.ToString().ToUpper(), "DATE")) { avaiArg.Value = new CodePrimitiveExpression("dateTime"); } } } // loop for each arguments } } // Loop for each xml attribute } } }
public void AddRange(CodeAttributeArgumentCollection value) {}
// CodeAttributeArgumentCollection public void CodeAttributeArgumentCollectionExample() { //<Snippet1> //<Snippet2> // Creates an empty CodeAttributeArgumentCollection. CodeAttributeArgumentCollection collection = new CodeAttributeArgumentCollection(); //</Snippet2> //<Snippet3> // Adds a CodeAttributeArgument to the collection. collection.Add(new CodeAttributeArgument("Test Boolean Argument", new CodePrimitiveExpression(true))); //</Snippet3> //<Snippet4> // Adds an array of CodeAttributeArgument objects to the collection. CodeAttributeArgument[] arguments = { new CodeAttributeArgument(), new CodeAttributeArgument() }; collection.AddRange(arguments); // Adds a collection of CodeAttributeArgument objects to // the collection. CodeAttributeArgumentCollection argumentsCollection = new CodeAttributeArgumentCollection(); argumentsCollection.Add(new CodeAttributeArgument("TestBooleanArgument", new CodePrimitiveExpression(true))); argumentsCollection.Add(new CodeAttributeArgument("TestIntArgument", new CodePrimitiveExpression(1))); collection.AddRange(argumentsCollection); //</Snippet4> //<Snippet5> // Tests for the presence of a CodeAttributeArgument // within the collection, and retrieves its index if it is found. CodeAttributeArgument testArgument = new CodeAttributeArgument("Test Boolean Argument", new CodePrimitiveExpression(true)); int itemIndex = -1; if (collection.Contains(testArgument)) { itemIndex = collection.IndexOf(testArgument); } //</Snippet5> //<Snippet6> // Copies the contents of the collection beginning at index 0, // to the specified CodeAttributeArgument array. // 'arguments' is a CodeAttributeArgument array. collection.CopyTo(arguments, 0); //</Snippet6> //<Snippet7> // Retrieves the count of the items in the collection. int collectionCount = collection.Count; //</Snippet7> //<Snippet8> // Inserts a CodeAttributeArgument at index 0 of the collection. collection.Insert(0, new CodeAttributeArgument("Test Boolean Argument", new CodePrimitiveExpression(true))); //</Snippet8> //<Snippet9> // Removes the specified CodeAttributeArgument from the collection. CodeAttributeArgument argument = new CodeAttributeArgument("Test Boolean Argument", new CodePrimitiveExpression(true)); collection.Remove(argument); //</Snippet9> //<Snippet10> // Removes the CodeAttributeArgument at index 0. collection.RemoveAt(0); //</Snippet10> //</Snippet1> }
public CodeAttributeArgumentCollection(CodeAttributeArgumentCollection value) {}
public static IList <CodeAttributeArgument> GetAttributeArguments(this CodeAttributeArgumentCollection args) { return(args.Cast <CodeAttributeArgument>().ToList()); }
public static CodeAttributeArgument Find(this CodeAttributeArgumentCollection attributes, string argName) { return(attributes.Cast <CodeAttributeArgument>().FirstOrDefault(arg => arg.Name == argName)); }
public void AddRange_Null_Item() { CodeAttributeArgumentCollection coll = new CodeAttributeArgumentCollection(); coll.AddRange(new CodeAttributeArgument[] { null }); }
public void AddRange_Null_Collection() { CodeAttributeArgumentCollection coll = new CodeAttributeArgumentCollection(); coll.AddRange((CodeAttributeArgumentCollection)null); }
public void Remove_NotInCollection() { CodeAttributeArgumentCollection coll = new CodeAttributeArgumentCollection(); coll.Remove(new CodeAttributeArgument()); }
public void Remove_Null() { CodeAttributeArgumentCollection coll = new CodeAttributeArgumentCollection(); coll.Remove((CodeAttributeArgument)null); }
void AddPrimitiveArgument(CodeAttributeArgumentCollection arguments, object obj) { arguments.Add(new CodeAttributeArgument(new CodePrimitiveExpression(obj))); }
public void Constructor1_Null() { CodeAttributeArgumentCollection coll = new CodeAttributeArgumentCollection( (CodeAttributeArgument[])null); }