//----------------------------------------------------------------------- // // Copyright (c) Microsoft Corporation. // // // Class stubs to allow compiling on CoreClr. // //----------------------------------------------------------------------- namespace Microsoft.Isam.Esent.Interop { using System; using System.Diagnostics; using System.Diagnostics.CodeAnalysis; /// /// Some useful functionality that was omitted from Core CLR classes. /// [SuppressMessage( "Microsoft.StyleCop.CSharp.MaintainabilityRules", "SA1402:FileMayOnlyContainASingleClass", Justification = "These stub classes are compiled only on some platforms that do not contain the entire framework, e.g. new Windows user interface.")] public static class ExtensionsToCoreClr { /// Converts the value of this instance to the equivalent OLE Automation date. /// A DateTime structure. /// A double-precision floating-point number that contains an OLE Automation date equivalent to the value of this instance. /// The value of this instance cannot be represented as an OLE Automation Date. /// 2 public static double ToOADate(this DateTime dateTime) { return LibraryHelpers.TicksToOADate(dateTime.Ticks); } } /// /// JetApi code that is specific to ESENT. /// [SuppressMessage( "Microsoft.StyleCop.CSharp.MaintainabilityRules", "SA1402:FileMayOnlyContainASingleClass", Justification = "These stub classes are compiled only on some platforms that do not contain the entire framework, e.g. new Windows user interface.")] public class SerializationInfo { /// /// Prints out the object's contents. /// /// A string represenetation or the object. public override string ToString() { return base.ToString(); } /// /// Deserializes an integer. /// /// The name of the field to retrieve. /// An integer. public int GetInt32(string propName) { return 0; } } /// /// A fake class to allow compilation on platforms that lack this class. /// [SuppressMessage("StyleCop.CSharp.MaintainabilityRules", "SA1402:FileMayOnlyContainASingleClass", Justification = "Reviewed. Suppression is OK here because it's a collection of trivial classes.")] [SuppressMessage( "Microsoft.StyleCop.CSharp.MaintainabilityRules", "SA1402:FileMayOnlyContainASingleClass", Justification = "These stub classes are compiled only on some platforms that do not contain the entire framework, e.g. new Windows user interface.")] internal static class RuntimeHelpers { /// /// A fake function to allow compilation on platforms that lack this functionality. /// public static void PrepareConstrainedRegions() { } /// /// A fake function to allow compilation on platforms that lack this functionality. /// /// /// The method. /// public static void PrepareMethod(RuntimeMethodHandle method) { } } /// /// A fake class to allow compilation on platforms that lack this class. /// [SuppressMessage("StyleCop.CSharp.MaintainabilityRules", "SA1402:FileMayOnlyContainASingleClass", Justification = "Reviewed. Suppression is OK here because it's a collection of trivial classes.")] internal class TraceSwitch { /// /// Initializes a new instance of the class. /// /// /// The display name. /// /// /// The description. /// public TraceSwitch(string displayName, string description) { } /// /// Gets a value indicating whether TraceVerbose. /// public bool TraceVerbose { get; private set; } /// /// Gets a value indicating whether TraceWarning. /// public bool TraceWarning { get; private set; } /// /// Gets a value indicating whether TraceError. /// public bool TraceError { get; private set; } /// /// Gets a value indicating whether TraceInfo. /// public bool TraceInfo { get; private set; } /// /// Prints out the object's contents. /// /// A string represenetation or the object. public override string ToString() { return base.ToString(); } } /// /// A fake class to allow compilation on platforms that lack this class. /// [SuppressMessage("StyleCop.CSharp.MaintainabilityRules", "SA1402:FileMayOnlyContainASingleClass", Justification = "Reviewed. Suppression is OK here because it's a collection of trivial classes.")] internal class Trace { /// /// A fake function to allow compilation on platforms that lack this functionality. /// /// /// The condition. /// /// /// The message. /// [ConditionalAttribute("TRACE")] public static void WriteLineIf(bool condition, string message) { } /// /// A fake function to allow compilation on platforms that lack this functionality. /// /// /// The message. /// [ConditionalAttribute("TRACE")] public static void TraceError(string message) { } /// /// A fake function to allow compilation on platforms that lack this functionality. /// /// /// The message. /// /// /// The arguments. /// [ConditionalAttribute("TRACE")] public static void TraceWarning(string message, params object[] args) { } } } #if MANAGEDESENT_ON_WSA namespace System.ComponentModel { using System; using System.Diagnostics.CodeAnalysis; using System.Runtime.InteropServices; using System.Security; /// /// An exception from a Win32 call. /// //// The original derives from System.Runtime.InteropServices.ExternalException. internal class Win32Exception : Exception { /// /// The error code from a Win32 call. /// private readonly int nativeErrorCode; /// /// Initializes a new instance of the Win32Exception class. /// [SecuritySafeCritical] public Win32Exception() : this(Marshal.GetLastWin32Error()) { } /// /// Initializes a new instance of the Win32Exception class. /// /// A win32 error code. [SecuritySafeCritical] public Win32Exception(int error) : this(error, Win32Exception.GetErrorMessage(error)) { } /// /// Initializes a new instance of the Win32Exception class. /// /// A win32 error code. /// The string message. public Win32Exception(int error, string message) : base(message) { this.nativeErrorCode = error; } /// /// Initializes a new instance of the Win32Exception class. /// /// The string message. [SecuritySafeCritical] public Win32Exception(string message) : this(Marshal.GetLastWin32Error(), message) { } /// /// Initializes a new instance of the Win32Exception class. /// /// The string message. /// The nested exception. [SecuritySafeCritical, SuppressMessage("Microsoft.Interoperability", "CA1404:CallGetLastErrorImmediatelyAfterPInvoke", Justification = "Retuning error codes.")] public Win32Exception(string message, Exception innerException) : base(message, innerException) { this.nativeErrorCode = Marshal.GetLastWin32Error(); } /// /// Returns a string value of the Win32 error code. /// /// The Win32 error code. /// A string representation. [SecuritySafeCritical] private static string GetErrorMessage(int error) { string result = string.Empty; result = "Win32 error (0x" + Convert.ToString(error, 16) + ")"; return result; } } } #endif // MANAGEDESENT_ON_WSA