src/DotNetCommon.Core/ApplicationHelper.cs

(开头部分) 5KB

这里只显示每个文件的开头 60 行。登录后可以解锁完整代码。

namespace DotNetCommon
{
    using System;
    using System.Diagnostics;
    using System.IO;
    using System.Runtime.InteropServices;
    using System.Threading;

    /// <summary>
    /// 应用程序帮助类,可用来识别当前操作系统类型、程序运行持续时间
    /// </summary>
    public static class ApplicationHelper
    {
        /// <summary>
        /// 获取当前进程运行持续的时间
        /// </summary>
        public static TimeSpan GetProcessStartupDuration() =>
            DateTime.Now.Subtract(Process.GetCurrentProcess().StartTime);

        /// <summary>
        /// 判断当前操作系统是否是 <c>Windows</c>.
        /// </summary>
        public static bool IsWindows => RuntimeInformation.IsOSPlatform(OSPlatform.Windows);

        /// <summary>
        /// 判断当前操作系统是否是<c>Linux</c>.
        /// </summary>
        public static bool IsLinux => RuntimeInformation.IsOSPlatform(OSPlatform.Linux);

        /// <summary>
        /// 判断当前操作系统是否是<c>OSX</c>.
        /// </summary>
        public static bool IsOSX => RuntimeInformation.IsOSPlatform(OSPlatform.OSX);

        /// <summary>
        /// 返回操作系统的类型<seealso cref="OSPlatform"/>
        /// </summary>
        public static OSPlatform OSPlatform => GetOSPlatform();

        /// <summary>
        /// 判断当前程序是否是 <c>LARGEADDRESSAWARE</c>
        /// <para>关于LARGEADDRESSAWARE,参考: <seealso href="https://helloacm.com/large-address-aware/"/></para>
        /// </summary>
        public static bool IsProcessLargeAddressAware()
        {
            using var p = Process.GetCurrentProcess();
            return IsLargeAddressAware(p.MainModule?.FileName);
        }

        /// <summary>
        /// <see href="https://helloacm.com/large-address-aware/"/>
        /// </summary>
        internal static bool IsLargeAddressAware(string file)
        {
            Ensure.NotNullOrEmptyOrWhiteSpace(file);
            var fileInfo = new FileInfo(file);
            Ensure.Exists(fileInfo);

            const int ImageFileLargeAddressAware = 0x20;

后面还有 69 行代码,解锁后查看完整代码

24 小时内免费解锁 3 个项目,之后 1 积分/个。 规则说明

AI 解读

登录后可用,每次 10 积分,解读结果公开显示在下面。

还没有人解读过这个文件。