2012-02-01 12 views
13

यह वर्तमान परियोजना के पिछले डेवलपर्स मैं पकड़ा हवा है कि अपने समय के अंत निकट आ गया था और फैसला किया साथ काम कर रहा हूँ लगता है विघटित कर सकते हैं जो कुछ भी इसके साथ सौदा करेगा, उसके लिए दर्द होने के लिए कुछ काम करने वाले अभी तक अप्रबंधनीय कोड बनाने के लिए। दुर्भाग्य से मैं व्यक्ति कहता हूं।मैं एक नि: शुल्क उपकरण के लिए देख रहा हूँ स्टैंड-अलोन या ऐड-इन, कि त्रिगुट भाव

कोड के दौरान मुझे बहु-सशर्त टर्नरी अभिव्यक्तियां मिल रही हैं। यह अनुवाद करने और फिर से लिखने/दोबारा लिखने के लिए सिरदर्द हो रहा है।

किसी को भी एक नि: शुल्क उपकरण, स्टैंडअलोन का पता है या करता है वी.एस. 2008 के लिए एक ऐड-इन, कि त्रिगुट भाव विघटित कर सकते हैं के रूप में? इस परियोजना पर कोडरश के लिए कोई बजट नहीं है। यदि आवश्यक हो तो मैं फिर से कोडिंग जारी रखूंगा, लेकिन मैं यहां थोड़ी उम्मीद करने की कोशिश कर रहा हूं।

यहां इस मुद्दे का एक उदाहरण है (आपको इसे देखने के लिए खेद है)।

