Code:
/ Net / Net / 3.5.50727.3053 / DEVDIV / depot / DevDiv / releases / whidbey / netfxsp / 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
- ImpersonationContext.cs
- WebPartVerbsEventArgs.cs
- Operators.cs
- HtmlEmptyTagControlBuilder.cs
- ScriptingJsonSerializationSection.cs
- BamlLocalizabilityResolver.cs
- GenerateScriptTypeAttribute.cs
- ItemsControl.cs
- PropertyGridView.cs
- HttpCapabilitiesEvaluator.cs
- BitmapFrameEncode.cs
- StatusBarDrawItemEvent.cs
- MailAddressCollection.cs
- WindowsListViewGroupSubsetLink.cs
- String.cs
- ItemCheckedEvent.cs
- DataReaderContainer.cs
- SymbolTable.cs
- IIS7WorkerRequest.cs
- LambdaCompiler.Statements.cs
- TreeViewItemAutomationPeer.cs
- ReflectionPermission.cs
- SchemaSetCompiler.cs
- SafeCoTaskMem.cs
- SqlBooleanizer.cs
- Psha1DerivedKeyGenerator.cs
- InvalidAsynchronousStateException.cs
- UIAgentMonitorHandle.cs
- RubberbandSelector.cs
- SelectionRangeConverter.cs
- PageSetupDialog.cs
- ConfigurationManagerInternalFactory.cs
- ConfigXmlSignificantWhitespace.cs
- RemoteWebConfigurationHostStream.cs
- ToolConsole.cs
- InputLangChangeEvent.cs
- Duration.cs
- EngineSiteSapi.cs
- ISFTagAndGuidCache.cs
- PointCollectionValueSerializer.cs
- Filter.cs
- DataError.cs
- LabelLiteral.cs
- Matrix3DValueSerializer.cs
- CompareInfo.cs
- MainMenu.cs
- EmissiveMaterial.cs
- TemplateBindingExpressionConverter.cs
- SQLMoneyStorage.cs
- DataPagerField.cs
- CodeArgumentReferenceExpression.cs
- FixedSchema.cs
- _NegoStream.cs
- MsmqPoisonMessageException.cs
- ProcessInputEventArgs.cs
- PartialToken.cs
- DataGridViewElement.cs
- ModelPropertyImpl.cs
- GradientBrush.cs
- SymmetricAlgorithm.cs
- WinFormsSecurity.cs
- ScalarOps.cs
- X509CertificateCollection.cs
- ListViewSelectEventArgs.cs
- CounterSet.cs
- MailDefinitionBodyFileNameEditor.cs
- PixelFormat.cs
- InvokePatternIdentifiers.cs
- EntityDataSourceChangingEventArgs.cs
- CommandID.cs
- OleDbPropertySetGuid.cs
- BigIntegerStorage.cs
- IdentitySection.cs
- AdapterUtil.cs
- EnvelopedPkcs7.cs
- DnsPermission.cs
- InternalBufferOverflowException.cs
- ReturnEventArgs.cs
- ReferencedAssembly.cs
- FuncCompletionCallbackWrapper.cs
- AssemblyHash.cs
- XmlSiteMapProvider.cs
- TreeView.cs
- CollectionView.cs
- EntityDataSourceWrapperCollection.cs
- ReadonlyMessageFilter.cs
- ImageMapEventArgs.cs
- Fault.cs
- SaveWorkflowAsyncResult.cs
- SchemaNotation.cs
- SrgsText.cs
- NameTable.cs
- DataSourceCache.cs
- RuleConditionDialog.cs
- FormatConvertedBitmap.cs
- ProfessionalColorTable.cs
- NetworkAddressChange.cs
- FramingChannels.cs
- FixUp.cs
- DayRenderEvent.cs