Exemple #1
0
        public static TEnum GetTrigger <TEnum>(this LambdaExpression selectorExpression)
            where TEnum : struct
        {
            Enum result;

            if (!triggersCache.TryGetValue(selectorExpression.@Method(), out result))
            {
                var    triggerAttribute = selectorExpression.@Attribute <TriggerAttribute>(false);
                string triggerName      = (triggerAttribute != null) ?
                                          triggerAttribute.name : GetTriggerName(selectorExpression.@MethodName());
                if (string.IsNullOrEmpty(triggerName))
                {
                    throw new NotSupportedException("Unable to resolve the trigger for the method " + selectorExpression.@MethodName());
                }
                TEnum typedResult;
                if (!Enum.TryParse <TEnum>(triggerName, out typedResult))
                {
                    throw new NotSupportedException("Unable to associate the method " + selectorExpression.@MethodName() + " with a specific trigger.");
                }
                result = (Enum)(object)typedResult;
                triggersCache.Add(selectorExpression.@Method(), result);
            }
            return((TEnum)(object)result);
        }