sNoteType = objSelection.Items[1].Selected ? 
    objSelection.Items[0].Selected ? 
    objSelection.Items[3].Selected ? 
    objSelection.Items[4].Selected ? 
    objSelection.Items[5].Selected ? 
    objSelection.Items[2].Selected ? 
    string.Empty + "OV " : 
    string.Empty + "EV " : 
    objSelection.Items[2].Selected ? 
    string.Empty + "OV " : 
    string.Empty + "LT " : 
    objSelection.Items[5].Selected ? 
    objSelection.Items[2].Selected ? 
    string.Empty + "OV " : 
    string.Empty + "EV " : 
    objSelection.Items[2].Selected ? 
    string.Empty + "OV " : 
    string.Empty + "BA " : 
    objSelection.Items[4].Selected ? 
    objSelection.Items[5].Selected ? 
    objSelection.Items[2].Selected ? 
    string.Empty + "OV " : 
    string.Empty + "EV " : 
    objSelection.Items[2].Selected ? 
    string.Empty + "OV " : 
    string.Empty + "LT " : 
    objSelection.Items[5].Selected ? 
    objSelection.Items[2].Selected ? 
    string.Empty + "OV " : 
    string.Empty + "EV " : 
    objSelection.Items[2].Selected ? 
    string.Empty + "OV " : 
    string.Empty + "LS " : 
    objSelection.Items[3].Selected ? 
    objSelection.Items[4].Selected ? 
    objSelection.Items[5].Selected ? 
    objSelection.Items[2].Selected ? 
    string.Empty + "OV " : 
    string.Empty + "EV " : 
    objSelection.Items[2].Selected ? 
    string.Empty + "OV " : 
    string.Empty + "LT " : 
    objSelection.Items[5].Selected ? 
    objSelection.Items[2].Selected ? 
    string.Empty + "OV " : 
    string.Empty + "EV " : 
    objSelection.Items[2].Selected ? 
    string.Empty + "OV " : 
    string.Empty + "BA " : 
    objSelection.Items[4].Selected ? 
    objSelection.Items[5].Selected ? 
    objSelection.Items[2].Selected ? 
    string.Empty + "OV " : 
    string.Empty + "EV " : 
    objSelection.Items[2].Selected ? 
    string.Empty + "OV " : 
    string.Empty + "LT " : 
    objSelection.Items[5].Selected ? 
    objSelection.Items[2].Selected ? 
    string.Empty + "OV " : 
    string.Empty + "EV " : 
    objSelection.Items[2].Selected ? 
    string.Empty + "OV " : 
    string.Empty + "FD " : 
    objSelection.Items[0].Selected ? 
    objSelection.Items[3].Selected ? 
    objSelection.Items[4].Selected ? 
    objSelection.Items[5].Selected ? 
    objSelection.Items[2].Selected ? 
    string.Empty + "OV " : 
    string.Empty + "EV " : 
    objSelection.Items[2].Selected ? 
    string.Empty + "OV " : 
    string.Empty + "LT " : 
    objSelection.Items[5].Selected ? 
    objSelection.Items[2].Selected ? 
    string.Empty + "OV " : 
    string.Empty + "EV " : 
    objSelection.Items[2].Selected ? 
    string.Empty + "OV " : 
    string.Empty + "BA " : 
    objSelection.Items[4].Selected ? 
    objSelection.Items[5].Selected ? 
    objSelection.Items[2].Selected ? 
    string.Empty + "OV " : 
    string.Empty + "EV " : 
    objSelection.Items[2].Selected ? 
    string.Empty + "OV " : 
    string.Empty + "LT " : 
    objSelection.Items[5].Selected ? 
    objSelection.Items[2].Selected ? 
    string.Empty + "OV " : 
    string.Empty + "EV " : 
    objSelection.Items[2].Selected ? 
    string.Empty + "OV " : 
    string.Empty + "LS " : 
    objSelection.Items[3].Selected ? 
    objSelection.Items[4].Selected ? 
    objSelection.Items[5].Selected ? 
    objSelection.Items[2].Selected ? 
    string.Empty + "OV " : 
    string.Empty + "EV " : 
    objSelection.Items[2].Selected ? 
    string.Empty + "OV " : 
    string.Empty + "LT " : 
    objSelection.Items[5].Selected ? 
    objSelection.Items[2].Selected ? 
    string.Empty + "OV " : 
    string.Empty + "EV " : 
    objSelection.Items[2].Selected ? 
    string.Empty + "OV " : 
    string.Empty + "BA " : 
    objSelection.Items[4].Selected ? 
    objSelection.Items[5].Selected ? 
    objSelection.Items[2].Selected ? 
    string.Empty + "OV " : 
    string.Empty + "EV " : 
    objSelection.Items[2].Selected ? 
    string.Empty + "OV " : 
    string.Empty + "LT " : 
    objSelection.Items[5].Selected ? 
    objSelection.Items[2].Selected ? 
    string.Empty + "OV " : 
    string.Empty + "EV " : 
    objSelection.Items[2].Selected ? 
    string.Empty + "OV " : 
    string.Empty; 
+8

ओच। मुझे बस इतना ही मिला है। माफ़ कीजिये। –

+11

आप इसे दैनिक डब्ल्यूटीएफ पर पोस्ट करना चाहते हैं। –

+0

कोडरश और रीशेपर दोनों के पास अपने उत्पादों का नि: शुल्क परीक्षण है जो आपके लिए इस कोड को साफ़ करने के लिए काफी लंबा होना चाहिए। आप कोड आधार की सफाई में अपनी उत्पादकता के आधार पर अपने प्रबंधन को लाइसेंस खरीदने का औचित्य भी दे सकते हैं। – tawman

उत्तर

5

कोडरश एक्सप्रेस (फ्री) यह और भी बहुत कुछ करता है। here देखें।

+0

हटाएं निराशा की धुंध में मैंने अपनी साइट पर एक्सप्रेस संस्करण भी नहीं देखा। मुझे यहां इंगित करने के लिए धन्यवाद। –

8

ReSharper टर्नरी को if/else में परिवर्तित कर सकते हैं।

मैं वास्तव में इसे रीशेपर के माध्यम से चलाता हूं, और आउटपुट उतना ही डरावना है। मैं आपको रिफैक्टरिंग में शुभकामनाएं देता हूं।

