Ejemplo n.º 1
0
        /// <summary>
        /// Returns minimum SWF version where action with specified code was defined.
        /// </summary>
        /// <param name="code">action code</param>
        /// <returns></returns>
        public static int GetActionVersion(SwfActionCode code)
        {
            if (_mapver == null)
            {
                _mapver = EnumReflector.GetAttributeMap <SwfActionCode, int, SwfVersionAttribute>(attr => attr.Version);
            }
            int result;

            if (_mapver.TryGetValue(code, out result))
            {
                return(result);
            }
            return(-1);
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Try to create concrete <see cref="SwfAction"/> subclass using given action code.
        /// </summary>
        /// <param name="code">action code</param>
        /// <returns></returns>
        public static SwfAction Create(SwfActionCode code)
        {
            //TODO: Can be optimized using simple switch.

            ConstructorInfo ctor;

            if (_ctors == null)
            {
                _ctors = new Hashtable();

                var asm = typeof(SwfTagFactory).Assembly;

                foreach (var type in asm.GetTypes())
                {
                    if (type.IsAbstract)
                    {
                        continue;
                    }

                    if (type.IsDefined(typeof(TODOAttribute), true))
                    {
                        continue;
                    }

                    var attr = type.GetAttribute <SwfActionAttribute>(true);
                    if (attr != null)
                    {
                        ctor = type.GetConstructor(Type.EmptyTypes);
                        if (ctor == null)
                        {
                            throw new InvalidOperationException("SwfTag has no default ctor");
                        }
                        _ctors[attr.Code] = ctor;
                    }
                }
            }

            ctor = (ConstructorInfo)_ctors[code];
            if (ctor != null)
            {
                return((SwfAction)ctor.Invoke(null));
            }

            return(null);
        }
Ejemplo n.º 3
0
 public SwfActionAttribute(SwfActionCode code)
 {
     Code = code;
 }
Ejemplo n.º 4
0
 public SwfUnknownAction(SwfActionCode code, byte[] data)
 {
     _code = code;
     Data  = data;
 }
Ejemplo n.º 5
0
 public SwfUnknownAction(SwfActionCode code)
 {
     _code = code;
 }
Ejemplo n.º 6
0
 public SwfSimpleAction(SwfActionCode code)
 {
     _code = code;
 }