Code:
/ Dotnetfx_Win7_3.5.1 / Dotnetfx_Win7_3.5.1 / 3.5.1 / DEVDIV / depot / DevDiv / releases / whidbey / NetFXspW7 / ndp / clr / src / ManagedLibraries / Security / System / Security / permissions / dataprotectionpermission.cs / 1 / dataprotectionpermission.cs
// ==++==
//
// Copyright (c) Microsoft Corporation. All rights reserved.
//
// ==--==
//
// DataProtectionPermission.cs
//
namespace System.Security.Permissions {
using System.Globalization;
[Serializable()]
public sealed class DataProtectionPermission : CodeAccessPermission, IUnrestrictedPermission {
private DataProtectionPermissionFlags m_flags;
public DataProtectionPermission (PermissionState state) {
if (state == PermissionState.Unrestricted)
m_flags = DataProtectionPermissionFlags.AllFlags;
else if (state == PermissionState.None)
m_flags = DataProtectionPermissionFlags.NoFlags;
else
throw new ArgumentException(SecurityResources.GetResourceString("Argument_InvalidPermissionState"));
}
public DataProtectionPermission (DataProtectionPermissionFlags flag) {
this.Flags = flag;
}
public DataProtectionPermissionFlags Flags {
set {
VerifyFlags(value);
m_flags = value;
}
get {
return m_flags;
}
}
//
// IUnrestrictedPermission implementation
//
public bool IsUnrestricted () {
return m_flags == DataProtectionPermissionFlags.AllFlags;
}
//
// IPermission implementation
//
public override IPermission Union (IPermission target) {
if (target == null)
return this.Copy();
try {
DataProtectionPermission operand = (DataProtectionPermission) target;
DataProtectionPermissionFlags flag_union = m_flags | operand.m_flags;
if (flag_union == DataProtectionPermissionFlags.NoFlags)
return null;
else
return new DataProtectionPermission(flag_union);
}
catch (InvalidCastException) {
throw new ArgumentException(String.Format(CultureInfo.CurrentCulture, SecurityResources.GetResourceString("Argument_WrongType"), this.GetType().FullName));
}
}
public override bool IsSubsetOf (IPermission target) {
if (target == null)
return m_flags == DataProtectionPermissionFlags.NoFlags;
try {
DataProtectionPermission operand = (DataProtectionPermission) target;
DataProtectionPermissionFlags sourceFlag = this.m_flags;
DataProtectionPermissionFlags targetFlag = operand.m_flags;
return ((sourceFlag & targetFlag) == sourceFlag);
}
catch (InvalidCastException) {
throw new ArgumentException(String.Format(CultureInfo.CurrentCulture, SecurityResources.GetResourceString("Argument_WrongType"), this.GetType().FullName));
}
}
public override IPermission Intersect (IPermission target) {
if (target == null)
return null;
try {
DataProtectionPermission operand = (DataProtectionPermission) target;
DataProtectionPermissionFlags flag_intersect = operand.m_flags & this.m_flags;
if (flag_intersect == DataProtectionPermissionFlags.NoFlags)
return null;
else
return new DataProtectionPermission(flag_intersect);
}
catch (InvalidCastException) {
throw new ArgumentException(String.Format(CultureInfo.CurrentCulture, SecurityResources.GetResourceString("Argument_WrongType"), this.GetType().FullName));
}
}
public override IPermission Copy () {
if (this.Flags == DataProtectionPermissionFlags.NoFlags)
return null;
return new DataProtectionPermission(m_flags);
}
//
// FromXml/ToXml
//
public override SecurityElement ToXml () {
SecurityElement securityElement = new SecurityElement("IPermission");
securityElement.AddAttribute("class", this.GetType().FullName + ", " + this.GetType().Module.Assembly.FullName.Replace('\"', '\''));
securityElement.AddAttribute("version", "1");
if (!IsUnrestricted())
securityElement.AddAttribute("Flags", m_flags.ToString());
else
securityElement.AddAttribute("Unrestricted", "true");
return securityElement;
}
public override void FromXml (SecurityElement securityElement) {
if (securityElement == null)
throw new ArgumentNullException("securityElement");
string className = securityElement.Attribute("class");
if (className == null || className.IndexOf(this.GetType().FullName, StringComparison.Ordinal) == -1)
throw new ArgumentException(SecurityResources.GetResourceString("Argument_InvalidClassAttribute"), "securityElement");
string unrestricted = securityElement.Attribute("Unrestricted");
if (unrestricted != null && String.Compare(unrestricted, "true", StringComparison.OrdinalIgnoreCase) == 0) {
m_flags = DataProtectionPermissionFlags.AllFlags;
return;
}
m_flags = DataProtectionPermissionFlags.NoFlags;
string strFlags = securityElement.Attribute("Flags");
if (strFlags != null) {
DataProtectionPermissionFlags flags = (DataProtectionPermissionFlags) Enum.Parse(typeof(DataProtectionPermissionFlags), strFlags);
VerifyFlags(flags);
m_flags = flags;
}
}
internal static void VerifyFlags (DataProtectionPermissionFlags flags) {
if ((flags & ~DataProtectionPermissionFlags.AllFlags) != 0)
throw new ArgumentException(String.Format(CultureInfo.CurrentCulture, SecurityResources.GetResourceString("Arg_EnumIllegalVal"), (int)flags));
}
}
}
// File provided for Reference Use Only by Microsoft Corporation (c) 2007.
// ==++==
//
// Copyright (c) Microsoft Corporation. All rights reserved.
//
// ==--==
//
// DataProtectionPermission.cs
//
namespace System.Security.Permissions {
using System.Globalization;
[Serializable()]
public sealed class DataProtectionPermission : CodeAccessPermission, IUnrestrictedPermission {
private DataProtectionPermissionFlags m_flags;
public DataProtectionPermission (PermissionState state) {
if (state == PermissionState.Unrestricted)
m_flags = DataProtectionPermissionFlags.AllFlags;
else if (state == PermissionState.None)
m_flags = DataProtectionPermissionFlags.NoFlags;
else
throw new ArgumentException(SecurityResources.GetResourceString("Argument_InvalidPermissionState"));
}
public DataProtectionPermission (DataProtectionPermissionFlags flag) {
this.Flags = flag;
}
public DataProtectionPermissionFlags Flags {
set {
VerifyFlags(value);
m_flags = value;
}
get {
return m_flags;
}
}
//
// IUnrestrictedPermission implementation
//
public bool IsUnrestricted () {
return m_flags == DataProtectionPermissionFlags.AllFlags;
}
//
// IPermission implementation
//
public override IPermission Union (IPermission target) {
if (target == null)
return this.Copy();
try {
DataProtectionPermission operand = (DataProtectionPermission) target;
DataProtectionPermissionFlags flag_union = m_flags | operand.m_flags;
if (flag_union == DataProtectionPermissionFlags.NoFlags)
return null;
else
return new DataProtectionPermission(flag_union);
}
catch (InvalidCastException) {
throw new ArgumentException(String.Format(CultureInfo.CurrentCulture, SecurityResources.GetResourceString("Argument_WrongType"), this.GetType().FullName));
}
}
public override bool IsSubsetOf (IPermission target) {
if (target == null)
return m_flags == DataProtectionPermissionFlags.NoFlags;
try {
DataProtectionPermission operand = (DataProtectionPermission) target;
DataProtectionPermissionFlags sourceFlag = this.m_flags;
DataProtectionPermissionFlags targetFlag = operand.m_flags;
return ((sourceFlag & targetFlag) == sourceFlag);
}
catch (InvalidCastException) {
throw new ArgumentException(String.Format(CultureInfo.CurrentCulture, SecurityResources.GetResourceString("Argument_WrongType"), this.GetType().FullName));
}
}
public override IPermission Intersect (IPermission target) {
if (target == null)
return null;
try {
DataProtectionPermission operand = (DataProtectionPermission) target;
DataProtectionPermissionFlags flag_intersect = operand.m_flags & this.m_flags;
if (flag_intersect == DataProtectionPermissionFlags.NoFlags)
return null;
else
return new DataProtectionPermission(flag_intersect);
}
catch (InvalidCastException) {
throw new ArgumentException(String.Format(CultureInfo.CurrentCulture, SecurityResources.GetResourceString("Argument_WrongType"), this.GetType().FullName));
}
}
public override IPermission Copy () {
if (this.Flags == DataProtectionPermissionFlags.NoFlags)
return null;
return new DataProtectionPermission(m_flags);
}
//
// FromXml/ToXml
//
public override SecurityElement ToXml () {
SecurityElement securityElement = new SecurityElement("IPermission");
securityElement.AddAttribute("class", this.GetType().FullName + ", " + this.GetType().Module.Assembly.FullName.Replace('\"', '\''));
securityElement.AddAttribute("version", "1");
if (!IsUnrestricted())
securityElement.AddAttribute("Flags", m_flags.ToString());
else
securityElement.AddAttribute("Unrestricted", "true");
return securityElement;
}
public override void FromXml (SecurityElement securityElement) {
if (securityElement == null)
throw new ArgumentNullException("securityElement");
string className = securityElement.Attribute("class");
if (className == null || className.IndexOf(this.GetType().FullName, StringComparison.Ordinal) == -1)
throw new ArgumentException(SecurityResources.GetResourceString("Argument_InvalidClassAttribute"), "securityElement");
string unrestricted = securityElement.Attribute("Unrestricted");
if (unrestricted != null && String.Compare(unrestricted, "true", StringComparison.OrdinalIgnoreCase) == 0) {
m_flags = DataProtectionPermissionFlags.AllFlags;
return;
}
m_flags = DataProtectionPermissionFlags.NoFlags;
string strFlags = securityElement.Attribute("Flags");
if (strFlags != null) {
DataProtectionPermissionFlags flags = (DataProtectionPermissionFlags) Enum.Parse(typeof(DataProtectionPermissionFlags), strFlags);
VerifyFlags(flags);
m_flags = flags;
}
}
internal static void VerifyFlags (DataProtectionPermissionFlags flags) {
if ((flags & ~DataProtectionPermissionFlags.AllFlags) != 0)
throw new ArgumentException(String.Format(CultureInfo.CurrentCulture, SecurityResources.GetResourceString("Arg_EnumIllegalVal"), (int)flags));
}
}
}
// File provided for Reference Use Only by Microsoft Corporation (c) 2007.
Link Menu

