public IndexOf ( |
||
value | ||
return | int |
public void Constructor1 () { CodeTypeMember tm1 = new CodeTypeMember (); CodeTypeMember tm2 = new CodeTypeMember (); CodeTypeMember[] typeMembers = new CodeTypeMember[] { tm1, tm2 }; CodeTypeMemberCollection coll = new CodeTypeMemberCollection ( typeMembers); Assert.AreEqual (2, coll.Count, "#1"); Assert.AreEqual (0, coll.IndexOf (tm1), "#2"); Assert.AreEqual (1, coll.IndexOf (tm2), "#3"); }
public void Constructor0_Deny_Unrestricted () { CodeTypeMemberCollection coll = new CodeTypeMemberCollection (); Assert.AreEqual (0, coll.Add (ctm), "Add"); Assert.AreSame (ctm, coll[0], "this[int]"); coll.CopyTo (array, 0); coll.AddRange (array); coll.AddRange (coll); Assert.IsTrue (coll.Contains (ctm), "Contains"); Assert.AreEqual (0, coll.IndexOf (ctm), "IndexOf"); coll.Insert (0, ctm); coll.Remove (ctm); }
/// ------------------------------------------------------------------------------------ /// <summary> /// Gets the index of a member method/property by name /// </summary> /// <param name="types">member collection</param> /// <param name="name">name to look for</param> /// <returns>index of member if found, otherwise -1</returns> /// ------------------------------------------------------------------------------------ private int IndexOfMember(CodeTypeMemberCollection types, string name) { foreach (CodeTypeMember member in types) { if (member.Name == name) return types.IndexOf(member); } return -1; }
public void Constructor2 () { CodeTypeMember tm1 = new CodeTypeMember (); CodeTypeMember tm2 = new CodeTypeMember (); CodeTypeMemberCollection c = new CodeTypeMemberCollection (); c.Add (tm1); c.Add (tm2); CodeTypeMemberCollection coll = new CodeTypeMemberCollection (c); Assert.AreEqual (2, coll.Count, "#1"); Assert.AreEqual (0, coll.IndexOf (tm1), "#2"); Assert.AreEqual (1, coll.IndexOf (tm2), "#3"); }
public void Remove () { CodeTypeMember ctm1 = new CodeTypeMember (); CodeTypeMember ctm2 = new CodeTypeMember (); CodeTypeMemberCollection coll = new CodeTypeMemberCollection (); coll.Add (ctm1); coll.Add (ctm2); Assert.AreEqual (2, coll.Count, "#1"); Assert.AreEqual (0, coll.IndexOf (ctm1), "#2"); Assert.AreEqual (1, coll.IndexOf (ctm2), "#3"); coll.Remove (ctm1); Assert.AreEqual (1, coll.Count, "#4"); Assert.AreEqual (-1, coll.IndexOf (ctm1), "#5"); Assert.AreEqual (0, coll.IndexOf (ctm2), "#6"); }
public void AddRange () { CodeTypeMember tm1 = new CodeTypeMember (); CodeTypeMember tm2 = new CodeTypeMember (); CodeTypeMember tm3 = new CodeTypeMember (); CodeTypeMemberCollection coll1 = new CodeTypeMemberCollection (); coll1.Add (tm1); coll1.Add (tm2); CodeTypeMemberCollection coll2 = new CodeTypeMemberCollection (); coll2.Add (tm3); coll2.AddRange (coll1); Assert.AreEqual (3, coll2.Count, "#1"); Assert.AreEqual (1, coll2.IndexOf (tm1), "#2"); Assert.AreEqual (2, coll2.IndexOf (tm2), "#3"); Assert.AreEqual (0, coll2.IndexOf (tm3), "#4"); CodeTypeMemberCollection coll3 = new CodeTypeMemberCollection (); coll3.Add (tm3); coll3.AddRange (new CodeTypeMember[] { tm1, tm2 }); Assert.AreEqual (3, coll2.Count, "#5"); Assert.AreEqual (1, coll2.IndexOf (tm1), "#6"); Assert.AreEqual (2, coll2.IndexOf (tm2), "#7"); Assert.AreEqual (0, coll2.IndexOf (tm3), "#8"); }
public void Insert () { CodeTypeMember tm1 = new CodeTypeMember (); CodeTypeMember tm2 = new CodeTypeMember (); CodeTypeMemberCollection coll = new CodeTypeMemberCollection (); coll.Add (tm1); Assert.AreEqual (1, coll.Count, "#1"); Assert.AreEqual (0, coll.IndexOf (tm1), "#2"); coll.Insert (0, tm2); Assert.AreEqual (2, coll.Count, "#3"); Assert.AreEqual (1, coll.IndexOf (tm1), "#4"); Assert.AreEqual (0, coll.IndexOf (tm2), "#5"); }