Code:
/ Dotnetfx_Win7_3.5.1 / Dotnetfx_Win7_3.5.1 / 3.5.1 / DEVDIV / depot / DevDiv / releases / whidbey / NetFXspW7 / ndp / fx / src / DataOracleClient / System / Data / OracleClient / OracleBoolean.cs / 1 / OracleBoolean.cs
//------------------------------------------------------------------------------ //// Copyright (c) Microsoft Corporation. All rights reserved. // //[....] //----------------------------------------------------------------------------- namespace System.Data.OracleClient { using System; using System.Data.Common; using System.Diagnostics; using System.Runtime.InteropServices; using System.Globalization; //--------------------------------------------------------------------- // OracleBoolean // // This class implements support for comparisons of other Oracle type // classes that may be null; there is no Boolean data type in oracle // that this maps too; it's merely a convenience class. // [StructLayout(LayoutKind.Sequential)] public struct OracleBoolean : IComparable { private byte _value; // value: 1 (true), 2 (false), 0 (unknown/Null) (see below) private const byte x_Null = 0; private const byte x_True = 1; private const byte x_False = 2; public static readonly OracleBoolean False = new OracleBoolean(false); public static readonly OracleBoolean Null = new OracleBoolean(0, true); public static readonly OracleBoolean One = new OracleBoolean(1); public static readonly OracleBoolean True = new OracleBoolean(true); public static readonly OracleBoolean Zero = new OracleBoolean(0); // Construct a non-null boolean from a boolean value public OracleBoolean(bool value) { this._value = (byte)(value ? x_True : x_False); } // Construct a non-null boolean from a specific value public OracleBoolean(int value) : this(value, false) {} // Construct a potentially null boolean from a specific value private OracleBoolean(int value, bool isNull) { if (isNull) { this._value = x_Null; } else { this._value = (value != 0) ? x_True : x_False; } } private byte ByteValue { get { return _value; } } public bool IsFalse { get { return _value == x_False; } } public bool IsNull { get { return _value == x_Null; } } public bool IsTrue { get { return _value == x_True; } } public bool Value { get { switch (_value) { case x_True: return true; case x_False: return false; default: throw ADP.DataIsNull(); } } } public int CompareTo( object obj ) { if (obj is OracleBoolean) { OracleBoolean i = (OracleBoolean)obj; // If both Null, consider them equal. // Otherwise, Null is less than anything. if (IsNull) { return i.IsNull ? 0 : -1; } else if (i.IsNull) { return 1; } if (this.ByteValue < i.ByteValue) { return -1; } if (this.ByteValue > i.ByteValue) { return 1; } return 0; } throw ADP.WrongType(obj.GetType(), typeof(OracleBoolean)); } public override bool Equals(object value) { if (value is OracleBoolean) { OracleBoolean i = (OracleBoolean)value; if (i.IsNull || IsNull) { return (i.IsNull && IsNull); } else { return (this == i).Value; } } return false; } public override int GetHashCode() { return IsNull ? 0 : _value.GetHashCode(); } public static OracleBoolean Parse(string s) { OracleBoolean ret; try { ret = new OracleBoolean(Int32.Parse(s, CultureInfo.InvariantCulture)); } catch (Exception e) { Type type = e.GetType(); if ( (type == ADP.ArgumentNullExceptionType) || (type == ADP.FormatExceptionType) || (type == ADP.OverflowExceptionType) ) { ret = new OracleBoolean(Boolean.Parse(s)); } else { throw e; } } return ret; } public override string ToString() { if (IsNull) { return ADP.NullString; } return Value.ToString(CultureInfo.CurrentCulture); } public static OracleBoolean And(OracleBoolean x, OracleBoolean y) { // Alternative method for operator & return (x & y); } public static OracleBoolean Equals(OracleBoolean x, OracleBoolean y) { // Alternative method for operator == return (x == y); } public static OracleBoolean NotEquals(OracleBoolean x, OracleBoolean y) { // Alternative method for operator != return (x != y); } public static OracleBoolean OnesComplement(OracleBoolean x) { // Alternative method for operator ~ return (~x); } public static OracleBoolean Or(OracleBoolean x, OracleBoolean y) { // Alternative method for operator | return (x | y); } public static OracleBoolean Xor(OracleBoolean x, OracleBoolean y) { // Alternative method for operator ^ return (x ^ y); } public static implicit operator OracleBoolean(bool x) { // Implicit conversion from bool to OracleBoolean return new OracleBoolean(x); } public static explicit operator OracleBoolean(string x) { // Explicit conversion from string to OracleBoolean return OracleBoolean.Parse(x); } public static explicit operator OracleBoolean(OracleNumber x) { // Explicit conversion from OracleNumber to OracleBoolean return x.IsNull ? Null : new OracleBoolean(x.Value != Decimal.Zero); } public static explicit operator bool(OracleBoolean x) { // Explicit conversion from OracleBoolean to bool. Throw exception if x is Null. return x.Value; } //--------------------------------------------------------------------- // Unary operators //---------------------------------------------------------------------- public static OracleBoolean operator! (OracleBoolean x) { switch (x._value) { case x_True: return OracleBoolean.False; case x_False: return OracleBoolean.True; default: Debug.Assert(x._value == x_Null); return OracleBoolean.Null; } } public static OracleBoolean operator~ (OracleBoolean x) { return (!x); } public static bool operator true (OracleBoolean x) { return x.IsTrue; } public static bool operator false (OracleBoolean x) { return x.IsFalse; } //--------------------------------------------------------------------- // Binary operators //---------------------------------------------------------------------- public static OracleBoolean operator& (OracleBoolean x, OracleBoolean y) { if (x._value == x_False || y._value == x_False) { return OracleBoolean.False; } else if (x._value == x_True && y._value == x_True) { return OracleBoolean.True; } else { return OracleBoolean.Null; } } public static OracleBoolean operator== (OracleBoolean x, OracleBoolean y) { return(x.IsNull || y.IsNull) ? OracleBoolean.Null : new OracleBoolean(x._value == y._value); } public static OracleBoolean operator!= (OracleBoolean x, OracleBoolean y) { return ! (x == y); } public static OracleBoolean operator| (OracleBoolean x, OracleBoolean y) { if (x._value == x_True || y._value == x_True) { return OracleBoolean.True; } else if (x._value == x_False && y._value == x_False) { return OracleBoolean.False; } else { return OracleBoolean.Null; } } public static OracleBoolean operator^ (OracleBoolean x, OracleBoolean y) { return(x.IsNull || y.IsNull) ? Null : new OracleBoolean(x._value != y._value); } } } // File provided for Reference Use Only by Microsoft Corporation (c) 2007. //------------------------------------------------------------------------------ //// Copyright (c) Microsoft Corporation. All rights reserved. // //[....] //----------------------------------------------------------------------------- namespace System.Data.OracleClient { using System; using System.Data.Common; using System.Diagnostics; using System.Runtime.InteropServices; using System.Globalization; //--------------------------------------------------------------------- // OracleBoolean // // This class implements support for comparisons of other Oracle type // classes that may be null; there is no Boolean data type in oracle // that this maps too; it's merely a convenience class. // [StructLayout(LayoutKind.Sequential)] public struct OracleBoolean : IComparable { private byte _value; // value: 1 (true), 2 (false), 0 (unknown/Null) (see below) private const byte x_Null = 0; private const byte x_True = 1; private const byte x_False = 2; public static readonly OracleBoolean False = new OracleBoolean(false); public static readonly OracleBoolean Null = new OracleBoolean(0, true); public static readonly OracleBoolean One = new OracleBoolean(1); public static readonly OracleBoolean True = new OracleBoolean(true); public static readonly OracleBoolean Zero = new OracleBoolean(0); // Construct a non-null boolean from a boolean value public OracleBoolean(bool value) { this._value = (byte)(value ? x_True : x_False); } // Construct a non-null boolean from a specific value public OracleBoolean(int value) : this(value, false) {} // Construct a potentially null boolean from a specific value private OracleBoolean(int value, bool isNull) { if (isNull) { this._value = x_Null; } else { this._value = (value != 0) ? x_True : x_False; } } private byte ByteValue { get { return _value; } } public bool IsFalse { get { return _value == x_False; } } public bool IsNull { get { return _value == x_Null; } } public bool IsTrue { get { return _value == x_True; } } public bool Value { get { switch (_value) { case x_True: return true; case x_False: return false; default: throw ADP.DataIsNull(); } } } public int CompareTo( object obj ) { if (obj is OracleBoolean) { OracleBoolean i = (OracleBoolean)obj; // If both Null, consider them equal. // Otherwise, Null is less than anything. if (IsNull) { return i.IsNull ? 0 : -1; } else if (i.IsNull) { return 1; } if (this.ByteValue < i.ByteValue) { return -1; } if (this.ByteValue > i.ByteValue) { return 1; } return 0; } throw ADP.WrongType(obj.GetType(), typeof(OracleBoolean)); } public override bool Equals(object value) { if (value is OracleBoolean) { OracleBoolean i = (OracleBoolean)value; if (i.IsNull || IsNull) { return (i.IsNull && IsNull); } else { return (this == i).Value; } } return false; } public override int GetHashCode() { return IsNull ? 0 : _value.GetHashCode(); } public static OracleBoolean Parse(string s) { OracleBoolean ret; try { ret = new OracleBoolean(Int32.Parse(s, CultureInfo.InvariantCulture)); } catch (Exception e) { Type type = e.GetType(); if ( (type == ADP.ArgumentNullExceptionType) || (type == ADP.FormatExceptionType) || (type == ADP.OverflowExceptionType) ) { ret = new OracleBoolean(Boolean.Parse(s)); } else { throw e; } } return ret; } public override string ToString() { if (IsNull) { return ADP.NullString; } return Value.ToString(CultureInfo.CurrentCulture); } public static OracleBoolean And(OracleBoolean x, OracleBoolean y) { // Alternative method for operator & return (x & y); } public static OracleBoolean Equals(OracleBoolean x, OracleBoolean y) { // Alternative method for operator == return (x == y); } public static OracleBoolean NotEquals(OracleBoolean x, OracleBoolean y) { // Alternative method for operator != return (x != y); } public static OracleBoolean OnesComplement(OracleBoolean x) { // Alternative method for operator ~ return (~x); } public static OracleBoolean Or(OracleBoolean x, OracleBoolean y) { // Alternative method for operator | return (x | y); } public static OracleBoolean Xor(OracleBoolean x, OracleBoolean y) { // Alternative method for operator ^ return (x ^ y); } public static implicit operator OracleBoolean(bool x) { // Implicit conversion from bool to OracleBoolean return new OracleBoolean(x); } public static explicit operator OracleBoolean(string x) { // Explicit conversion from string to OracleBoolean return OracleBoolean.Parse(x); } public static explicit operator OracleBoolean(OracleNumber x) { // Explicit conversion from OracleNumber to OracleBoolean return x.IsNull ? Null : new OracleBoolean(x.Value != Decimal.Zero); } public static explicit operator bool(OracleBoolean x) { // Explicit conversion from OracleBoolean to bool. Throw exception if x is Null. return x.Value; } //--------------------------------------------------------------------- // Unary operators //---------------------------------------------------------------------- public static OracleBoolean operator! (OracleBoolean x) { switch (x._value) { case x_True: return OracleBoolean.False; case x_False: return OracleBoolean.True; default: Debug.Assert(x._value == x_Null); return OracleBoolean.Null; } } public static OracleBoolean operator~ (OracleBoolean x) { return (!x); } public static bool operator true (OracleBoolean x) { return x.IsTrue; } public static bool operator false (OracleBoolean x) { return x.IsFalse; } //--------------------------------------------------------------------- // Binary operators //---------------------------------------------------------------------- public static OracleBoolean operator& (OracleBoolean x, OracleBoolean y) { if (x._value == x_False || y._value == x_False) { return OracleBoolean.False; } else if (x._value == x_True && y._value == x_True) { return OracleBoolean.True; } else { return OracleBoolean.Null; } } public static OracleBoolean operator== (OracleBoolean x, OracleBoolean y) { return(x.IsNull || y.IsNull) ? OracleBoolean.Null : new OracleBoolean(x._value == y._value); } public static OracleBoolean operator!= (OracleBoolean x, OracleBoolean y) { return ! (x == y); } public static OracleBoolean operator| (OracleBoolean x, OracleBoolean y) { if (x._value == x_True || y._value == x_True) { return OracleBoolean.True; } else if (x._value == x_False && y._value == x_False) { return OracleBoolean.False; } else { return OracleBoolean.Null; } } public static OracleBoolean operator^ (OracleBoolean x, OracleBoolean y) { return(x.IsNull || y.IsNull) ? Null : new OracleBoolean(x._value != y._value); } } } // 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
- SecurityContext.cs
- SafeMILHandle.cs
- CardSpaceShim.cs
- DoubleLinkListEnumerator.cs
- OracleFactory.cs
- AppDomainManager.cs
- ReadOnlyHierarchicalDataSource.cs
- Int32CAMarshaler.cs
- SettingsSavedEventArgs.cs
- WindowsRegion.cs
- SizeAnimationBase.cs
- ItemAutomationPeer.cs
- AuthenticationModuleElementCollection.cs
- XmlSiteMapProvider.cs
- Mappings.cs
- EntityContainerEmitter.cs
- SlotInfo.cs
- PostBackOptions.cs
- DictionaryTraceRecord.cs
- CodeTypeParameterCollection.cs
- WeakReferenceKey.cs
- Animatable.cs
- OptionUsage.cs
- InkCollectionBehavior.cs
- Vector.cs
- ClientSettingsProvider.cs
- TypeExtensionConverter.cs
- XmlNotation.cs
- Item.cs
- SqlCommandBuilder.cs
- HScrollProperties.cs
- ManagedFilter.cs
- SerializationFieldInfo.cs
- QilInvokeLateBound.cs
- ZipFileInfo.cs
- InlinedLocationReference.cs
- localization.cs
- JpegBitmapDecoder.cs
- UpDownBase.cs
- CustomErrorCollection.cs
- AttachedPropertyBrowsableForTypeAttribute.cs
- GroupBoxAutomationPeer.cs
- ContainerUtilities.cs
- ProcessManager.cs
- TabControl.cs
- OutputWindow.cs
- ImmutableCollection.cs
- XslTransform.cs
- ObjectSet.cs
- ModelUtilities.cs
- InfoCardRSAPKCS1SignatureDeformatter.cs
- MailMessage.cs
- CroppedBitmap.cs
- Types.cs
- RectangleGeometry.cs
- CompilerWrapper.cs
- EtwTrace.cs
- DataTemplateKey.cs
- DtdParser.cs
- SQLInt32Storage.cs
- XmlSchemaAnnotation.cs
- RenderTargetBitmap.cs
- ToolboxComponentsCreatedEventArgs.cs
- DataGrid.cs
- ContextMenuStripGroup.cs
- HttpCacheVary.cs
- BindToObject.cs
- UnsafeNativeMethods.cs
- CategoryAttribute.cs
- QueueSurrogate.cs
- HtmlTableCellCollection.cs
- InvalidOperationException.cs
- PerfCounters.cs
- InstallerTypeAttribute.cs
- RequestNavigateEventArgs.cs
- XmlDocumentType.cs
- ObjectStateManager.cs
- XmlSchemaObject.cs
- PermissionSetEnumerator.cs
- SinglePhaseEnlistment.cs
- ProjectionPlan.cs
- TreeViewDesigner.cs
- PrinterResolution.cs
- SendKeys.cs
- SmiSettersStream.cs
- PlatformNotSupportedException.cs
- ItemDragEvent.cs
- ResourceReferenceKeyNotFoundException.cs
- TextElementEnumerator.cs
- Canvas.cs
- BinaryConverter.cs
- DataGridViewRowPostPaintEventArgs.cs
- CommonRemoteMemoryBlock.cs
- MultipartContentParser.cs
- MessageProperties.cs
- CubicEase.cs
- SerializationInfoEnumerator.cs
- WebProxyScriptElement.cs
- EntityDataSourceView.cs
- AssemblyCollection.cs