if (objSelection.Items[1].Selected) 
      if (objSelection.Items[0].Selected) 
       if (objSelection.Items[3].Selected) 
        if (objSelection.Items[4].Selected) 
         if (objSelection.Items[5].Selected) 
          if (objSelection.Items[2].Selected) sNoteType = string.Empty + "OV "; 
          else sNoteType = string.Empty + "EV "; 
         else 
         { 
          if (objSelection.Items[2].Selected) sNoteType = string.Empty + "OV "; 
          else sNoteType = string.Empty + "LT "; 
         } 
        else 
        { 
         if (objSelection.Items[5].Selected) 
          if (objSelection.Items[2].Selected) sNoteType = string.Empty + "OV "; 
          else sNoteType = string.Empty + "EV "; 
         else 
         { 
          if (objSelection.Items[2].Selected) sNoteType = string.Empty + "OV "; 
          else sNoteType = string.Empty + "BA "; 
         } 
        } 
       else 
       { 
        if (objSelection.Items[4].Selected) 
         if (objSelection.Items[5].Selected) 
          if (objSelection.Items[2].Selected) sNoteType = string.Empty + "OV "; 
          else sNoteType = string.Empty + "EV "; 
         else 
         { 
          if (objSelection.Items[2].Selected) sNoteType = string.Empty + "OV "; 
          else sNoteType = string.Empty + "LT "; 
         } 
        else 
        { 
         if (objSelection.Items[5].Selected) 
          if (objSelection.Items[2].Selected) sNoteType = string.Empty + "OV "; 
          else sNoteType = string.Empty + "EV "; 
         else 
         { 
          if (objSelection.Items[2].Selected) sNoteType = string.Empty + "OV "; 
          else sNoteType = string.Empty + "LS "; 
         } 
        } 
       } 
      else 
      { 
       if (objSelection.Items[3].Selected) 
        if (objSelection.Items[4].Selected) 
         if (objSelection.Items[5].Selected) 
          if (objSelection.Items[2].Selected) sNoteType = string.Empty + "OV "; 
          else sNoteType = string.Empty + "EV "; 
         else 
         { 
          if (objSelection.Items[2].Selected) sNoteType = string.Empty + "OV "; 
          else sNoteType = string.Empty + "LT "; 
         } 
        else 
        { 
         if (objSelection.Items[5].Selected) 
          if (objSelection.Items[2].Selected) sNoteType = string.Empty + "OV "; 
          else sNoteType = string.Empty + "EV "; 
         else 
         { 
          if (objSelection.Items[2].Selected) sNoteType = string.Empty + "OV "; 
          else sNoteType = string.Empty + "BA "; 
         } 
        } 
       else 
       { 
        if (objSelection.Items[4].Selected) 
         if (objSelection.Items[5].Selected) 
          if (objSelection.Items[2].Selected) sNoteType = string.Empty + "OV "; 
          else sNoteType = string.Empty + "EV "; 
         else 
         { 
          if (objSelection.Items[2].Selected) sNoteType = string.Empty + "OV "; 
          else sNoteType = string.Empty + "LT "; 
         } 
        else 
        { 
         if (objSelection.Items[5].Selected) 
          if (objSelection.Items[2].Selected) sNoteType = string.Empty + "OV "; 
          else sNoteType = string.Empty + "EV "; 
         else 
         { 
          if (objSelection.Items[2].Selected) sNoteType = string.Empty + "OV "; 
          else sNoteType = string.Empty + "FD "; 
         } 
        } 
       } 
      } 
     else 
     { 
      if (objSelection.Items[0].Selected) 
       if (objSelection.Items[3].Selected) 
        if (objSelection.Items[4].Selected) 
         if (objSelection.Items[5].Selected) 
          if (objSelection.Items[2].Selected) sNoteType = string.Empty + "OV "; 
          else sNoteType = string.Empty + "EV "; 
         else 
         { 
          if (objSelection.Items[2].Selected) sNoteType = string.Empty + "OV "; 
          else sNoteType = string.Empty + "LT "; 
         } 
        else 
        { 
         if (objSelection.Items[5].Selected) 
          if (objSelection.Items[2].Selected) sNoteType = string.Empty + "OV "; 
          else sNoteType = string.Empty + "EV "; 
         else 
         { 
          if (objSelection.Items[2].Selected) sNoteType = string.Empty + "OV "; 
          else sNoteType = string.Empty + "BA "; 
         } 
        } 
       else 
       { 
        if (objSelection.Items[4].Selected) 
         if (objSelection.Items[5].Selected) 
          if (objSelection.Items[2].Selected) sNoteType = string.Empty + "OV "; 
          else sNoteType = string.Empty + "EV "; 
         else 
         { 
          if (objSelection.Items[2].Selected) sNoteType = string.Empty + "OV "; 
          else sNoteType = string.Empty + "LT "; 
         } 
        else 
        { 
         if (objSelection.Items[5].Selected) 
          if (objSelection.Items[2].Selected) sNoteType = string.Empty + "OV "; 
          else sNoteType = string.Empty + "EV "; 
         else 
         { 
          if (objSelection.Items[2].Selected) sNoteType = string.Empty + "OV "; 
          else sNoteType = string.Empty + "LS "; 
         } 
        } 
       } 
      else 
      { 
       if (objSelection.Items[3].Selected) 
        if (objSelection.Items[4].Selected) 
         if (objSelection.Items[5].Selected) 
          if (objSelection.Items[2].Selected) sNoteType = string.Empty + "OV "; 
          else sNoteType = string.Empty + "EV "; 
         else 
         { 
          if (objSelection.Items[2].Selected) sNoteType = string.Empty + "OV "; 
          else sNoteType = string.Empty + "LT "; 
         } 
        else 
        { 
         if (objSelection.Items[5].Selected) 
          if (objSelection.Items[2].Selected) sNoteType = string.Empty + "OV "; 
          else sNoteType = string.Empty + "EV "; 
         else 
         { 
          if (objSelection.Items[2].Selected) sNoteType = string.Empty + "OV "; 
          else sNoteType = string.Empty + "BA "; 
         } 
        } 
       else 
       { 
        if (objSelection.Items[4].Selected) 
         if (objSelection.Items[5].Selected) 
          if (objSelection.Items[2].Selected) sNoteType = string.Empty + "OV "; 
          else sNoteType = string.Empty + "EV "; 
         else 
         { 
          if (objSelection.Items[2].Selected) sNoteType = string.Empty + "OV "; 
          else sNoteType = string.Empty + "LT "; 
         } 
        else 
        { 
         if (objSelection.Items[5].Selected) 
          if (objSelection.Items[2].Selected) sNoteType = string.Empty + "OV "; 
          else sNoteType = string.Empty + "EV "; 
         else 
         { 
          if (objSelection.Items[2].Selected) sNoteType = string.Empty + "OV "; 
          else sNoteType = string.Empty; 
         } 
        } 
       } 
      } 
     } 
