Code:
/ 4.0 / 4.0 / DEVDIV_TFS / Dev10 / Releases / RTMRel / ndp / clr / src / BCL / System / ConsoleKeyInfo.cs / 1305376 / ConsoleKeyInfo.cs
using System.Diagnostics.Contracts; // ==++== // // Copyright (c) Microsoft Corporation. All rights reserved. // // ==--== /*============================================================================== ** ** Class: ConsoleKeyInfo ** ** ** Purpose: This value type represents a single key press, with modifier keys ** like Alt, Control, and Shift. ** ** =============================================================================*/ namespace System { [Serializable] public struct ConsoleKeyInfo { private char _keyChar; private ConsoleKey _key; private ConsoleModifiers _mods; public ConsoleKeyInfo(char keyChar, ConsoleKey key, bool shift, bool alt, bool control) { // Limit ConsoleKey values to 0 to 255, but don't check whether the // key is a valid value in our ConsoleKey enum. There are a few // values in that enum that we didn't define, and reserved keys // that might start showing up on keyboards in a few years. if (((int)key) < 0 || ((int)key) > 255) throw new ArgumentOutOfRangeException("key", Environment.GetResourceString("ArgumentOutOfRange_ConsoleKey")); Contract.EndContractBlock(); _keyChar = keyChar; _key = key; _mods = 0; if (shift) _mods |= ConsoleModifiers.Shift; if (alt) _mods |= ConsoleModifiers.Alt; if (control) _mods |= ConsoleModifiers.Control; } public char KeyChar { get { return _keyChar; } } public ConsoleKey Key { get { return _key; } } public ConsoleModifiers Modifiers { get { return _mods; } } public override bool Equals(Object value) { if (value is ConsoleKeyInfo) return Equals((ConsoleKeyInfo)value); else return false; } public bool Equals(ConsoleKeyInfo obj) { return obj._keyChar == _keyChar && obj._key == _key && obj._mods == _mods; } public static bool operator ==(ConsoleKeyInfo a, ConsoleKeyInfo b) { return a.Equals(b); } public static bool operator !=(ConsoleKeyInfo a, ConsoleKeyInfo b) { return !(a == b); } public override int GetHashCode() { return (int)_keyChar | (int) _mods; } } } // File provided for Reference Use Only by Microsoft Corporation (c) 2007. // Copyright (c) Microsoft Corporation. All rights reserved. using System.Diagnostics.Contracts; // ==++== // // Copyright (c) Microsoft Corporation. All rights reserved. // // ==--== /*============================================================================== ** ** Class: ConsoleKeyInfo ** ** ** Purpose: This value type represents a single key press, with modifier keys ** like Alt, Control, and Shift. ** ** =============================================================================*/ namespace System { [Serializable] public struct ConsoleKeyInfo { private char _keyChar; private ConsoleKey _key; private ConsoleModifiers _mods; public ConsoleKeyInfo(char keyChar, ConsoleKey key, bool shift, bool alt, bool control) { // Limit ConsoleKey values to 0 to 255, but don't check whether the // key is a valid value in our ConsoleKey enum. There are a few // values in that enum that we didn't define, and reserved keys // that might start showing up on keyboards in a few years. if (((int)key) < 0 || ((int)key) > 255) throw new ArgumentOutOfRangeException("key", Environment.GetResourceString("ArgumentOutOfRange_ConsoleKey")); Contract.EndContractBlock(); _keyChar = keyChar; _key = key; _mods = 0; if (shift) _mods |= ConsoleModifiers.Shift; if (alt) _mods |= ConsoleModifiers.Alt; if (control) _mods |= ConsoleModifiers.Control; } public char KeyChar { get { return _keyChar; } } public ConsoleKey Key { get { return _key; } } public ConsoleModifiers Modifiers { get { return _mods; } } public override bool Equals(Object value) { if (value is ConsoleKeyInfo) return Equals((ConsoleKeyInfo)value); else return false; } public bool Equals(ConsoleKeyInfo obj) { return obj._keyChar == _keyChar && obj._key == _key && obj._mods == _mods; } public static bool operator ==(ConsoleKeyInfo a, ConsoleKeyInfo b) { return a.Equals(b); } public static bool operator !=(ConsoleKeyInfo a, ConsoleKeyInfo b) { return !(a == b); } public override int GetHashCode() { return (int)_keyChar | (int) _mods; } } } // 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
- PointKeyFrameCollection.cs
- autovalidator.cs
- SequenceFullException.cs
- ThrowHelper.cs
- SessionIDManager.cs
- CompositionAdorner.cs
- ProcessHostServerConfig.cs
- ProviderSettings.cs
- WebHttpDispatchOperationSelector.cs
- ToolStripHighContrastRenderer.cs
- BuildResultCache.cs
- OutputScopeManager.cs
- ZipIOCentralDirectoryDigitalSignature.cs
- InternalResources.cs
- XmlDataSource.cs
- CallSiteOps.cs
- ZeroOpNode.cs
- SourceElementsCollection.cs
- ServiceRouteHandler.cs
- _SpnDictionary.cs
- MetadataPropertyAttribute.cs
- IisTraceWebEventProvider.cs
- OAVariantLib.cs
- NavigationEventArgs.cs
- TcpTransportSecurityElement.cs
- SafeNativeMethods.cs
- COM2PropertyDescriptor.cs
- TimeStampChecker.cs
- RuleSettings.cs
- FrameworkContentElement.cs
- CodeVariableDeclarationStatement.cs
- MetafileHeaderEmf.cs
- EventManager.cs
- selecteditemcollection.cs
- ImageSource.cs
- TextBoxAutomationPeer.cs
- Transform3DCollection.cs
- BuildManager.cs
- FileFormatException.cs
- DataGridViewTextBoxEditingControl.cs
- NameObjectCollectionBase.cs
- InputLangChangeRequestEvent.cs
- DelegateBodyWriter.cs
- MostlySingletonList.cs
- AuthenticationException.cs
- ClientTarget.cs
- XhtmlBasicTextViewAdapter.cs
- HideDisabledControlAdapter.cs
- FreezableDefaultValueFactory.cs
- PropertyTab.cs
- TextDecoration.cs
- RuntimeWrappedException.cs
- SuppressIldasmAttribute.cs
- Win32Native.cs
- EventData.cs
- ListItemParagraph.cs
- WindowsAltTab.cs
- EncryptedHeader.cs
- XamlReader.cs
- XmlMembersMapping.cs
- ClientRuntimeConfig.cs
- SpeechUI.cs
- WebPartDescriptionCollection.cs
- SafeHandles.cs
- MsmqIntegrationProcessProtocolHandler.cs
- ConfigurationValues.cs
- EntityType.cs
- CurrentChangingEventManager.cs
- WebServiceBindingAttribute.cs
- ListBoxChrome.cs
- DesignerDataConnection.cs
- StylusPointProperty.cs
- _KerberosClient.cs
- CorrelationManager.cs
- HierarchicalDataTemplate.cs
- ReadOnlyMetadataCollection.cs
- XmlUnspecifiedAttribute.cs
- EmptyEnumerator.cs
- CorrelationManager.cs
- OleDbEnumerator.cs
- ClientSponsor.cs
- BinHexDecoder.cs
- TableItemProviderWrapper.cs
- ValueType.cs
- HttpFileCollectionWrapper.cs
- SchemaMapping.cs
- TextElementCollection.cs
- HtmlInputPassword.cs
- ContentElementAutomationPeer.cs
- WindowsMenu.cs
- UnionExpr.cs
- ImageButton.cs
- StreamGeometryContext.cs
- XmlMapping.cs
- LinqDataSourceView.cs
- TransportBindingElementImporter.cs
- TableColumn.cs
- Geometry.cs
- ControlBuilderAttribute.cs
- AutoResizedEvent.cs