Code:
/ Dotnetfx_Vista_SP2 / Dotnetfx_Vista_SP2 / 8.0.50727.4016 / DEVDIV / depot / DevDiv / releases / whidbey / NetFxQFE / 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
- ReflectionHelper.cs
- TdsValueSetter.cs
- TrackingServices.cs
- ComponentEditorPage.cs
- AuthStoreRoleProvider.cs
- WindowPatternIdentifiers.cs
- CodePageUtils.cs
- ToolStripDropDownClosingEventArgs.cs
- DocumentXmlWriter.cs
- RadioButtonFlatAdapter.cs
- ConnectionStringsExpressionBuilder.cs
- FontStretchConverter.cs
- ResourceWriter.cs
- odbcmetadatafactory.cs
- EncoderParameters.cs
- _Win32.cs
- MiniAssembly.cs
- FileUpload.cs
- CharacterMetricsDictionary.cs
- MemoryRecordBuffer.cs
- TraceUtility.cs
- BasicCellRelation.cs
- Renderer.cs
- QilDataSource.cs
- StoreContentChangedEventArgs.cs
- TriggerActionCollection.cs
- ManagedWndProcTracker.cs
- PerformanceCounters.cs
- ManagedIStream.cs
- ProfileService.cs
- SqlFacetAttribute.cs
- ValidationResult.cs
- ReceiveActivityValidator.cs
- SequentialWorkflowHeaderFooter.cs
- ControlCollection.cs
- SingleKeyFrameCollection.cs
- InputReportEventArgs.cs
- ReadOnlyAttribute.cs
- ListViewTableRow.cs
- QilTernary.cs
- PageBuildProvider.cs
- GridViewRow.cs
- LayoutInformation.cs
- TableRow.cs
- DataBindingHandlerAttribute.cs
- Header.cs
- MaskDesignerDialog.cs
- DiscardableAttribute.cs
- Int32EqualityComparer.cs
- SafeCoTaskMem.cs
- GridViewCellAutomationPeer.cs
- FlowDocumentPage.cs
- LockedActivityGlyph.cs
- SemaphoreFullException.cs
- Activity.cs
- TakeOrSkipQueryOperator.cs
- QuotedPrintableStream.cs
- OleDbWrapper.cs
- TrackPoint.cs
- FontSource.cs
- ConstantCheck.cs
- StringSource.cs
- BaseHashHelper.cs
- ConfigPathUtility.cs
- ChannelBinding.cs
- CodeLabeledStatement.cs
- MulticastIPAddressInformationCollection.cs
- WizardForm.cs
- NavigationProperty.cs
- X509Chain.cs
- DiscoveryClientBindingElement.cs
- MulticastNotSupportedException.cs
- XmlAggregates.cs
- RubberbandSelector.cs
- DbQueryCommandTree.cs
- OrderedEnumerableRowCollection.cs
- OdbcConnection.cs
- MetaTable.cs
- Nullable.cs
- SchemaImporterExtensionsSection.cs
- EventDescriptor.cs
- DoubleSumAggregationOperator.cs
- WindowsMenu.cs
- TransformCollection.cs
- PartialArray.cs
- CompilationPass2Task.cs
- ScriptResourceHandler.cs
- SqlEnums.cs
- MemoryStream.cs
- TrustManagerPromptUI.cs
- DataBindingHandlerAttribute.cs
- CryptoApi.cs
- PenThreadWorker.cs
- BuilderInfo.cs
- DataGridViewCellMouseEventArgs.cs
- OleDbDataAdapter.cs
- XPathExpr.cs
- Label.cs
- DataListItemCollection.cs
- ListBoxItem.cs