+0

अनुसंधान के लिए धन्यवाद। यह अच्छी तरह से पता है कि इस समुदाय के पास आपके जैसे उपयोगकर्ताओं से समर्थन है। मैं कोडरश एक्सप्रेस संस्करण के साथ जा रहा हूं इसलिए मुझे एक उपकरण पर निर्भर नहीं है जिसे मैं बाद में खरीद नहीं पाऊंगा। –

+0

वह कोड मुझे रोता है। – Reid

1

अगर मैं ऐसी स्थिति का सामना करना पड़ा, मैं रोसलिन की जांच और देखें कि यह कैसे मदद कर सकते हैं के लिए इसका इस्तेमाल होगा। मैं वी.एस. के लिए एक प्लगइन के विकास लगता है, त्रिगुट अभिव्यक्ति आपके द्वारा चुने गए पुनर्रचना, एक "सप्ताह के अंत में" परियोजना फिट होगा।

http://blog.filipekberg.se/2011/10/23/exploring-how-to-write-a-code-analyzer-with-roslyn/ http://blogs.msdn.com/b/csharpfaq/archive/2011/11/03/using-the-roslyn-syntax-api.aspx

+0

मुझे इस गड़बड़ को कुछ मजेदार बनाने के आपके दृष्टिकोण को पसंद है! –

