之前有做过一个小项目,有这样的参数要求,如果用户可以指定如下三个参数“x86”,"amd64"以及“both",分别表示在x86,amd64或者再x86以及amd64下进行编译。编译的代码很接近,唯一的区别在于使用x86还是amd64.

后来经过Blair的指导,我发现自己的代码过于冗余了,完全可以通过向量或者array的方式进行判定。 


enum PLATFORM
{    
     X86 = 0x01,
     AMD64 = 0x10;
     ARM = 0x100,
     X86_AMD64 = 0x11,
     ALL = 0x111
}

[in] PLATFORM op_pla

List<string> platList = new List<string>;

if (op_pla & X86) { platList.append("x86"); }
if (op_pla & AMD64) { platList.append("amd64"); }
if (op_pla & ARM) { platList.append("arm"); }

foreach (string pla in platList)
{
    Build(pla); // do the build process
}


这个方法可以降低代码冗余。

 

相关文章:

  • 2021-08-11
  • 2021-08-25
  • 2021-06-18
  • 2022-12-23
  • 2021-06-26
  • 2021-06-21
  • 2022-12-23
  • 2021-10-12
猜你喜欢
  • 2021-08-07
  • 2022-12-23
  • 2021-07-15
  • 2022-12-23
  • 2021-08-09
  • 2021-10-29
  • 2022-12-23
相关资源
相似解决方案