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 / OracleMonthSpan.cs / 1 / OracleMonthSpan.cs
//------------------------------------------------------------------------------
//
// Copyright (c) Microsoft Corporation. All rights reserved.
//
// [....]
//-----------------------------------------------------------------------------
namespace System.Data.OracleClient
{
using System;
using System.Data.SqlTypes;
using System.Data.Common;
using System.Diagnostics;
using System.Globalization;
using System.Runtime.InteropServices;
using System.Text;
//---------------------------------------------------------------------
// OracleMonthSpan
//
// This class implements support the Oracle 9i 'INTERVAL YEAR TO MONTH'
// internal data type.
//
[StructLayout(LayoutKind.Sequential, Pack=1)]
public struct OracleMonthSpan : IComparable, INullable {
private int _value;
private const int MaxMonth = 176556;
private const int MinMonth = -176556;
public static readonly OracleMonthSpan MaxValue = new OracleMonthSpan(MaxMonth); // 4172 BC - 9999 AD * 12 months/year
public static readonly OracleMonthSpan MinValue = new OracleMonthSpan(MinMonth); // 4172 BC - 9999 AD * 12 months/year
public static readonly OracleMonthSpan Null = new OracleMonthSpan(true);
private const int NullValue = Int32.MaxValue;
// Construct from nothing -- the value will be null
internal OracleMonthSpan(bool isNull) {
_value = NullValue;
}
// Construct from an integer number of months
public OracleMonthSpan (int months) {
_value = months;
AssertValid(_value);
}
public OracleMonthSpan (Int32 years, Int32 months) {
try {
checked { _value = (years * 12) + months; } // Will assert below if invalid.
}
catch (System.OverflowException) {
throw ADP.MonthOutOfRange();
}
AssertValid(_value);
}
// Copy constructor
public OracleMonthSpan (OracleMonthSpan from) {
_value = from._value;
}
// (internal) construct from a row/parameter binding
internal OracleMonthSpan (NativeBuffer buffer, int valueOffset) {
_value = MarshalToInt32(buffer, valueOffset);
}
public bool IsNull {
get {
return (NullValue == _value);
}
}
public int Value {
get {
if (IsNull) {
throw ADP.DataIsNull();
}
return _value;
}
}
static private void AssertValid(int monthSpan) {
if (monthSpan < MinMonth || monthSpan > MaxMonth) {
throw ADP.MonthOutOfRange();
}
}
public int CompareTo(object obj) {
if (obj.GetType() == typeof(OracleMonthSpan)) {
OracleMonthSpan odt = (OracleMonthSpan)obj;
// If both values are Null, consider them equal.
// Otherwise, Null is less than anything.
if (IsNull) {
return odt.IsNull ? 0 : -1;
}
if (odt.IsNull) {
return 1;
}
// Neither value is null, do the comparison.
int result = _value.CompareTo(odt._value);
return result;
}
throw ADP.WrongType(obj.GetType(), typeof(OracleMonthSpan));
}
public override bool Equals(object value) {
if (value is OracleMonthSpan) {
return (this == (OracleMonthSpan)value).Value;
}
else {
return false;
}
}
public override int GetHashCode() {
return IsNull ? 0 : _value.GetHashCode();
}
static internal int MarshalToInt32( NativeBuffer buffer, int valueOffset) {
byte[] ociValue = buffer.ReadBytes(valueOffset, 5);
int years = (int)((long)( (int)ociValue[0] << 24
| (int)ociValue[1] << 16
| (int)ociValue[2] << 8
| (int)ociValue[3]
) - 0x80000000);
int months = (int)ociValue[4] - 60;
int result = (years * 12) + months;
AssertValid(result);
return result;
}
static internal int MarshalToNative(object value, NativeBuffer buffer, int offset) {
int from;
if ( value is OracleMonthSpan )
from = ((OracleMonthSpan)value)._value;
else
from = (int)value;
byte[] ociValue = new byte[5];
int years = (int)((long)(from / 12) + 0x80000000);
int months = from % 12;
// DEVNOTE: undoubtedly, this is Intel byte order specific, but how
// do I verify what Oracle needs on a non Intel machine?
ociValue[0] = (byte)((years >> 24));
ociValue[1] = (byte)((years >> 16) & 0xff);
ociValue[2] = (byte)((years >> 8) & 0xff);
ociValue[3] = (byte)(years & 0xff);
ociValue[4] = (byte)(months + 60);
buffer.WriteBytes(offset, ociValue, 0, 5);
return 5;
}
public static OracleMonthSpan Parse(string s) {
int ms = Int32.Parse(s, CultureInfo.InvariantCulture);
return new OracleMonthSpan(ms);
}
public override string ToString() {
if (IsNull) {
return ADP.NullString;
}
string retval = Value.ToString(CultureInfo.CurrentCulture);
return retval;
}
public static OracleBoolean Equals(OracleMonthSpan x, OracleMonthSpan y) {
// Alternative method for operator ==
return (x == y);
}
public static OracleBoolean GreaterThan(OracleMonthSpan x, OracleMonthSpan y) {
// Alternative method for operator >
return (x > y);
}
public static OracleBoolean GreaterThanOrEqual(OracleMonthSpan x, OracleMonthSpan y) {
// Alternative method for operator >=
return (x >= y);
}
public static OracleBoolean LessThan(OracleMonthSpan x, OracleMonthSpan y) {
// Alternative method for operator <
return (x < y);
}
public static OracleBoolean LessThanOrEqual(OracleMonthSpan x, OracleMonthSpan y) {
// Alternative method for operator <=
return (x <= y);
}
public static OracleBoolean NotEquals(OracleMonthSpan x, OracleMonthSpan y) {
// Alternative method for operator !=
return (x != y);
}
public static explicit operator int(OracleMonthSpan x) {
if (x.IsNull) {
throw ADP.DataIsNull();
}
return x.Value;
}
public static explicit operator OracleMonthSpan(string x) {
return OracleMonthSpan.Parse(x);
}
public static OracleBoolean operator== (OracleMonthSpan x, OracleMonthSpan y) {
return (x.IsNull || y.IsNull) ? OracleBoolean.Null : new OracleBoolean(x.CompareTo(y) == 0);
}
public static OracleBoolean operator> (OracleMonthSpan x, OracleMonthSpan y) {
return (x.IsNull || y.IsNull) ? OracleBoolean.Null : new OracleBoolean(x.CompareTo(y) > 0);
}
public static OracleBoolean operator>= (OracleMonthSpan x, OracleMonthSpan y) {
return (x.IsNull || y.IsNull) ? OracleBoolean.Null : new OracleBoolean(x.CompareTo(y) >= 0);
}
public static OracleBoolean operator< (OracleMonthSpan x, OracleMonthSpan y) {
return (x.IsNull || y.IsNull) ? OracleBoolean.Null : new OracleBoolean(x.CompareTo(y) < 0);
}
public static OracleBoolean operator<= (OracleMonthSpan x, OracleMonthSpan y) {
return (x.IsNull || y.IsNull) ? OracleBoolean.Null : new OracleBoolean(x.CompareTo(y) <= 0);
}
public static OracleBoolean operator!= (OracleMonthSpan x, OracleMonthSpan y) {
return (x.IsNull || y.IsNull) ? OracleBoolean.Null : new OracleBoolean(x.CompareTo(y) != 0);
}
}
}
// 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.SqlTypes;
using System.Data.Common;
using System.Diagnostics;
using System.Globalization;
using System.Runtime.InteropServices;
using System.Text;
//---------------------------------------------------------------------
// OracleMonthSpan
//
// This class implements support the Oracle 9i 'INTERVAL YEAR TO MONTH'
// internal data type.
//
[StructLayout(LayoutKind.Sequential, Pack=1)]
public struct OracleMonthSpan : IComparable, INullable {
private int _value;
private const int MaxMonth = 176556;
private const int MinMonth = -176556;
public static readonly OracleMonthSpan MaxValue = new OracleMonthSpan(MaxMonth); // 4172 BC - 9999 AD * 12 months/year
public static readonly OracleMonthSpan MinValue = new OracleMonthSpan(MinMonth); // 4172 BC - 9999 AD * 12 months/year
public static readonly OracleMonthSpan Null = new OracleMonthSpan(true);
private const int NullValue = Int32.MaxValue;
// Construct from nothing -- the value will be null
internal OracleMonthSpan(bool isNull) {
_value = NullValue;
}
// Construct from an integer number of months
public OracleMonthSpan (int months) {
_value = months;
AssertValid(_value);
}
public OracleMonthSpan (Int32 years, Int32 months) {
try {
checked { _value = (years * 12) + months; } // Will assert below if invalid.
}
catch (System.OverflowException) {
throw ADP.MonthOutOfRange();
}
AssertValid(_value);
}
// Copy constructor
public OracleMonthSpan (OracleMonthSpan from) {
_value = from._value;
}
// (internal) construct from a row/parameter binding
internal OracleMonthSpan (NativeBuffer buffer, int valueOffset) {
_value = MarshalToInt32(buffer, valueOffset);
}
public bool IsNull {
get {
return (NullValue == _value);
}
}
public int Value {
get {
if (IsNull) {
throw ADP.DataIsNull();
}
return _value;
}
}
static private void AssertValid(int monthSpan) {
if (monthSpan < MinMonth || monthSpan > MaxMonth) {
throw ADP.MonthOutOfRange();
}
}
public int CompareTo(object obj) {
if (obj.GetType() == typeof(OracleMonthSpan)) {
OracleMonthSpan odt = (OracleMonthSpan)obj;
// If both values are Null, consider them equal.
// Otherwise, Null is less than anything.
if (IsNull) {
return odt.IsNull ? 0 : -1;
}
if (odt.IsNull) {
return 1;
}
// Neither value is null, do the comparison.
int result = _value.CompareTo(odt._value);
return result;
}
throw ADP.WrongType(obj.GetType(), typeof(OracleMonthSpan));
}
public override bool Equals(object value) {
if (value is OracleMonthSpan) {
return (this == (OracleMonthSpan)value).Value;
}
else {
return false;
}
}
public override int GetHashCode() {
return IsNull ? 0 : _value.GetHashCode();
}
static internal int MarshalToInt32( NativeBuffer buffer, int valueOffset) {
byte[] ociValue = buffer.ReadBytes(valueOffset, 5);
int years = (int)((long)( (int)ociValue[0] << 24
| (int)ociValue[1] << 16
| (int)ociValue[2] << 8
| (int)ociValue[3]
) - 0x80000000);
int months = (int)ociValue[4] - 60;
int result = (years * 12) + months;
AssertValid(result);
return result;
}
static internal int MarshalToNative(object value, NativeBuffer buffer, int offset) {
int from;
if ( value is OracleMonthSpan )
from = ((OracleMonthSpan)value)._value;
else
from = (int)value;
byte[] ociValue = new byte[5];
int years = (int)((long)(from / 12) + 0x80000000);
int months = from % 12;
// DEVNOTE: undoubtedly, this is Intel byte order specific, but how
// do I verify what Oracle needs on a non Intel machine?
ociValue[0] = (byte)((years >> 24));
ociValue[1] = (byte)((years >> 16) & 0xff);
ociValue[2] = (byte)((years >> 8) & 0xff);
ociValue[3] = (byte)(years & 0xff);
ociValue[4] = (byte)(months + 60);
buffer.WriteBytes(offset, ociValue, 0, 5);
return 5;
}
public static OracleMonthSpan Parse(string s) {
int ms = Int32.Parse(s, CultureInfo.InvariantCulture);
return new OracleMonthSpan(ms);
}
public override string ToString() {
if (IsNull) {
return ADP.NullString;
}
string retval = Value.ToString(CultureInfo.CurrentCulture);
return retval;
}
public static OracleBoolean Equals(OracleMonthSpan x, OracleMonthSpan y) {
// Alternative method for operator ==
return (x == y);
}
public static OracleBoolean GreaterThan(OracleMonthSpan x, OracleMonthSpan y) {
// Alternative method for operator >
return (x > y);
}
public static OracleBoolean GreaterThanOrEqual(OracleMonthSpan x, OracleMonthSpan y) {
// Alternative method for operator >=
return (x >= y);
}
public static OracleBoolean LessThan(OracleMonthSpan x, OracleMonthSpan y) {
// Alternative method for operator <
return (x < y);
}
public static OracleBoolean LessThanOrEqual(OracleMonthSpan x, OracleMonthSpan y) {
// Alternative method for operator <=
return (x <= y);
}
public static OracleBoolean NotEquals(OracleMonthSpan x, OracleMonthSpan y) {
// Alternative method for operator !=
return (x != y);
}
public static explicit operator int(OracleMonthSpan x) {
if (x.IsNull) {
throw ADP.DataIsNull();
}
return x.Value;
}
public static explicit operator OracleMonthSpan(string x) {
return OracleMonthSpan.Parse(x);
}
public static OracleBoolean operator== (OracleMonthSpan x, OracleMonthSpan y) {
return (x.IsNull || y.IsNull) ? OracleBoolean.Null : new OracleBoolean(x.CompareTo(y) == 0);
}
public static OracleBoolean operator> (OracleMonthSpan x, OracleMonthSpan y) {
return (x.IsNull || y.IsNull) ? OracleBoolean.Null : new OracleBoolean(x.CompareTo(y) > 0);
}
public static OracleBoolean operator>= (OracleMonthSpan x, OracleMonthSpan y) {
return (x.IsNull || y.IsNull) ? OracleBoolean.Null : new OracleBoolean(x.CompareTo(y) >= 0);
}
public static OracleBoolean operator< (OracleMonthSpan x, OracleMonthSpan y) {
return (x.IsNull || y.IsNull) ? OracleBoolean.Null : new OracleBoolean(x.CompareTo(y) < 0);
}
public static OracleBoolean operator<= (OracleMonthSpan x, OracleMonthSpan y) {
return (x.IsNull || y.IsNull) ? OracleBoolean.Null : new OracleBoolean(x.CompareTo(y) <= 0);
}
public static OracleBoolean operator!= (OracleMonthSpan x, OracleMonthSpan y) {
return (x.IsNull || y.IsNull) ? OracleBoolean.Null : new OracleBoolean(x.CompareTo(y) != 0);
}
}
}
// 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
- XmlEntity.cs
- PageSetupDialog.cs
- WebPartEditorCancelVerb.cs
- WebControl.cs
- MenuItemAutomationPeer.cs
- PathSegmentCollection.cs
- PagerSettings.cs
- GenerateHelper.cs
- GenericWebPart.cs
- ClientTargetCollection.cs
- Pen.cs
- ListenerElementsCollection.cs
- MoveSizeWinEventHandler.cs
- PixelFormats.cs
- TypeAccessException.cs
- UInt32Converter.cs
- TextBoxRenderer.cs
- _SecureChannel.cs
- PeerEndPoint.cs
- precedingquery.cs
- StringExpressionSet.cs
- HttpRuntimeSection.cs
- WorkflowOwnershipException.cs
- RuleSetReference.cs
- TraceUtils.cs
- WebWorkflowRole.cs
- ConstructorBuilder.cs
- ApplicationFileCodeDomTreeGenerator.cs
- BitmapSourceSafeMILHandle.cs
- ProtocolsConfigurationEntry.cs
- CacheSection.cs
- CodeTypeReferenceCollection.cs
- DispatcherTimer.cs
- Style.cs
- NavigateEvent.cs
- SafeEventLogWriteHandle.cs
- UnsafeNetInfoNativeMethods.cs
- DataServices.cs
- ToolBar.cs
- thaishape.cs
- SQLDateTimeStorage.cs
- ActiveXHost.cs
- X509SecurityTokenAuthenticator.cs
- ConfigXmlWhitespace.cs
- IndentedWriter.cs
- FormsAuthentication.cs
- DelegatingConfigHost.cs
- AnnotationHighlightLayer.cs
- SettingsPropertyNotFoundException.cs
- Enum.cs
- TextAction.cs
- ModelUIElement3D.cs
- Table.cs
- ObjectView.cs
- TextBox.cs
- ModelVisual3D.cs
- MarshalByValueComponent.cs
- ProxyManager.cs
- MailMessage.cs
- StringFunctions.cs
- ProcessManager.cs
- SHA512.cs
- WebPartVerb.cs
- RNGCryptoServiceProvider.cs
- GestureRecognitionResult.cs
- DES.cs
- ContentDefinition.cs
- SingleStorage.cs
- StringCollectionMarkupSerializer.cs
- FlagPanel.cs
- FormattedTextSymbols.cs
- PageParserFilter.cs
- Documentation.cs
- RoutedEventHandlerInfo.cs
- PersistenceIOParticipant.cs
- DBCSCodePageEncoding.cs
- TraceEventCache.cs
- XmlElementList.cs
- ReachVisualSerializer.cs
- ResourceReferenceExpressionConverter.cs
- ObjectStateFormatter.cs
- File.cs
- MemoryPressure.cs
- ToolStripItemDesigner.cs
- ParameterCollection.cs
- SQLUtility.cs
- SwitchLevelAttribute.cs
- FixUpCollection.cs
- ClientSideProviderDescription.cs
- SizeConverter.cs
- MergeFailedEvent.cs
- ThicknessAnimationUsingKeyFrames.cs
- Context.cs
- XmlSchemaChoice.cs
- ConditionBrowserDialog.cs
- LongMinMaxAggregationOperator.cs
- IndependentAnimationStorage.cs
- TypeSemantics.cs
- GlyphsSerializer.cs
- ObjectViewQueryResultData.cs