Code:
/ Net / Net / 3.5.50727.3053 / DEVDIV / depot / DevDiv / releases / Orcas / SP / 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
- RectKeyFrameCollection.cs
- ToolStripDesigner.cs
- LiteralText.cs
- MessageRpc.cs
- XPathException.cs
- Brushes.cs
- FilteredSchemaElementLookUpTable.cs
- BrowserCapabilitiesCompiler.cs
- DataViewSetting.cs
- Cursors.cs
- WindowsTitleBar.cs
- LocatorPartList.cs
- WebContentFormatHelper.cs
- StyleCollection.cs
- ClientUtils.cs
- TableLayoutPanel.cs
- XmlWrappingReader.cs
- Image.cs
- NetworkInformationPermission.cs
- RectangleGeometry.cs
- InitiatorSessionSymmetricTransportSecurityProtocol.cs
- MutexSecurity.cs
- SQLBinaryStorage.cs
- ListSourceHelper.cs
- TimeSpanStorage.cs
- PropertyState.cs
- Int32RectConverter.cs
- AdornerDecorator.cs
- IpcChannelHelper.cs
- CapiSafeHandles.cs
- SqlException.cs
- ApplicationSecurityManager.cs
- HttpCachePolicy.cs
- RegistryPermission.cs
- ContractNamespaceAttribute.cs
- ArrayConverter.cs
- KeyValuePairs.cs
- EncryptedXml.cs
- XamlDesignerSerializationManager.cs
- Viewport3DAutomationPeer.cs
- SiblingIterators.cs
- SessionStateSection.cs
- ConstraintConverter.cs
- StylusPlugin.cs
- KnownBoxes.cs
- GridEntryCollection.cs
- RtfFormatStack.cs
- ObjectSet.cs
- ListViewTableRow.cs
- FixedHighlight.cs
- WebContentFormatHelper.cs
- ScrollItemProviderWrapper.cs
- TagMapInfo.cs
- UnsafeNativeMethods.cs
- VScrollProperties.cs
- _NetworkingPerfCounters.cs
- WindowsScroll.cs
- BorderGapMaskConverter.cs
- CollectionChangeEventArgs.cs
- CodeAttachEventStatement.cs
- ToolStripStatusLabel.cs
- VScrollProperties.cs
- DefaultExpression.cs
- EncoderBestFitFallback.cs
- FilteredAttributeCollection.cs
- CookieParameter.cs
- basevalidator.cs
- MetadataCollection.cs
- URIFormatException.cs
- SiteMapDataSource.cs
- DataQuery.cs
- ConfigXmlElement.cs
- WebPermission.cs
- PolygonHotSpot.cs
- TableRowGroupCollection.cs
- StorageMappingItemLoader.cs
- ElementProxy.cs
- ContractsBCL.cs
- DataColumn.cs
- DotAtomReader.cs
- EncodedStreamFactory.cs
- PenLineJoinValidation.cs
- DataGridViewRowConverter.cs
- ParameterModifier.cs
- ManifestResourceInfo.cs
- TabControl.cs
- TableLayoutSettingsTypeConverter.cs
- ListControlConvertEventArgs.cs
- EventSourceCreationData.cs
- CellTreeNode.cs
- ReliabilityContractAttribute.cs
- SafeNativeMethods.cs
- StringArrayConverter.cs
- ColorMap.cs
- X509Utils.cs
- FrugalMap.cs
- SqlNamer.cs
- HashSet.cs
- CharKeyFrameCollection.cs
- BamlResourceSerializer.cs