codemaid icon indicating copy to clipboard operation
codemaid copied to clipboard

格式化删除 `ref struct` 中的 `ref`关键字

Open xkz1994 opened this issue 2 years ago • 3 comments

Environment

  • Visual Studio version: [2022 Community]
  • CodeMaid version: [12.0]
  • Code language: [C#]

Description

Replace this text with a short description and code sample.

Steps to recreate

格式化删除 ref struct 中的 ref关键字

Current behavior

Explain what it's doing and why it's wrong.

Expected behavior

Explain what it should be doing after it's fixed.

xkz1994 avatar Jun 09 '23 09:06 xkz1994

Thanks for reporting the issue. I have been unable to reproduce it. Can you please provide a minimal code sample that exhibits the issue?

codecadwallader avatar Jul 22 '23 22:07 codecadwallader

public ref struct SplitEnumerator to public struct SplitEnumerator

        /// <summary>
        /// 分割迭代器
        /// </summary>
        public ref struct SplitEnumerator
        {
            /// <summary>
            /// 字符串
            /// </summary>
            public ReadOnlySpan<char> CurrentStr { get; private set; }

            /// <summary>
            /// 分割符
            /// </summary>
            private readonly ReadOnlySpan<char> _separator;

            /// <summary>
            /// 分割字符串
            /// </summary>
            /// <param name="currentStr">当前字符串</param>
            /// <param name="separator">分割符</param>
            public SplitEnumerator(in ReadOnlySpan<char> currentStr, in ReadOnlySpan<char> separator)
            {
                CurrentStr = currentStr;
                _separator = separator;
                Current = default;
            }

            /// <summary>
            /// 获取迭代器, 因为值类型所以是拷贝
            /// </summary>
            /// <returns>迭代器</returns>
            public SplitEnumerator GetEnumerator() => this;

            /// <summary>
            /// 迭代分割的字符串
            /// </summary>
            public ReadOnlySpan<char> Current { get; private set; }

            /// <summary>
            /// 移动到下一个分割的字符串
            /// </summary>
            /// <returns>是否包含下一个</returns>
            public bool MoveNext()
            {
                var span = CurrentStr;
                if (span.Length == 0) // Reach the end of the string
                    return false;

                var index = span.IndexOf(_separator); // 查找符合span的索引完全匹配(IndexOfAny不是完全匹配)
                if (index == -1) // The string is composed of only one line
                {
                    CurrentStr = ReadOnlySpan<char>.Empty; // The remaining string is an empty string
                    Current = span;
                    return true;
                }

                CurrentStr = span.Slice(index + _separator.Length);
                Current = span.Slice(0, index);
                return true;
            }
        }

xkz1994 avatar Jul 24 '23 02:07 xkz1994

Thank you for the code sample. I have still been unable to reproduce it. We have seen similar issues with the explicit access modifiers logic though, so perhaps if you disable inserting explicit access modifiers on structs that may help? Please see #879 for more details.

codecadwallader avatar Oct 28 '23 14:10 codecadwallader