CA1500 vs. SA1309 - Which one wins?

后端 未结 6 1083
野性不改
野性不改 2021-01-01 12:36

I\'ll prefix by saying that I understand that both Code Analysis and StyleCop are meant as guidelines, and many people chose to ignore these anyway. But having said that, I

6条回答
  •  春和景丽
    2021-01-01 12:56

    The only alternative I can think of that seems like it would satisfy both rules and that I have actually seen used anywhere is something like the following. I don't follow this convention myself, as it seems clumsy.

    public class Class1
    {
        // prefix private fields with "m"
        private int mValue1;
    
        public int Value1
        {
            get { return mValue1; }
            set { mValue1 = value; }
        }
    
        private string mValue2;
    
        public string Value2
        {
            get { return mValue2; }
            set { mValue2 = value; }
        }
    
        // prefix parameters with "p"
        public bool PerformAction(int pValue1, string pValue2)
        {
            if (pValue1 > mValue1)
            {
                mValue2 = pValue2;
                return true;
            }
            else
            {
                return (mValue2 == pValue2);
            }
        }
    }
    

提交回复
热议问题