Code:
/ Dotnetfx_Win7_3.5.1 / Dotnetfx_Win7_3.5.1 / 3.5.1 / DEVDIV / depot / DevDiv / releases / Orcas / NetFXw7 / wpf / src / Core / CSharp / System / Windows / Input / Command / InputBinding.cs / 1 / InputBinding.cs
//---------------------------------------------------------------------------- // // Copyright (C) Microsoft Corporation. All rights reserved. // //--------------------------------------------------------------------------- using System; using System.Security; // SecurityCritical, TreatAsSafe using System.Security.Permissions; using System.Windows; using System.Windows.Markup; using System.ComponentModel; namespace System.Windows.Input { ////// InputBinding - InputGesture and ICommand combination /// Used to specify the binding between Gesture and Command at Element level. /// public class InputBinding : DependencyObject, ICommandSource { #region Constructor ////// Default Constructor - needed to allow markup creation /// protected InputBinding() { } ////// Constructor /// /// Command /// Input Gesture ////// Critical - may associate a secure command with a gesture, in /// these cases we need to demand the appropriate permission. /// TreatAsSafe - Calls CheckSecureCommand which does the appropriate demand. /// [SecurityCritical] public InputBinding(ICommand command, InputGesture gesture) { if (command == null) throw new ArgumentNullException("command"); if (gesture == null) throw new ArgumentNullException("gesture"); // Check before assignment to avoid continuation CheckSecureCommand(command, gesture); _command = command; _gesture = gesture; } #endregion Constructor //----------------------------------------------------- // // Public Methods // //----------------------------------------------------- #region Public Methods ////// Command Object associated /// ////// Critical - may associate a secure command with a gesture, in /// these cases we need to demand the appropriate permission. /// PublicOk - Calls CheckSecureCommand which does the appropriate demand. /// [TypeConverter("System.Windows.Input.CommandConverter, PresentationFramework, Version=" + Microsoft.Internal.BuildInfo.WCP_VERSION + ", Culture=neutral, PublicKeyToken=" + Microsoft.Internal.BuildInfo.WCP_PUBLIC_KEY_TOKEN + ", Custom=null")] [Localizability(LocalizationCategory.NeverLocalize)] // cannot be localized public ICommand Command { get { return _command; } [SecurityCritical] set { if (value == null) throw new ArgumentNullException("value"); lock (_dataLock) { // Check before assignment to avoid continuation // CheckSecureCommand(value, _gesture); _command = value; } } } ////// A parameter for the command. /// public object CommandParameter { get { return _commandParameter; } set { lock (_dataLock) { _commandParameter = value; } } } ////// Where the command should be raised. /// public IInputElement CommandTarget { get { return _commandTarget; } set { lock (_dataLock) { _commandTarget = value; } } } ////// InputGesture associated with the Command /// ////// Critical - may associate a secure command with a gesture, in /// these cases we need to demand the appropriate permission. /// PublicOk - Calls CheckSecureCommand which does the appropriate demand. /// public virtual InputGesture Gesture { // We would like to make this getter non-virtual but that's not legal // in C#. Luckily there is no security issue with leaving it virtual. get { return _gesture; } [SecurityCritical] set { if (value == null) throw new ArgumentNullException("value"); lock (_dataLock) { // Check before assignment to avoid continuation // CheckSecureCommand(_command, value); _gesture = value; } } } #endregion Public Methods //------------------------------------------------------ // // Internal Methods // //----------------------------------------------------- ////// Critical - determines if a command will later make an /// assert. This is critical to be right, because /// later we assume that the binding was protected. /// TreatAsSafe - Demand() is not an unsafe operation /// [SecurityCritical, SecurityTreatAsSafe] void CheckSecureCommand(ICommand command, InputGesture gesture) { ISecureCommand secure = command as ISecureCommand; if (secure != null) { secure.UserInitiatedPermission.Demand(); } } //------------------------------------------------------ // // Private Fields // //------------------------------------------------------ #region Private Fields private ICommand _command = null ; private InputGesture _gesture = null ; private object _commandParameter; private IInputElement _commandTarget; internal static object _dataLock = new object(); #endregion Private Fields } } // File provided for Reference Use Only by Microsoft Corporation (c) 2007. // Copyright (c) Microsoft Corporation. All rights reserved. //---------------------------------------------------------------------------- // // Copyright (C) Microsoft Corporation. All rights reserved. // //--------------------------------------------------------------------------- using System; using System.Security; // SecurityCritical, TreatAsSafe using System.Security.Permissions; using System.Windows; using System.Windows.Markup; using System.ComponentModel; namespace System.Windows.Input { ////// InputBinding - InputGesture and ICommand combination /// Used to specify the binding between Gesture and Command at Element level. /// public class InputBinding : DependencyObject, ICommandSource { #region Constructor ////// Default Constructor - needed to allow markup creation /// protected InputBinding() { } ////// Constructor /// /// Command /// Input Gesture ////// Critical - may associate a secure command with a gesture, in /// these cases we need to demand the appropriate permission. /// TreatAsSafe - Calls CheckSecureCommand which does the appropriate demand. /// [SecurityCritical] public InputBinding(ICommand command, InputGesture gesture) { if (command == null) throw new ArgumentNullException("command"); if (gesture == null) throw new ArgumentNullException("gesture"); // Check before assignment to avoid continuation CheckSecureCommand(command, gesture); _command = command; _gesture = gesture; } #endregion Constructor //----------------------------------------------------- // // Public Methods // //----------------------------------------------------- #region Public Methods ////// Command Object associated /// ////// Critical - may associate a secure command with a gesture, in /// these cases we need to demand the appropriate permission. /// PublicOk - Calls CheckSecureCommand which does the appropriate demand. /// [TypeConverter("System.Windows.Input.CommandConverter, PresentationFramework, Version=" + Microsoft.Internal.BuildInfo.WCP_VERSION + ", Culture=neutral, PublicKeyToken=" + Microsoft.Internal.BuildInfo.WCP_PUBLIC_KEY_TOKEN + ", Custom=null")] [Localizability(LocalizationCategory.NeverLocalize)] // cannot be localized public ICommand Command { get { return _command; } [SecurityCritical] set { if (value == null) throw new ArgumentNullException("value"); lock (_dataLock) { // Check before assignment to avoid continuation // CheckSecureCommand(value, _gesture); _command = value; } } } ////// A parameter for the command. /// public object CommandParameter { get { return _commandParameter; } set { lock (_dataLock) { _commandParameter = value; } } } ////// Where the command should be raised. /// public IInputElement CommandTarget { get { return _commandTarget; } set { lock (_dataLock) { _commandTarget = value; } } } ////// InputGesture associated with the Command /// ////// Critical - may associate a secure command with a gesture, in /// these cases we need to demand the appropriate permission. /// PublicOk - Calls CheckSecureCommand which does the appropriate demand. /// public virtual InputGesture Gesture { // We would like to make this getter non-virtual but that's not legal // in C#. Luckily there is no security issue with leaving it virtual. get { return _gesture; } [SecurityCritical] set { if (value == null) throw new ArgumentNullException("value"); lock (_dataLock) { // Check before assignment to avoid continuation // CheckSecureCommand(_command, value); _gesture = value; } } } #endregion Public Methods //------------------------------------------------------ // // Internal Methods // //----------------------------------------------------- ////// Critical - determines if a command will later make an /// assert. This is critical to be right, because /// later we assume that the binding was protected. /// TreatAsSafe - Demand() is not an unsafe operation /// [SecurityCritical, SecurityTreatAsSafe] void CheckSecureCommand(ICommand command, InputGesture gesture) { ISecureCommand secure = command as ISecureCommand; if (secure != null) { secure.UserInitiatedPermission.Demand(); } } //------------------------------------------------------ // // Private Fields // //------------------------------------------------------ #region Private Fields private ICommand _command = null ; private InputGesture _gesture = null ; private object _commandParameter; private IInputElement _commandTarget; internal static object _dataLock = new object(); #endregion Private Fields } } // File provided for Reference Use Only by Microsoft Corporation (c) 2007. // Copyright (c) Microsoft Corporation. All rights reserved.
Link Menu
This book is available now!
Buy at Amazon US or
Buy at Amazon UK
- DesignerSelectionListAdapter.cs
- DataGridViewLinkCell.cs
- PathNode.cs
- ListViewDeletedEventArgs.cs
- Point3D.cs
- ScriptReferenceBase.cs
- __Error.cs
- Activator.cs
- PersonalizableTypeEntry.cs
- NetworkCredential.cs
- DataGridViewComboBoxCell.cs
- PageStatePersister.cs
- Models.cs
- DecimalConstantAttribute.cs
- SqlFunctionAttribute.cs
- Slider.cs
- ImageSource.cs
- FileVersionInfo.cs
- Mouse.cs
- GroupBox.cs
- Window.cs
- LinkLabel.cs
- Classification.cs
- SelectorAutomationPeer.cs
- CacheChildrenQuery.cs
- PropertyGridDesigner.cs
- NeutralResourcesLanguageAttribute.cs
- CqlWriter.cs
- SqlBuffer.cs
- WindowsRegion.cs
- DbResourceAllocator.cs
- SessionStateItemCollection.cs
- UIElement3D.cs
- ZipIOModeEnforcingStream.cs
- LicenseContext.cs
- Win32SafeHandles.cs
- DataControlField.cs
- PostBackOptions.cs
- DesignerActionService.cs
- DataGridParentRows.cs
- MessageDesigner.cs
- InvokeGenerator.cs
- ApplicationDirectory.cs
- DynamicRenderer.cs
- InfoCardKeyedHashAlgorithm.cs
- FormViewPageEventArgs.cs
- ValidatingReaderNodeData.cs
- ConstraintManager.cs
- DataGridViewAutoSizeModeEventArgs.cs
- NCryptNative.cs
- CollectionViewSource.cs
- UInt16Storage.cs
- DBCSCodePageEncoding.cs
- EntryIndex.cs
- QuaternionKeyFrameCollection.cs
- ParentQuery.cs
- SqlException.cs
- Set.cs
- WCFServiceClientProxyGenerator.cs
- RegionData.cs
- BitVector32.cs
- ContextStaticAttribute.cs
- DragEventArgs.cs
- MultiDataTrigger.cs
- UIElementCollection.cs
- ListViewItemMouseHoverEvent.cs
- PageAsyncTaskManager.cs
- TemplatePropertyEntry.cs
- Highlights.cs
- SecurityManager.cs
- FloatUtil.cs
- DocumentPageHost.cs
- ImageMapEventArgs.cs
- ChildChangedEventArgs.cs
- AspNetHostingPermission.cs
- XsltInput.cs
- ResXResourceWriter.cs
- RelOps.cs
- BindingWorker.cs
- ContextMarshalException.cs
- EventMappingSettingsCollection.cs
- NetworkInformationPermission.cs
- BulletDecorator.cs
- AuthenticatingEventArgs.cs
- SecurityUtils.cs
- ResXDataNode.cs
- AddInToken.cs
- InfoCardTrace.cs
- EntityCommandCompilationException.cs
- ContextProperty.cs
- EntityStoreSchemaGenerator.cs
- ErrorFormatterPage.cs
- QilLiteral.cs
- LocationInfo.cs
- PingOptions.cs
- XMLSyntaxException.cs
- ScriptingProfileServiceSection.cs
- GeneralTransform.cs
- EpmContentSerializerBase.cs
- DbProviderConfigurationHandler.cs