コード例 #1
0
 // Token: 0x0600035C RID: 860 RVA: 0x00010C94 File Offset: 0x0000EE94
 public void PoisonCall(EmergencyKit kit, TryDelegate dangerousCall)
 {
     PoisonControl.< > c__DisplayClass1 CS$ < > 8__locals1 = new PoisonControl.< > c__DisplayClass1();
     CS$ < > 8__locals1.kit         = kit;
     CS$ < > 8__locals1.< > 4__this = this;
     ILUtil.DoTryFilterCatch(dangerousCall, new FilterDelegate(CS$ < > 8__locals1, (UIntPtr)ldftn(< PoisonCall > b__0)), null);
 }
コード例 #2
0
ファイル: Lexer.cs プロジェクト: zoujiaqing/Obsidian
 internal Lexer(JinjaEnvironment environment)
 {
     Environment = environment;
     _Delegates  = new TryDelegate[]
     {
         TryNewLine,
         TryWhiteSpace,
         TryKeyword,
         TrySingleChar,
     };
     _KeywordLookups.Add(environment.Settings.BlockStartString.ToCharArray(), TokenType.StatementStart);
     _KeywordLookups.Add(environment.Settings.BlockEndString.ToCharArray(), TokenType.StatementEnd);
     _KeywordLookups.Add(environment.Settings.VariableStartString.ToCharArray(), TokenType.ExpressionStart);
     _KeywordLookups.Add(environment.Settings.VariableEndString.ToCharArray(), TokenType.ExpressionEnd);
     _KeywordLookups.Add(environment.Settings.CommentStartString.ToCharArray(), TokenType.CommentStart);
     _KeywordLookups.Add(environment.Settings.CommentEndString.ToCharArray(), TokenType.CommentEnd);
     if (environment.Settings.LineCommentPrefix != null)
     {
         _KeywordLookups.Add(environment.Settings.LineCommentPrefix.ToCharArray(), TokenType.LineComment);
     }
     if (environment.Settings.LineStatementPrefix != null)
     {
         _KeywordLookups.Add(environment.Settings.LineStatementPrefix.ToCharArray(), TokenType.LineStatement);
     }
 }
コード例 #3
0
        private static string TryGetOrDefault(TryDelegate getter, string defaultValue)
        {
            if (getter(out string result))
            {
                return(result);
            }

            return(defaultValue);
        }
コード例 #4
0
 static void TryTest(TryDelegate d)
 {
     try
     {
         d();
     }
     catch (Exception e)
     {
         Console.WriteLine("Error: {0}", e);
     }
 }
コード例 #5
0
 public bool TryExecute(TryDelegate task)
 {
     TransientExceptionHandler.< > c__DisplayClass1 CS$ < > 8__locals1 = new TransientExceptionHandler.< > c__DisplayClass1();
     CS$ < > 8__locals1.< > 4__this = this;
     ArgumentValidator.ThrowIfNull("task", task);
     CS$ < > 8__locals1.exception   = null;
     CS$ < > 8__locals1.needToRetry = false;
     ILUtil.DoTryFilterCatch(task, this.transientExceptionFilter, new CatchDelegate(CS$ < > 8__locals1, (UIntPtr)ldftn(< TryExecute > b__0)));
     if (!CS$ < > 8__locals1.needToRetry)
     {
         this.TransientExceptionCount = 0;
         this.tracer.TraceDebug((long)this.GetHashCode(), "TransientExceptionHandler.TryExecute: Task completed successfully and the retry count has beeen restarted.");
     }
コード例 #6
0
            public static T?ParseNullable <T>(string s, TryDelegate <T> tryDelegate) where T : struct
            {
                if (s == null)
                {
                    return(null);
                }

                T temp;

                return(tryDelegate(s, out temp)
                    ? (T?)temp
                    : null);
            }
コード例 #7
0
            public static bool TryParseNullable <T>(string s, out T?result, TryDelegate <T> tryDelegate) where T : struct
            {
                if (s == null)
                {
                    result = null;
                    return(true);
                }

                T    temp;
                bool success = tryDelegate(s, out temp);

                result = temp;
                return(success);
            }
コード例 #8
0
 public void ExecuteWithRetry(TryDelegate task)
 {
     ArgumentValidator.ThrowIfNull("task", task);
     while (!this.TryExecute(task))
     {
         if (this.budget != null)
         {
             this.budget.EndLocal();
         }
         if (this.delayBetweenAttempts > TimeSpan.Zero)
         {
             this.tracer.TraceDebug <TimeSpan>((long)this.GetHashCode(), "TransientExceptionHandler.ExecuteWithRetry: Sleeping thread for {0}.", this.delayBetweenAttempts);
             Thread.Sleep(this.delayBetweenAttempts);
         }
         if (this.budget != null)
         {
             this.budget.StartLocal(this.callerInfo, default(TimeSpan));
         }
     }
 }
コード例 #9
0
ファイル: Optional.cs プロジェクト: webappsuk/CoreLibraries
        /// <summary>
        /// Returns the assigned value if the supplied try function returns true for the specified input.
        /// </summary>
        /// <typeparam name="TIn">The type of the input.</typeparam>
        /// <typeparam name="TOut">The type of the output.</typeparam>
        /// <param name="tryFunction">The try function.</param>
        /// <param name="input">The input.</param>
        /// <param name="unassignedOnNull">
        /// if set to <c>true</c> returns <see cref="Unassigned" /> if <paramref name="tryFunction" /> outputs a
        ///     <see langword="null" />,
        /// even when it returns <see langword="true" />.
        /// </param>
        /// <returns>Optional{`0}.</returns>
        public static Optional <T> UnassignedOnFailure <TIn, TOut>(
            [NotNull] TryDelegate <TIn, TOut> tryFunction,
            TIn input,
            bool unassignedOnNull = false)
            where TOut : T
        {
            if (tryFunction == null)
            {
                throw new ArgumentNullException("tryFunction");
            }
            TOut result;

            if (tryFunction(input, out result))
            {
                return(unassignedOnNull && ReferenceEquals(result, null)
                    ? Unassigned
                    : new Optional <T>(result, true));
            }
            return(Unassigned);
        }
コード例 #10
0
        public static Maybe <TResult> FromTryOut <TResult>(TryDelegate <string, TResult> call, string value)
        {
            TResult result;

            return(call(value, out result) ? Just(result) : Nothing);
        }
コード例 #11
0
        private static string TryGetOrDefault(TryDelegate getter, string defaultValue)
        {
            string result;
            if (getter(out result))
            {
                return result;
            }

            return defaultValue;
        }
コード例 #12
0
 public static T?Parse <T>(string s, TryDelegate <T> tryDelegate)
     where T : struct
 {
     return(tryDelegate(s, out T value) ? value : default(T?));
 }
コード例 #13
0
 public static Maybe <TResult> FromTryOut <TResult>([InstantHandle] TryDelegate <string, TResult> call, string value) => FromTryOut <string, TResult>(call, value);
コード例 #14
0
        public static Maybe <TResult> FromTryOut <TArg, TResult>([InstantHandle] TryDelegate <TArg, TResult> call, TArg value)
        {
            TResult result;

            return(call(value, out result) ? Just(result) : Maybe <TResult> .Nothing);
        }