AutoPatientInfoRecorder/src/AntdUI/Lib/Vanara/Shared/ResourceId.cs

(开头部分) 6KB

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

// THIS FILE IS PART OF Vanara PROJECT
// THE Vanara PROJECT IS AN OPENSOURCE LIBRARY LICENSED UNDER THE MIT License.
// COPYRIGHT (C) dahall. ALL RIGHTS RESERVED.
// GITHUB: https://github.com/dahall/Vanara

using System;
using System.Runtime.InteropServices;
using static Vanara.PInvoke.Macros;

#pragma warning disable IDE1006 // Naming Styles

namespace Vanara.PInvoke
{
    /// <summary>Helper structure to use for a pointer that can morph into a string, pointer or integer.</summary>
    [StructLayout(LayoutKind.Sequential, CharSet = CharSet.Auto)]
    [PInvokeData("winuser.h")]
    public struct ResourceId : IEquatable<string>, IEquatable<IntPtr>, IEquatable<int>, IEquatable<ResourceId>, IHandle
    {
        private IntPtr ptr;

        /// <summary>Gets or sets an integer identifier.</summary>
        /// <value>The identifier.</value>
        public int id
        {
            get => IS_INTRESOURCE(ptr) ? (ushort)ptr.ToInt32() : 0;
            set
            {
                if (value > ushort.MaxValue || value <= 0) throw new ArgumentOutOfRangeException(nameof(id));
                ptr = (IntPtr)(ushort)value;
            }
        }

        /// <summary>Determines whether this value is an integer identifier for a resource.</summary>
        /// <returns>If the value is a resource identifier, the return value is <see langword="true"/>. Otherwise, the return value is <see langword="false"/>.</returns>
        public bool IsIntResource => IS_INTRESOURCE(ptr);

        /// <summary>Represent a NULL value.</summary>
        public static readonly ResourceId NULL = new ResourceId();

        /// <summary>Performs an implicit conversion from <see cref="SafeResourceId"/> to <see cref="System.Int32"/>.</summary>
        /// <param name="r">The r.</param>
        /// <returns>The result of the conversion.</returns>
        public static implicit operator int(ResourceId r) => r.id;

        /// <summary>Performs an implicit conversion from <see cref="ResourceId"/> to <see cref="IntPtr"/>.</summary>
        /// <param name="r">The r.</param>
        /// <returns>The result of the conversion.</returns>
        public static implicit operator IntPtr(ResourceId r) => r.ptr;

        /// <summary>Performs an implicit conversion from <see cref="int"/> to <see cref="ResourceId"/>.</summary>
        /// <param name="resId">The resource identifier.</param>
        /// <returns>The result of the conversion.</returns>
        public static implicit operator ResourceId(int resId) => new ResourceId { id = resId };

        /// <summary>Performs an implicit conversion from <see cref="IntPtr"/> to <see cref="ResourceId"/>.</summary>
        /// <param name="p">The PTR.</param>
        /// <returns>The result of the conversion.</returns>
        public static implicit operator ResourceId(IntPtr p) => new ResourceId { ptr = p };

        /// <summary>Performs an implicit conversion from <see cref="ResourceId"/> to <see cref="string"/>.</summary>
后面还有 69 行代码,解锁后查看完整代码

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

AI 解读 AI

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

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