3

मैं तुम्हारे लिए यह परिवर्तित उपयोग करते हुए मेरे CodeRush एक्सप्रेस

if (objSelection.Items[1].Selected) 
    if (objSelection.Items[0].Selected) 
     if (objSelection.Items[3].Selected) 
      if (objSelection.Items[4].Selected) 
       if (objSelection.Items[5].Selected) 
        if (objSelection.Items[2].Selected) 
         sNoteType = string.Empty + "OV "; 
        else 
         sNoteType = string.Empty + "EV "; 
       else 
        if (objSelection.Items[2].Selected) 
         sNoteType = string.Empty + "OV "; 
        else 
         sNoteType = string.Empty + "LT "; 
      else 
       if (objSelection.Items[5].Selected) 
        if (objSelection.Items[2].Selected) 
         sNoteType = string.Empty + "OV "; 
        else 
         sNoteType = string.Empty + "EV "; 
       else 
        if (objSelection.Items[2].Selected) 
         sNoteType = string.Empty + "OV "; 
        else 
         sNoteType = string.Empty + "BA "; 
     else 
      if (objSelection.Items[4].Selected) 
       if (objSelection.Items[5].Selected) 
        if (objSelection.Items[2].Selected) 
         sNoteType = string.Empty + "OV "; 
        else 
         sNoteType = string.Empty + "EV "; 
       else 
        if (objSelection.Items[2].Selected) 
         sNoteType = string.Empty + "OV "; 
        else 
         sNoteType = string.Empty + "LT "; 
      else 
       if (objSelection.Items[5].Selected) 
        if (objSelection.Items[2].Selected) 
         sNoteType = string.Empty + "OV "; 
        else 
         sNoteType = string.Empty + "EV "; 
       else 
        if (objSelection.Items[2].Selected) 
         sNoteType = string.Empty + "OV "; 
        else 
         sNoteType = string.Empty + "LS "; 
    else 
     if (objSelection.Items[3].Selected) 
      if (objSelection.Items[4].Selected) 
       if (objSelection.Items[5].Selected) 
        if (objSelection.Items[2].Selected) 
         sNoteType = string.Empty + "OV "; 
        else 
         sNoteType = string.Empty + "EV "; 
       else 
        if (objSelection.Items[2].Selected) 
         sNoteType = string.Empty + "OV "; 
        else 
         sNoteType = string.Empty + "LT "; 
      else 
       if (objSelection.Items[5].Selected) 
        if (objSelection.Items[2].Selected) 
         sNoteType = string.Empty + "OV "; 
        else 
         sNoteType = string.Empty + "EV "; 
       else 
        if (objSelection.Items[2].Selected) 
         sNoteType = string.Empty + "OV "; 
        else 
         sNoteType = string.Empty + "BA "; 
     else 
      if (objSelection.Items[4].Selected) 
       if (objSelection.Items[5].Selected) 
        if (objSelection.Items[2].Selected) 
         sNoteType = string.Empty + "OV "; 
        else 
         sNoteType = string.Empty + "EV "; 
       else 
        if (objSelection.Items[2].Selected) 
         sNoteType = string.Empty + "OV "; 
        else 
         sNoteType = string.Empty + "LT "; 
      else 
       if (objSelection.Items[5].Selected) 
        if (objSelection.Items[2].Selected) 
         sNoteType = string.Empty + "OV "; 
        else 
         sNoteType = string.Empty + "EV "; 
       else 
        if (objSelection.Items[2].Selected) 
         sNoteType = string.Empty + "OV "; 
        else 
         sNoteType = string.Empty + "FD "; 
