//-----------------------------------------------------------------------
//
// Copyright (c) Microsoft Corporation.
//
//-----------------------------------------------------------------------
namespace Microsoft.Isam.Esent.Interop.Windows8
{
using System;
using System.Diagnostics;
using System.Diagnostics.CodeAnalysis;
using System.Globalization;
using System.Runtime.InteropServices;
///
/// The native version of the JET_ERRINFOBASIC structure.
///
[StructLayout(LayoutKind.Sequential, CharSet = CharSet.Unicode)]
[SuppressMessage("Microsoft.StyleCop.CSharp.NamingRules",
"SA1305:FieldNamesMustNotUseHungarianNotation",
Justification = "This should match the unmanaged API, which isn't capitalized.")]
[SuppressMessage(
"Microsoft.StyleCop.CSharp.NamingRules",
"SA1307:AccessibleFieldsMustBeginWithUpperCaseLetter",
Justification = "This should match the unmanaged API, which isn't capitalized.")]
internal struct NATIVE_ERRINFOBASIC
{
///
/// The number of elements in the error hierarchy.
///
public const int HierarchySize = 8;
///
/// The length of the source file where the error occurred.
///
public const int SourceFileLength = 64;
///
/// Size of the structure.
///
public uint cbStruct;
///
/// The error value for the requested info level.
///
public JET_err errValue;
///
/// The most specific category of the error.
///
public JET_ERRCAT errcatMostSpecific;
///
/// Hierarchy of error categories. Position 0 is the highest level in the hierarchy, and the rest are JET_errcatUnknown.
///
[MarshalAs(UnmanagedType.ByValArray, SizeConst = HierarchySize)]
public byte[] rgCategoricalHierarchy;
///
/// The source file line for the requested info level.
///
public uint lSourceLine;
///
/// The source file name for the requested info level.
///
[MarshalAs(UnmanagedType.ByValTStr, SizeConst = SourceFileLength)]
public string rgszSourceFile;
}
///
/// Contains the information about an error.
///
[SuppressMessage(
"Microsoft.StyleCop.CSharp.NamingRules",
"SA1300:ElementMustBeginWithUpperCaseLetter",
Justification = "This should match the unmanaged API, which isn't capitalized.")]
[Serializable]
public sealed class JET_ERRINFOBASIC : IContentEquatable, IDeepCloneable
{
///
/// The error value for the requested info level.
///
private JET_err errorValue;
///
/// The most specific category of the error.
///
private JET_ERRCAT errorcatMostSpecific;
///
/// Hierarchy of error categories. Position 0 is the highest level in the hierarchy, and the rest are JET_errcatUnknown.
///
private JET_ERRCAT[] arrayCategoricalHierarchy;
///
/// The source file line for the requested info level.
///
private int sourceLine;
///
/// The source file name for the requested info level.
///
private string sourceFile;
///
/// Initializes a new instance of the JET_ERRINFOBASIC class.
///
public JET_ERRINFOBASIC()
{
this.rgCategoricalHierarchy = new JET_ERRCAT[NATIVE_ERRINFOBASIC.HierarchySize];
}
///
/// Gets or sets the error value for the requested info level.
///
public JET_err errValue
{
[DebuggerStepThrough]
get { return this.errorValue; }
set { this.errorValue = value; }
}
///
/// Gets or sets the category of the error.
///
public JET_ERRCAT errcat
{
[DebuggerStepThrough]
get { return this.errorcatMostSpecific; }
set { this.errorcatMostSpecific = value; }
}
///
/// Gets or sets the hierarchy of errors. Position 0 is the highest level in the hierarchy, and the rest are JET_errcatUnknown.
///
public JET_ERRCAT[] rgCategoricalHierarchy
{
[DebuggerStepThrough]
get { return this.arrayCategoricalHierarchy; }
set { this.arrayCategoricalHierarchy = value; }
}
///
/// Gets or sets the source file line for the requested info level.
///
public int lSourceLine
{
[DebuggerStepThrough]
get { return this.sourceLine; }
set { this.sourceLine = value; }
}
///
/// Gets or sets the source file name for the requested info level.
///
public string rgszSourceFile
{
[DebuggerStepThrough]
get { return this.sourceFile; }
set { this.sourceFile = value; }
}
///
/// Returns a deep copy of the object.
///
/// A deep copy of the object.
public JET_ERRINFOBASIC DeepClone()
{
JET_ERRINFOBASIC result = (JET_ERRINFOBASIC)this.MemberwiseClone();
return result;
}
///
/// Generate a string representation of the instance.
///
/// The structure as a string.
public override string ToString()
{
return string.Format(CultureInfo.InvariantCulture, "JET_ERRINFOBASIC({0}:{1}:{2}:{3})", this.errValue, this.errcat, this.rgszSourceFile, this.lSourceLine);
}
///
/// Returns a value indicating whether this instance is equal
/// to another instance.
///
/// An instance to compare with this instance.
/// True if the two instances are equal.
public bool ContentEquals(JET_ERRINFOBASIC other)
{
if (null == other)
{
return false;
}
return this.errValue == other.errValue
&& this.errcat == other.errcat
&& this.lSourceLine == other.lSourceLine
&& this.rgszSourceFile == other.rgszSourceFile
&& Util.ArrayStructEquals(this.rgCategoricalHierarchy, other.rgCategoricalHierarchy, this.rgCategoricalHierarchy == null ? 0 : this.rgCategoricalHierarchy.Length);
}
///
/// Gets the native (interop) version of this object.
///
/// The native (interop) version of this object.
internal NATIVE_ERRINFOBASIC GetNativeErrInfo()
{
var native = new NATIVE_ERRINFOBASIC();
native.cbStruct = checked((uint)Marshal.SizeOf(typeof(NATIVE_ERRINFOBASIC)));
native.errValue = this.errValue;
native.errcatMostSpecific = this.errcat;
native.rgCategoricalHierarchy = new byte[NATIVE_ERRINFOBASIC.HierarchySize];
if (this.rgCategoricalHierarchy != null)
{
for (int i = 0; i < this.rgCategoricalHierarchy.Length; ++i)
{
native.rgCategoricalHierarchy[i] = (byte)this.rgCategoricalHierarchy[i];
}
}
native.lSourceLine = (uint)this.lSourceLine;
native.rgszSourceFile = this.rgszSourceFile;
return native;
}
///
/// Sets the fields of the object from a native JET_ERRINFOBASIC struct.
///
///
/// The native errinfobasic to set the values from.
///
internal void SetFromNative(
ref NATIVE_ERRINFOBASIC value)
{
unchecked
{
this.errValue = value.errValue;
this.errcat = value.errcatMostSpecific;
if (value.rgCategoricalHierarchy != null)
{
for (int i = 0; i < value.rgCategoricalHierarchy.Length; ++i)
{
this.rgCategoricalHierarchy[i] = (JET_ERRCAT)value.rgCategoricalHierarchy[i];
}
}
this.lSourceLine = (int)value.lSourceLine;
this.rgszSourceFile = value.rgszSourceFile;
}
}
}
}