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
- DesignerHelpers.cs
- DataObjectMethodAttribute.cs
- DataServiceEntityAttribute.cs
- FormatSettings.cs
- ObjectSerializerFactory.cs
- WsdlBuildProvider.cs
- EndOfStreamException.cs
- Condition.cs
- CharacterBuffer.cs
- UncommonField.cs
- Transform3D.cs
- RepeatBehavior.cs
- DataGridDesigner.cs
- TemplateGroupCollection.cs
- CodeMemberMethod.cs
- Point4DConverter.cs
- StateItem.cs
- CapabilitiesAssignment.cs
- MD5.cs
- WebSysDescriptionAttribute.cs
- DataGrid.cs
- ZoneIdentityPermission.cs
- WebControlAdapter.cs
- UncommonField.cs
- HashSetEqualityComparer.cs
- XmlAnyElementAttributes.cs
- Point.cs
- SmtpTransport.cs
- WebPartEditVerb.cs
- CookielessHelper.cs
- CryptoSession.cs
- UnSafeCharBuffer.cs
- TypeConverterHelper.cs
- MembershipValidatePasswordEventArgs.cs
- ObjectMaterializedEventArgs.cs
- RuleCache.cs
- SqlCommandBuilder.cs
- Rect3DValueSerializer.cs
- ConfigsHelper.cs
- Int32AnimationBase.cs
- ValidatorCompatibilityHelper.cs
- ReachPageContentCollectionSerializer.cs
- SqlAggregateChecker.cs
- TripleDESCryptoServiceProvider.cs
- WorkflowDesigner.cs
- XmlIncludeAttribute.cs
- CompilerParameters.cs
- DBDataPermissionAttribute.cs
- ComponentConverter.cs
- DiscoveryClientOutputChannel.cs
- DbFunctionCommandTree.cs
- WebPartConnectionsCancelVerb.cs
- WebPartVerbCollection.cs
- RegexMatchCollection.cs
- EntryPointNotFoundException.cs
- StyleSheetDesigner.cs
- XpsFontSerializationService.cs
- HelpKeywordAttribute.cs
- GreaterThanOrEqual.cs
- SoapSchemaImporter.cs
- StackBuilderSink.cs
- LineUtil.cs
- XPathAncestorIterator.cs
- LocatorBase.cs
- WebPartTransformerAttribute.cs
- ObjectAssociationEndMapping.cs
- XPathDocumentBuilder.cs
- ServiceHttpModule.cs
- ArrayList.cs
- ImplicitInputBrush.cs
- PropertyInformation.cs
- SettingsProperty.cs
- WebPartTransformerAttribute.cs
- WebPartDisplayMode.cs
- WindowsUserNameSecurityTokenAuthenticator.cs
- ComponentManagerBroker.cs
- uribuilder.cs
- EncodingDataItem.cs
- ToolTipAutomationPeer.cs
- DataKeyCollection.cs
- EasingFunctionBase.cs
- PerfProviderCollection.cs
- AuthenticateEventArgs.cs
- ClientTargetSection.cs
- EventRoute.cs
- messageonlyhwndwrapper.cs
- SoapObjectInfo.cs
- webclient.cs
- ClientTargetCollection.cs
- XmlSchemaComplexType.cs
- InternalConfigHost.cs
- InvokePattern.cs
- VirtualPathData.cs
- XmlSchemaValidationException.cs
- OracleConnection.cs
- CriticalHandle.cs
- BaseServiceProvider.cs
- ProcessHostFactoryHelper.cs
- DoubleAnimation.cs
- Overlapped.cs