else 
    if (objSelection.Items[0].Selected) 
     if (objSelection.Items[3].Selected) 
      if (objSelection.Items[4].Selected) 
       if (objSelection.Items[5].Selected) 
        if (objSelection.Items[2].Selected) 
         sNoteType = string.Empty + "OV "; 
        else 
         sNoteType = string.Empty + "EV "; 
       else 
        if (objSelection.Items[2].Selected) 
         sNoteType = string.Empty + "OV "; 
        else 
         sNoteType = string.Empty + "LT "; 
      else 
       if (objSelection.Items[5].Selected) 
        if (objSelection.Items[2].Selected) 
         sNoteType = string.Empty + "OV "; 
        else 
         sNoteType = string.Empty + "EV "; 
       else 
        if (objSelection.Items[2].Selected) 
         sNoteType = string.Empty + "OV "; 
        else 
         sNoteType = string.Empty + "BA "; 
     else 
      if (objSelection.Items[4].Selected) 
       if (objSelection.Items[5].Selected) 
        if (objSelection.Items[2].Selected) 
         sNoteType = string.Empty + "OV "; 
        else 
         sNoteType = string.Empty + "EV "; 
       else 
        if (objSelection.Items[2].Selected) 
         sNoteType = string.Empty + "OV "; 
        else 
         sNoteType = string.Empty + "LT "; 
      else 
       if (objSelection.Items[5].Selected) 
        if (objSelection.Items[2].Selected) 
         sNoteType = string.Empty + "OV "; 
        else 
         sNoteType = string.Empty + "EV "; 
       else 
        if (objSelection.Items[2].Selected) 
         sNoteType = string.Empty + "OV "; 
        else 
         sNoteType = string.Empty + "LS "; 
    else 
     if (objSelection.Items[3].Selected) 
      if (objSelection.Items[4].Selected) 
       if (objSelection.Items[5].Selected) 
        if (objSelection.Items[2].Selected) 
         sNoteType = string.Empty + "OV "; 
        else 
         sNoteType = string.Empty + "EV "; 
       else 
        if (objSelection.Items[2].Selected) 
         sNoteType = string.Empty + "OV "; 
        else 
         sNoteType = string.Empty + "LT "; 
      else 
       if (objSelection.Items[5].Selected) 
        if (objSelection.Items[2].Selected) 
         sNoteType = string.Empty + "OV "; 
        else 
         sNoteType = string.Empty + "EV "; 
       else 
        if (objSelection.Items[2].Selected) 
         sNoteType = string.Empty + "OV "; 
        else 
         sNoteType = string.Empty + "BA "; 
     else 
      if (objSelection.Items[4].Selected) 
       if (objSelection.Items[5].Selected) 
        if (objSelection.Items[2].Selected) 
         sNoteType = string.Empty + "OV "; 
        else 
         sNoteType = string.Empty + "EV "; 
       else 
        if (objSelection.Items[2].Selected) 
         sNoteType = string.Empty + "OV "; 
        else 
         sNoteType = string.Empty + "LT "; 
      else 
       if (objSelection.Items[5].Selected) 
        if (objSelection.Items[2].Selected) 
         sNoteType = string.Empty + "OV "; 
        else 
         sNoteType = string.Empty + "EV "; 
       else 
        if (objSelection.Items[2].Selected) 
         sNoteType = string.Empty + "OV "; 
        else 
         sNoteType = string.Empty; 

बहरहाल, यह अभी भी बहुत बदसूरत है। मैं तुम्हें एक छह आयामी सच्चाई तालिका

string[,,,,,] table = new string[2,2,2,2,2,2]; 
table[0, 0, 0, 0, 0, 0] = "AA"; 
table[0, 0, 0, 0, 0, 1] = "BB"; 
table[0, 0, 0, 0, 1, 0] = "CC"; 
table[0, 0, 0, 0, 1, 1] = "DD"; 
... 

उपयोग करने के लिए यह तो इस

string sNoteType = table[ 
    objSelection.Items[0].Selected ? 1 : 0, 
    objSelection.Items[1].Selected ? 1 : 0, 
    objSelection.Items[2].Selected ? 1 : 0, 
    objSelection.Items[3].Selected ? 1 : 0, 
    objSelection.Items[4].Selected ? 1 : 0, 
    objSelection.Items[5].Selected ? 1 : 0]; 
10

