English 中文(简体)
RFC - safety enum inlash AS3
原标题:RFC - safe enum in Flash AS3

Morning all

从时间的开始,人类就希望并发明了在闪S3中进行列举的方法。

有许多尝试存在各种问题,例如能够利用建筑商制造新型um(不安全)。

我认为,以下是汇编时间的类型安全,并且可以安全地避免在运行时间产生新的 en类。

主要问题是,AS3公司没有能力拥有私人建筑。 举例来说,施工商只有在通过私人静态的ENFORCER(ENFORCER)的情况下才能取得成功,而这种认证只在班级内可见。

package
{
    public class PermissionsEnum
    {

        private static const ENFORCER = new Object();

        public static const READ:PermissionsEnum = new PermissionsEnum(ENFORCER, 1);
        public static const WRITE:PermissionsEnum = new PermissionsEnum(ENFORCER, 2);
        public static const CREATE:PermissionsEnum = new PermissionsEnum(ENFORCER, 4);
        public static const DELETE:PermissionsEnum = new PermissionsEnum(ENFORCER, 8);

        private var _value:uint;

        public function PermissionsEnum(e:Object, v:uint)
        {
            if (e != ENFORCER)
                throw new Error("Attempted enum security breach.");

            this._value = v;
        }

        public function get value() : uint
        {
            return this._value;
        }

    }

}

评论

以前的其他尝试使得某些微量参考材料(例如,Java汇编者脱节,C#汇编者允许这样做)成为一种试图阻止产生更多 en价值的尝试。 我认为这更加美好。

我们认为什么?

法学硕士

问题回答

您可在建筑商中使用更严格的时间限制(以下所有法规均载于PermissionsEnum.as/code>:

package
{
public class PermissionsEnum
{

    private static const ENFORCER:Enforcer = new Enforcer();

    public static const READ:PermissionsEnum = new PermissionsEnum(ENFORCER, 1);
    public static const WRITE:PermissionsEnum = new PermissionsEnum(ENFORCER, 2);
    public static const CREATE:PermissionsEnum = new PermissionsEnum(ENFORCER, 4);
    public static const DELETE:PermissionsEnum = new PermissionsEnum(ENFORCER, 8);

    private var _value:uint;

    public function PermissionsEnum(e:Enforcer, v:uint)
    {
        this._value = v;
    }

    public function get value() : uint
    {
        return this._value;
    }

}
}

class Enforcer
{
}

(1) 如何将价值观转化为成员?

(2) 我在创建<代码>PermissionsEnum时看到了一个问题:对其内值没有共同的控制。 我指的是,如果我ve5-10名成员,就没有发现重复的价值观。 但是,如果名单增加,也有可能在源头上犯错误:

public static const READ:PermissionsEnum = new PermissionsEnum(ENFORCER, 1);
public static const WRITE:PermissionsEnum = new PermissionsEnum(ENFORCER, 7);
public static const APPEND:PermissionsEnum = new PermissionsEnum(ENFORCER, 15);
public static const CREATE:PermissionsEnum = new PermissionsEnum(ENFORCER, 8);
public static const DELETE:PermissionsEnum = new PermissionsEnum(ENFORCER, 3);
public static const COMMIT:PermissionsEnum = new PermissionsEnum(ENFORCER, 6);
public static const SUBMIT:PermissionsEnum = new PermissionsEnum(ENFORCER, 21);
public static const POP:PermissionsEnum = new PermissionsEnum(ENFORCER, 22);
public static const PUSH:PermissionsEnum = new PermissionsEnum(ENFORCER, 3);
public static const SELECT:PermissionsEnum = new PermissionsEnum(ENFORCER, 17);
public static const DESELECT:PermissionsEnum = new PermissionsEnum(ENFORCER, 22);
public static const END:PermissionsEnum = new PermissionsEnum(ENFORCER, 15);




相关问题
Finding the Highest Value in an Enumeration

I m writing a method which determines the highest value in a .NET enumeration so I can create a BitArray with one bit for each enum value: pressedKeys = new BitArray(highestValueInEnum<Keys>());...

Conversion of Enum to Enumerable

To convert Enum to Enumerable ,I use public enum Flags { Trivial=1, Minor, Major, Critical } IEnumerable<int> n = Enumerable.Range((int)Flags.Trivial, (...

Subclass check, is operator or enum check

A couple of friends was discussing the use of inheritance and how to check if a subclass is of a specific type and we decided to post it here on Stack. The debate was about if you should implement a ...

Enum scoping issues

I try to keep things as local as possible, so I put enums at class scope, even if they are shared between two classes (I put it in the class that "goes better" with it.) This has worked out great, but ...

How do I sort enum members alphabetically in Java?

I have an enum class like the following: public enum Letter { OMEGA_LETTER("Omega"), GAMMA_LETTER("Gamma"), BETA_LETTER("Beta"), ALPHA_LETTER("Alpha"), private final String ...

C++ enum value initialization

I have an enum declared in my code as: enum REMOTE_CONN { REMOTE_CONN_DEFAULT = 0, REMOTE_CONN_EX_MAN = 10000, REMOTE_CONN_SD_ANNOUNCE, REMOTE_CONN_SD_IO, REMOTE_CONN_AL, ...

WCF: Enforce equal DataContracts on both sides

I m wondering if it is possible to have WCF make sure that the DataContracts on both sides of a connection are exactly the same (and throw an exception when trying to connect if they are not). For ...

热门标签