本文介绍了你会很长开关/ enum声明中使用的区域?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述 29岁程序员,3月因学历无情被辞! 我最近发现自己需要(是的,需要)来定义荒谬长开关报表和枚举声明在C#代码,但我想知道是什么人的感觉是将它们分成逻辑小节的最佳途径。在我的情况,无论是枚举值和例(其中基于枚举值)有相当明显的分组,但我稍微不确定如何在代码中反映这一点。 请注意,在我的代码,我有大约5组,每组10至30枚举值/每情况下 我可以预见这三个隐约明智的选项是: 定义#地区块(任选被空行分隔)。 注释每组它的名字,每个组的名称注释之前一个空行。 请两手空空 - 只需将开关/枚举作为一个巨大的情况下/值列表 的你更喜欢哪个?你会像对待枚举和单独切换?的(这似乎有点奇怪我。)现在,我不会说有任何正确/错误的回答这个问题,但我总归要在听证会很感兴趣什么一般性意见consenus是 注意1:此情况下,我可能潜在有一个非常长的枚举声明50%/ 100 +价值观是不幸的是不可避免的(同样与开关),因为我试图写一个词法分析器(tokeniser),因此这似乎有几个原因最合理的做法。 注意2:我充分认识到,几个重复的问题已经存在,就是否以一般的代码中使用的区域(用于结构类为主)的问题,但我在这里觉得我的问题是多具体还没有得到解决。 解决方案 当然,地区的事物了。他们可能没有太大变化,而在这个时候,可以扩大该地区,进行更改,折叠它,并移动到文件的其余部分。 他们是有原因的,用它们来你的优势。 I've recently found myself needing (yes, needing) to define absurdly long switch statements and enum declarations in C# code, but I'm wondering what people feel is the best way to split them into logical subsections. In my situation, both the enum values and the cases (which are based on the enum values) have fairly clear groupings, yet I am slightly unsure how to reflect this in code.Note that in my code, I have roughly 5 groups of between 10 and 30 enum values/cases each.The three vaguely sensible options I can envisage are:Define #region blocks around all logical groups of cases/enum values within the declaration (optionally separated by blank lines).Comment each group with it's name, with a blank line before each group name comment.Do nothing whatsoever - simply leave the switch/enum as a huge list of cases/values.Which do you prefer? Would you treat enums and switches separately? (This would seem slightly odd to me.) Now, I wouldn't say that there is any right/wrong answer to this question, though I would nonetheless be quite interested in hearing what the general consenus of views is.Note 1: This situation where I might potentially have an extremely long enum declaration of 50/100+ values is unfortunately unavoidable (and similarly with the switch), since I am attempting to write a lexer (tokeniser), and this would thus seem the most reasonable approach for several reasons.Note 2: I am fully aware that several duplicate questions already exist on the question of whether to use regions in general code (for structuring classes, mainly), but I feel my question here is much more specific and hasn't yet been addressed. 解决方案 Sure, region those things up. They probably don't change much, and when they do, you can expand the region, make your changes, collapse it, and move on to the rest of the file.They are there for a reason, use them to your advantage. 这篇关于你会很长开关/ enum声明中使用的区域?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持! 上岸,阿里云!
08-18 09:51