示例#1
0
 protected void VerifyIsNotValid()
 {
     if (this.IsValid)
     {
         ExceptionUtil.ThrowInvalidOperationException();
     }
 }
示例#2
0
 protected void VerifyIsValid()
 {
     if (!this.isValid)
     {
         ExceptionUtil.ThrowInvalidOperationException("This instance has been invalidated. If you are handling the event asynchronously, or storing the EventArgs for use outside the event handler method, you should first call Clone() to get a copy of this instance.");
     }
 }
 public static void AssertService <TService>(this IServiceProvider serviceProvider) where TService : class
 {
     if (serviceProvider.GetService <TService>() == null)
     {
         ExceptionUtil.ThrowInvalidOperationException();
     }
 }
示例#4
0
        public static T EnsureInitialized <T, TContext>(ref T target, TContext context, Func <TContext, T> valueFactory, out T unusedValue) where T : class
        {
            if (((T)target) != null)
            {
                unusedValue = default(T);
                return(target);
            }
            T local = valueFactory(context);

            if (local == null)
            {
                ExceptionUtil.ThrowInvalidOperationException("valueFactory may not return null");
            }
            T local2 = Interlocked.CompareExchange <T>(ref target, local, default(T));

            if (local2 == null)
            {
                unusedValue = default(T);
                return(local);
            }
            unusedValue = local;
            return(local2);
        }