This book is available now!
Buy at Amazon US or
Buy at Amazon UK
- SignerInfo.cs
- WebBrowserNavigatingEventHandler.cs
- Calendar.cs
- ToolStripDropDownItem.cs
- ByteConverter.cs
- WebPartConnectionsCloseVerb.cs
- GroupBox.cs
- SqlDataSource.cs
- Transform.cs
- TextSpan.cs
- BaseParser.cs
- PreviewPrintController.cs
- TagPrefixInfo.cs
- LocalsItemDescription.cs
- UInt32.cs
- UrlAuthFailedErrorFormatter.cs
- MulticastOption.cs
- NamedPermissionSet.cs
- HeaderedContentControl.cs
- dataobject.cs
- AssemblyFilter.cs
- StrongNameUtility.cs
- NetworkCredential.cs
- SimpleLine.cs
- XmlTypeMapping.cs
- VarInfo.cs
- IconConverter.cs
- SignatureSummaryDialog.cs
- TextPointerBase.cs
- DoubleAnimationUsingKeyFrames.cs
- DrawingContextDrawingContextWalker.cs
- DateTimeFormatInfo.cs
- PointAnimationUsingKeyFrames.cs
- DtrList.cs
- DataGridCellsPresenter.cs
- DirtyTextRange.cs
- RelationshipEntry.cs
- TransformationRules.cs
- DBCSCodePageEncoding.cs
- NameValueConfigurationElement.cs
- RectValueSerializer.cs
- ListViewDataItem.cs
- DbDataReader.cs
- Sorting.cs
- StrongNameKeyPair.cs
- BoundingRectTracker.cs
- Suspend.cs
- Parameter.cs
- CookieProtection.cs
- OuterGlowBitmapEffect.cs
- MediaPlayer.cs
- AuthenticationException.cs
- XmlNodeList.cs
- basecomparevalidator.cs
- Int64.cs
- Invariant.cs
- ReaderOutput.cs
- EventDescriptor.cs
- FormViewPageEventArgs.cs
- ContextMenuStrip.cs
- AssemblyNameProxy.cs
- PasswordRecoveryAutoFormat.cs
- RadioButtonRenderer.cs
- TextParagraphView.cs
- ScrollBar.cs
- cryptoapiTransform.cs
- UriExt.cs
- DataTableNameHandler.cs
- ComPlusDiagnosticTraceSchemas.cs
- Module.cs
- PeerObject.cs
- AssemblyLoader.cs
- WebPartConnectionsConnectVerb.cs
- FormatConvertedBitmap.cs
- ScrollBar.cs
- ipaddressinformationcollection.cs
- ProfileManager.cs
- CacheForPrimitiveTypes.cs
- WrapPanel.cs
- ExpressionContext.cs
- EventHandlers.cs
- ListViewGroupConverter.cs
- RTLAwareMessageBox.cs
- ScaleTransform.cs
- GeneralTransform3DGroup.cs
- EntityCollection.cs
- ConfigurationSection.cs
- UniqueIdentifierService.cs
- Variable.cs
- HandleRef.cs
- SqlBulkCopyColumnMapping.cs
- FormViewPageEventArgs.cs
- XPathSelectionIterator.cs
- IisTraceWebEventProvider.cs
- AutomationFocusChangedEventArgs.cs
- PolicyDesigner.cs
- ExpressionBindings.cs
- returneventsaver.cs
- FastEncoder.cs
- NotifyIcon.cs