codecadwallader / codemaid

CodeMaid is an open source Visual Studio extension to cleanup and simplify our C#, C++, F#, VB, PHP, PowerShell, JSON, XAML, XML, ASP, HTML, CSS, LESS, SCSS, JavaScript and TypeScript coding.
http://www.codemaid.net
GNU Lesser General Public License v3.0
1.88k stars 353 forks source link

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

Open xkz1994 opened 1 year ago

xkz1994 commented 1 year ago

Environment

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.

codecadwallader commented 1 year ago

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

xkz1994 commented 1 year ago

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;
            }
        }
codecadwallader commented 9 months ago

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.