我需要将枚举放入枚举或类似的枚举,这可能吗? [英] I need an enum placed inside an enum or something like that, is that possible?

查看:105
本文介绍了我需要将枚举放入枚举或类似的枚举,这可能吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是我制作的javascrip,是否可以制作类似的C#.net(2.0)代码?

This is a javascrip that I made, is it possible to make a simmilar C#.net (2.0) code?

// Window Frame Style Options (enum)
var w_WindowProperties = {
	"BorderStyle": { "None": "BorderStyle=" + 0, "FixedSingle": "BorderStyle=" + 1, "Fixed3D": "BorderStyle=" + 2 /*Default*/, "FixedDialog": "BorderStyle=" + 3, "Sizeable": "BorderStyle=" + 4, "FixedToolWindow": "BorderStyle=" + 5 /*MinimizeBox & MaximizeBox is hidden*/, "SizeableToolWindow": "BorderStyle=" + 6 /*MinimizeBox & MaximizeBox is hidden*/ },
	"StartPosition": { "Manual": "StartPosition=" + 0, "CenterScreen": "StartPosition=" + 1, "DefaultLocation": "StartPosition=" + 2 /*Default*/, "DefaultBounds": "StartPosition=" + 3 /* width:800px, height:600px*/, "CenterParent": "StartPosition=" + 4 },
	"ShowToolBox": { "No": "ShowToolBox=" + 0, "Yes": "ShowToolBox=" + 1 /*Default*/ },
	"ShowMinimizeBox": { "No": "ShowMinimizeBox=" + 0, "Yes": "ShowMinimizeBox=" + 1 /*Default*/},
	"ShowMaximizeBox": { "No": "ShowMaximizeBox=" + 0, "Yes": "ShowMaximizeBox=" + 1 /*Default*/ },
	"ShowCloseBox": { "No": "ShowCloseBox=" + 0, "Yes": "ShowCloseBox=" + 1 /*Default*/ }
};

推荐答案

您可以使用[Flags]属性对其进行组合:

You could use the [Flags] attribute to combine them:

[Flags]
enum WindowProps{ None=0, 
                  Fixed=1, Sizeable=2, (4), (8), (16), (32, (64), (128)
                  Single=256, ThreeD=512, Dialog=1024, ToolWindow=2048, (4096), (8192), (16384), (32768)
                  PosManual=65536, PosCenter=131072, PosDefault=262144, PosBounds=524288, PosCenterParent=1048576,  (2097152), (4194302), (8388608),
                  ShowTool=16777126, ShowMinimize=33554432, ShowMaximize=67108864, ShowClose=134217728, (268435456), (536870912), (1073741824), (21474483648) };

通知每个枚举组都在16位边界上被破坏,从而有扩展的空间.括号中的数字是每个16位块中可用的值,除非实际使用它们,否则不应将其包含在枚举中.

通过适当地开发一些辅助方法,可以非常容易地对其进行管理.

Notice that each group of enums is broken on the 16-bit boundaries, leaving room for expansion. The numbers in parenthesis are the values available withint each 16-bit block, and shouldn''t be included int your enum unless they''re actually being used.

With the appropriate development of a few helper methods, this would be very easily manageable.


不.您只需要定义几种枚举类型.对于枚举的高级使用(或不那么高级),请阅读我的文章:
枚举类型不枚举!解决.NET和语言限制 [ ^ ],
人类可读的枚举元数据 [
No. You would simple need to define several enumerations types. For advances (or not so advanced) use of enumerations, please read my articles:
Enumeration Types do not Enumerate! Working around .NET and Language Limitations[^],
Human-readable Enumeration Meta-data[^].

—SA


这篇关于我需要将枚举放入枚举或类似的枚举,这可能吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