Code:
/ FX-1434 / FX-1434 / 1.0 / untmp / whidbey / REDBITS / ndp / clr / src / BCL / System / Security / Permissions / FileDialogPermission.cs / 1 / FileDialogPermission.cs
// ==++== // // Copyright (c) Microsoft Corporation. All rights reserved. // // ==--== // FileDialogPermission.cs // namespace System.Security.Permissions { using System; using System.Text; using System.Security; using System.Security.Util; using System.IO; using System.Runtime.Serialization; using System.Reflection; using System.Collections; using System.Globalization; [Serializable, Flags] [System.Runtime.InteropServices.ComVisible(true)] public enum FileDialogPermissionAccess { None = 0x00, Open = 0x01, Save = 0x02, OpenSave = Open | Save } [Serializable] [System.Runtime.InteropServices.ComVisible(true)] public sealed class FileDialogPermission : CodeAccessPermission, IUnrestrictedPermission, IBuiltInPermission { FileDialogPermissionAccess access; public FileDialogPermission(PermissionState state) { if (state == PermissionState.Unrestricted) { SetUnrestricted(true); } else if (state == PermissionState.None) { SetUnrestricted(false); Reset(); } else { throw new ArgumentException(Environment.GetResourceString("Argument_InvalidPermissionState")); } } public FileDialogPermission(FileDialogPermissionAccess access) { VerifyAccess(access); this.access = access; } public FileDialogPermissionAccess Access { get { return access; } set { VerifyAccess(value); access = value; } } public override IPermission Copy() { return new FileDialogPermission(this.access); } public override void FromXml(SecurityElement esd) { CodeAccessPermission.ValidateElement(esd, this); if (XMLUtil.IsUnrestricted(esd)) { SetUnrestricted(true); return; } access = FileDialogPermissionAccess.None; string accessXml = esd.Attribute("Access"); if (accessXml != null) access = (FileDialogPermissionAccess)Enum.Parse(typeof(FileDialogPermissionAccess), accessXml); } ///int IBuiltInPermission.GetTokenIndex() { return FileDialogPermission.GetTokenIndex(); } internal static int GetTokenIndex() { return BuiltInPermissionIndex.FileDialogPermissionIndex; } public override IPermission Intersect(IPermission target) { if (target == null) { return null; } else if (!VerifyType(target)) { throw new ArgumentException(String.Format(CultureInfo.CurrentCulture, Environment.GetResourceString("Argument_WrongType"), this.GetType().FullName)); } FileDialogPermission operand = (FileDialogPermission)target; FileDialogPermissionAccess intersectAccess = access & operand.Access; if (intersectAccess == FileDialogPermissionAccess.None) return null; else return new FileDialogPermission(intersectAccess); } public override bool IsSubsetOf(IPermission target) { if (target == null) { // Only safe subset if this is empty return access == FileDialogPermissionAccess.None; } try { FileDialogPermission operand = (FileDialogPermission)target; if (operand.IsUnrestricted()) { return true; } else if (this.IsUnrestricted()) { return false; } else { int open = (int)(access & FileDialogPermissionAccess.Open); int save = (int)(access & FileDialogPermissionAccess.Save); int openTarget = (int)(operand.Access & FileDialogPermissionAccess.Open); int saveTarget = (int)(operand.Access & FileDialogPermissionAccess.Save); return open <= openTarget && save <= saveTarget; } } catch (InvalidCastException) { throw new ArgumentException(String.Format(CultureInfo.CurrentCulture, Environment.GetResourceString("Argument_WrongType"), this.GetType().FullName)); } } public bool IsUnrestricted() { return access == FileDialogPermissionAccess.OpenSave; } void Reset() { access = FileDialogPermissionAccess.None; } void SetUnrestricted( bool unrestricted ) { if (unrestricted) { access = FileDialogPermissionAccess.OpenSave; } } public override SecurityElement ToXml() { SecurityElement esd = CodeAccessPermission.CreatePermissionElement( this, "System.Security.Permissions.FileDialogPermission" ); if (!IsUnrestricted()) { if (access != FileDialogPermissionAccess.None) { esd.AddAttribute("Access", Enum.GetName(typeof(FileDialogPermissionAccess), access)); } } else { esd.AddAttribute("Unrestricted", "true"); } return esd; } public override IPermission Union(IPermission target) { if (target == null) { return this.Copy(); } else if (!VerifyType(target)) { throw new ArgumentException(String.Format(CultureInfo.CurrentCulture, Environment.GetResourceString("Argument_WrongType"), this.GetType().FullName)); } FileDialogPermission operand = (FileDialogPermission)target; return new FileDialogPermission(access | operand.Access); } static void VerifyAccess(FileDialogPermissionAccess access) { if ((access & ~FileDialogPermissionAccess.OpenSave) != 0 ) { throw new ArgumentException(String.Format(CultureInfo.CurrentCulture, Environment.GetResourceString("Arg_EnumIllegalVal"), (int)access)); } } } }
Link Menu
This book is available now!
Buy at Amazon US or
Buy at Amazon UK
- KnowledgeBase.cs
- WebServiceResponse.cs
- XPathScanner.cs
- TypeBuilderInstantiation.cs
- OutputCacheProfileCollection.cs
- GridErrorDlg.cs
- DataPagerFieldCollection.cs
- ReflectionUtil.cs
- ValidateNames.cs
- ValueExpressions.cs
- SafeCertificateContext.cs
- XmlMtomWriter.cs
- BuilderInfo.cs
- StorageAssociationSetMapping.cs
- NamespaceTable.cs
- QualifierSet.cs
- VersionConverter.cs
- IBuiltInEvidence.cs
- Quaternion.cs
- SkinBuilder.cs
- MimeMapping.cs
- DefinitionBase.cs
- ListControl.cs
- TextTreeText.cs
- CodeLinePragma.cs
- ListParagraph.cs
- KeyManager.cs
- XmlDataSourceNodeDescriptor.cs
- RequestQueue.cs
- XPathItem.cs
- HttpCapabilitiesSectionHandler.cs
- TabletCollection.cs
- TextFormatterContext.cs
- x509utils.cs
- TreeBuilderXamlTranslator.cs
- ColorAnimationBase.cs
- ProcessProtocolHandler.cs
- SQLStringStorage.cs
- TextWriterEngine.cs
- WpfGeneratedKnownTypes.cs
- SystemColorTracker.cs
- AutoResetEvent.cs
- XmlSchemaSimpleType.cs
- RangeContentEnumerator.cs
- EUCJPEncoding.cs
- TextFormatterImp.cs
- XmlWriterSettings.cs
- AccessibleObject.cs
- ToolboxItemImageConverter.cs
- GridViewColumnHeader.cs
- ViewBase.cs
- ModifierKeysValueSerializer.cs
- CacheSection.cs
- ChtmlCalendarAdapter.cs
- Decorator.cs
- LockedHandleGlyph.cs
- TextSimpleMarkerProperties.cs
- AssemblyCache.cs
- XmlChildEnumerator.cs
- DnsPermission.cs
- SchemaConstraints.cs
- AutomationProperty.cs
- MenuCommands.cs
- SQLStringStorage.cs
- JsonWriter.cs
- RightsManagementErrorHandler.cs
- FormsIdentity.cs
- PageRanges.cs
- HttpModuleAction.cs
- PartialTrustHelpers.cs
- ValueType.cs
- FixedTextBuilder.cs
- XmlQualifiedName.cs
- TextEffect.cs
- FragmentNavigationEventArgs.cs
- XmlCollation.cs
- AddIn.cs
- TextEditorTyping.cs
- ComponentEditorPage.cs
- RichTextBox.cs
- IOException.cs
- Size3DValueSerializer.cs
- DirectoryNotFoundException.cs
- SqlHelper.cs
- MultiPageTextView.cs
- FacetEnabledSchemaElement.cs
- _UriTypeConverter.cs
- Dynamic.cs
- EventWaitHandleSecurity.cs
- safePerfProviderHandle.cs
- AnonymousIdentificationSection.cs
- FileDialogPermission.cs
- control.ime.cs
- Vector3D.cs
- HotSpot.cs
- HtmlProps.cs
- PropertyStore.cs
- ServiceModelActivity.cs
- SystemIcons.cs
- FilterableAttribute.cs