示例#1
0
        public void WriteObject_DataContractIgnoringPrivateMember()
        {
            var dcjs = new DataContractJsonSerializer(typeof(PublicContractAboutPrivateClause));

            using (MemoryStream ms = new MemoryStream()) {
                var c = new PublicContractAboutPrivateClause();
                c.PublicFacingMember = "me";
                // SecretPolicyMakerMember is (default) unassigned
                Assert.Throws <SecurityException, FieldAccessException> (delegate {
                    dcjs.WriteObject(ms, c);
                }, "unassigned private member");
            }
        }
		public void WriteObject_DataContractIgnoringPrivateMember ()
		{
			var dcjs = new DataContractJsonSerializer (typeof (PublicContractAboutPrivateClause));
			using (MemoryStream ms = new MemoryStream ()) {
				var c = new PublicContractAboutPrivateClause ();
				c.PublicFacingMember = "me";
				// SecretPolicyMakerMember is (default) unassigned
				Assert.Throws<SecurityException,FieldAccessException> (delegate {
					dcjs.WriteObject (ms, c);
				}, "unassigned private member");
			}
		}