Add() public method

public Add ( PermissionSet permSet ) : void
permSet PermissionSet
return void
        // 2.0 metadata format

        internal static PermissionSetCollection CreateFromBinaryFormat(byte[] data)
        {
            if ((data == null) || (data [0] != 0x2E) || (data.Length < 2))
            {
                string msg = Locale.GetText("Invalid data in 2.0 metadata format.");
                throw new SecurityException(msg);
            }

            int pos     = 1;
            int numattr = PermissionSet.ReadEncodedInt(data, ref pos);
            PermissionSetCollection psc = new PermissionSetCollection();

            for (int i = 0; i < numattr; i++)
            {
                IPermission p = PermissionSet.ProcessAttribute(data, ref pos);
                if (p == null)
                {
                    string msg = Locale.GetText("Unsupported data found in 2.0 metadata format.");
                    throw new SecurityException(msg);
                }

                PermissionSet ps = new PermissionSet(PermissionState.None);
                ps.DeclarativeSecurity = true;
                ps.AddPermission(p);
                psc.Add(ps);
            }
            return(psc);
        }
		public void ToXml ()
		{
			PermissionSetCollection psc = new PermissionSetCollection ();
			SecurityElement se = psc.ToXml ();
			Assert.IsNull (se.Children, "Children==null for 0");
			PermissionSet unr = new PermissionSet (PermissionState.Unrestricted);
			psc.Add (unr);
			se = psc.ToXml ();
			Assert.AreEqual (1, se.Children.Count, "Children==1");
			Assert.AreEqual (unr.ToString (), se.Children[0].ToString (), "XML");
		}
		public void RemoveSet ()
		{
			PermissionSetCollection psc = new PermissionSetCollection ();
			PermissionSet unr = new PermissionSet (PermissionState.Unrestricted);
			psc.Add (unr);
			psc.RemoveSet (0);
			Assert.AreEqual (0, psc.Count, "Count");
		}
		public void GetSet ()
		{
			PermissionSetCollection psc = new PermissionSetCollection ();
			PermissionSet unr = new PermissionSet (PermissionState.Unrestricted);
			psc.Add (unr);
			PermissionSet ps = psc.GetSet (0);
			Assert.AreEqual (unr.ToString (), ps.ToString (), "Same XML");
			Assert.IsTrue (Object.ReferenceEquals (unr, ps), "Same Object Reference");
		}
		public void FromXml_Roundtrip ()
		{
			PermissionSetCollection psc = new PermissionSetCollection ();
			string expected = psc.ToString ();
			SecurityElement se = psc.ToXml ();
			psc.FromXml (se);
			string actual = psc.ToString ();
			Assert.AreEqual (expected, actual, "Empty");

			PermissionSet none = new PermissionSet (PermissionState.None);
			psc.Add (none);
			expected = psc.ToString ();
			se = psc.ToXml ();
			psc.FromXml (se);
			actual = psc.ToString ();
			Assert.AreEqual (expected, actual, "1-None");

			none.AddPermission (new SecurityPermission (SecurityPermissionFlag.Assertion));
			expected = psc.ToString ();
			se = psc.ToXml ();
			psc.FromXml (se);
			actual = psc.ToString ();
			Assert.AreEqual (expected, actual, "1-Assertion");
			Assert.AreEqual (1, psc.Count, "1");

			PermissionSet unr = new PermissionSet (PermissionState.Unrestricted);
			psc.Add (unr);
			expected = psc.ToString ();
			se = psc.ToXml ();
			psc.FromXml (se);
			actual = psc.ToString ();
			Assert.AreEqual (expected, actual, "2-Assertion+Unrestricted");
			Assert.AreEqual (2, psc.Count, "2");
		}
		public void Copy_References ()
		{
			PermissionSet none = new PermissionSet (PermissionState.None);
			PermissionSetCollection psc = new PermissionSetCollection ();
			psc.Add (none);
			PermissionSetCollection copy = psc.Copy ();
			Assert.AreEqual (1, copy.PermissionSets.Count, "Count-1");

			string before = psc.ToString ();
			none.AddPermission (new SecurityPermission (SecurityPermissionFlag.Assertion));

			Assert.AreEqual (none.ToString (), psc.PermissionSets[0].ToString (), "psc");
			Assert.AreEqual (before, copy.ToString (), "copy");
		}
		public void Copy ()
		{
			PermissionSet none = new PermissionSet (PermissionState.None);
			PermissionSet unr = new PermissionSet (PermissionState.Unrestricted);
			PermissionSetCollection psc = new PermissionSetCollection ();
			PermissionSetCollection copy = psc.Copy ();
			Assert.AreEqual (0, copy.PermissionSets.Count, "Count-0");
			psc.Add (none);
			Assert.AreEqual (0, copy.PermissionSets.Count, "Count-0b");
			copy = psc.Copy ();
			Assert.AreEqual (1, copy.PermissionSets.Count, "Count-1");
			psc.Add (none); // re-add same permissionset
			Assert.AreEqual (1, copy.PermissionSets.Count, "Count-1b");
			copy = psc.Copy ();
			Assert.AreEqual (2, copy.PermissionSets.Count, "Count-2");
			psc.Add (unr);
			Assert.AreEqual (2, copy.PermissionSets.Count, "Count-2b");
			copy = psc.Copy ();
			Assert.AreEqual (3, copy.PermissionSets.Count, "Count-3");
			Assert.AreEqual (3, copy.Count, "Count-3");
		}
		public void Add ()
		{
			PermissionSet none = new PermissionSet (PermissionState.None);
			PermissionSet unr = new PermissionSet (PermissionState.Unrestricted);
			PermissionSetCollection psc = new PermissionSetCollection ();
			Assert.AreEqual (0, psc.PermissionSets.Count, "Count-0");
			Assert.AreEqual (0, psc.Count, "Count-0");
			psc.Add (none);
			Assert.AreEqual (1, psc.PermissionSets.Count, "Count-1");
			// re-add same permissionset
			psc.Add (none);
			Assert.AreEqual (2, psc.PermissionSets.Count, "Count-2");
			psc.Add (unr);
			Assert.AreEqual (3, psc.PermissionSets.Count, "Count-3");
			Assert.AreEqual (3, psc.Count, "Count-3");
		}
		public void Add_Null ()
		{
			PermissionSetCollection psc = new PermissionSetCollection ();
			psc.Add (null);
		}
		// 2.0 metadata format

		internal static PermissionSetCollection CreateFromBinaryFormat (byte[] data)
		{
			if ((data == null) || (data [0] != 0x2E) || (data.Length < 2)) {
				string msg = Locale.GetText ("Invalid data in 2.0 metadata format.");
				throw new SecurityException (msg);
			}

			int pos = 1;
			int numattr = PermissionSet.ReadEncodedInt (data, ref pos);
			PermissionSetCollection psc = new PermissionSetCollection ();
			for (int i = 0; i < numattr; i++) {
				IPermission p = PermissionSet.ProcessAttribute (data, ref pos);
				if (p == null) {
					string msg = Locale.GetText ("Unsupported data found in 2.0 metadata format.");
					throw new SecurityException (msg);
				}

				PermissionSet ps = new PermissionSet (PermissionState.None);
				ps.DeclarativeSecurity = true;
				ps.AddPermission (p); 
				psc.Add (ps);
			}
			return psc;
		}