예제 #1
0
        public static string ToReason(this AuthorizationContext value, bool isAuthorized)
        {
            //
            // MUST return null and NOT empty string as the result is used as TargetNullValue in bindings!
            //
            if (isAuthorized)
            {
                return(null);
            }

            var field     = value.GetType().GetField(value.ToString());
            var attribute = Attribute.GetCustomAttribute(field, typeof(ReasonAttribute)) as ReasonAttribute;

            return(String.IsNullOrEmpty(attribute?.Reason) ? null : attribute.Reason);
        }