तरह पूछे जा सकती है, कोड का अर्थ वास्तव में बहुत से ऐसा लगता है सरल है सुझाव है। ReSharper के साथ सतत मुझे निम्नलिखित पाया:

string sNoteType; 
var items = objSelection.Items; 

var item0Selected = items[0].Selected; 
string item3NotSelectedValue; 
if (items[1].Selected) 
{ 
    item3NotSelectedValue = item0Selected ? "LS " : "FD "; 
} 
else 
{ 
    item3NotSelectedValue = item0Selected ? "LS " : string.Empty; 
} 

if (items[2].Selected) 
{ 
    sNoteType = "OV "; 
} 
else 
{ 
    if (items[5].Selected) 
    { 
     sNoteType = "EV "; 
    } 
    else 
    { 
     if (items[4].Selected) 
     { 
      sNoteType = "LT "; 
     } 
     else 
     { 
      if (items[3].Selected) 
      { 
       sNoteType = "BA "; 
      } 
      else 
      { 
       sNoteType = item3NotSelectedValue; 
      } 
     } 
    } 
} 

के बाद से जॉन सभी कड़ी मेहनत किया था, यहाँ एक संपादन मैं सार करने के लिए यह फोड़े नीचे लगता है कि है। जाहिर है, आप इस कोड के आसपास परीक्षण यथाशीघ्र रखना चाहते हैं - के रूप में मैं इस कुरूपता डिकोडिंग में कुछ गलती कर नहीं कल्पना नहीं कर सकते, और स्वचालित रिफैक्टरिंग केवल, तुम अब तक (नहीं बहुत होने वाली है नमूनों की दिखता से यहाँ रखा):

var items = objSelection.Items; 
string sNoteType = string.Empty;  
if (items[0].Selected && items[1].Selected) { 
    sNoteType = "LS "; 
} else if (items[1].Selected) { 
    sNoteType = "FD "; 
} else if (items[2].Selected) { 
    sNoteType = "OV "; 
} else if (items[3].Selected) { 
    sNoteType = "BA ";  
} else if (items[4].Selected) { 
    sNoteType = "LT "; 
} else if (items[5].Selected) { 
    sNoteType = "EV "; 
} 
5

इस कोड को मूल कुरूपता को समान रूप से व्यवहार करना चाहिए:

string sNoteType; 
if (objSelection.Items[2].Selected) 
{ 
    sNoteType = "OV "; 
} 
else if (objSelection.Items[5].Selected) 
{ 
    sNoteType = "EV "; 
} 
else if (objSelection.Items[4].Selected) 
{ 
    sNoteType = "LT "; 
} 
else if (objSelection.Items[3].Selected) 
{ 
    sNoteType = "BA "; 
} 
else if (objSelection.Items[0].Selected) 
{ 
    sNoteType = "LS "; 
} 
else if (objSelection.Items[1].Selected) 
{ 
    sNoteType = "FD "; 
} 
else 
{ 
    sNoteType = string.Empty; 
} 

इस पर पहुंचने के लिए मैं इस धारणा है कि जो कुछ भी कोड वर्तमान में क्या कर रहा है सही है के साथ शुरू कर दिया। इसके बाद मैंने 64 परीक्षण मामलों को उत्पन्न करने के लिए एक स्क्रिप्ट लिखी - एक सत्य मूल्यों के प्रत्येक संयोजन के लिए।इस का एक समूह कल्पना कीजिए:

[TestCase("EV ", "000001")] 
[TestCase("LT ", "000010")] 
[TestCase("EV ", "000011")] 
[TestCase("BA ", "000100")] 
[TestCase("EV ", "000101")] 

तब मैं पैटर्न eyeballed और अगर-बयान एक के बाद एक कुरूपता नहीं रह गया है सब पर की जरूरत थी जब तक गयी। मैं गारंटी नहीं दे सकता कि इस प्रकार मूल लेखक तर्क की कल्पना कर रहा था, लेकिन गारंटी दे सकता है कि यह सभी संभावित मामलों में समान रूप से व्यवहार करता है।

संबंधित मुद्दे