Ejemplo n.º 1
0
        /// <summary>
        /// Gets invokable methods by type
        /// </summary>
        public static MethodInfo[] GetInvokeAt(this Type source, InvokeAtType type)
        {
            var result  = new List <MethodInfo>();
            var methods = source.GetMethods(BindingFlags.Static | BindingFlags.Public);

            for (int i = 0; i < methods.Length; ++i)
            {
                var info = methods[i];
                var attr = info.GetCustomAttributes(typeof(InvokeAtAttribute), false)
                           .FirstOrDefault();
                if (attr == null)
                {
                    continue;
                }

                if ((attr as InvokeAtAttribute).Type != type)
                {
                    continue;
                }

                if (info.ReturnType != typeof(void))
                {
                    throw new TargetInvocationException("A function is marked with InvokeAt attribute, but the return type is not System.Void. Source: " + source.ToString(), null);
                }

                if (info.GetParameters().Length != 0)
                {
                    throw new TargetInvocationException("A function is marked with InvokeAt attribute, but contains parameters. Source: " + source.ToString(), null);
                }

                result.Add(info);
            }

            return(result.ToArray());
        }
Ejemplo n.º 2
0
 /// <summary>
 /// Attribute that allows a target method to be annotated for automatic invoke.
 /// </summary>
 /// <param name="type">Specifies a state during which the target annotated method should be invoked.</param>
 /// <param name="priority">Specifies the priority with which this method should be invoked.</param>
 public InvokeAtAttribute(InvokeAtType type, int priority)
 {
     fType     = type;
     fPriority = priority;
 }
Ejemplo n.º 3
0
 /// <summary>
 /// Attribute that allows a target method to be annotated for automatic invoke.
 /// </summary>
 /// <param name="type">Specifies a state during which the target annotated method should be invoked.</param>
 public InvokeAtAttribute(InvokeAtType type)
 {
     fType = type;
 }