private void ResolvePrefix(ref Attribute attribute)
 {
     if (attribute.prefixLength != 0)
     {
         ResolvePrefix(attribute.prefixOffset, attribute.prefixLength, out attribute.nsOffset, out attribute.nsLength);
     }
     else
     {
         // These should've been set when we added the prefix
         Fx.Assert(attribute.nsOffset == 0 && attribute.nsLength == 0, "");
     }
 }
 public TransactionSignalScope(TransactedAsyncResult result, Transaction transaction)
 {
     Fx.Assert(transaction != null, "Null Transaction provided to AsyncResult.TransactionSignalScope.");
     this.parent           = result;
     this.transactionScope = TransactionHelper.CreateTransactionScope(transaction);
 }
        protected void Complete(bool completedSynchronously)
        {
            if (this.isCompleted)
            {
                throw Fx.Exception.AsError(new InvalidOperationException(InternalSR.AsyncResultCompletedTwice(GetType())));
            }

#if DEBUG
            this.marker.AsyncResult = null;
            this.marker             = null;
            if (!Fx.FastDebug && completeStack == null)
            {
                completeStack = new StackTrace();
            }
#endif

            this.completedSynchronously = completedSynchronously;
            if (OnCompleting != null)
            {
                // Allow exception replacement, like a catch/throw pattern.
                try
                {
                    OnCompleting(this, this.exception);
                }
                catch (Exception exception)
                {
                    if (Fx.IsFatal(exception))
                    {
                        throw;
                    }
                    this.exception = exception;
                }
            }

            if (completedSynchronously)
            {
                // If we completedSynchronously, then there's no chance that the manualResetEvent was created so
                // we don't need to worry about a ----
                Fx.Assert(this.manualResetEvent == null, "No ManualResetEvent should be created for a synchronous AsyncResult.");
                this.isCompleted = true;
            }
            else
            {
                lock (ThisLock)
                {
                    this.isCompleted = true;
                    if (this.manualResetEvent != null)
                    {
                        this.manualResetEvent.Set();
                    }
                }
            }

            if (this.callback != null)
            {
                try
                {
                    if (VirtualCallback != null)
                    {
                        VirtualCallback(this.callback, this);
                    }
                    else
                    {
                        this.callback(this);
                    }
                }
#pragma warning disable 1634
#pragma warning suppress 56500 // transferring exception to another thread
                catch (Exception e)
                {
                    if (Fx.IsFatal(e))
                    {
                        throw;
                    }

                    throw Fx.Exception.AsError(new CallbackException(InternalSR.AsyncCallbackThrewException, e));
                }
#pragma warning restore 1634
            }
        }
示例#4
0
 public static Exception AssertAndThrowFatal(string description)
 {
     Fx.Assert(description);
     TraceCore.ShipAssertExceptionMessage(Trace, description);
     throw new FatalInternalException(description);
 }
示例#5
0
        static bool TryNumericConversion <T>(object source, out T result)
        {
            Fx.Assert(source != null, "caller must verify");
            TypeCode sourceTypeCode      = Type.GetTypeCode(source.GetType());
            TypeCode destinationTypeCode = Type.GetTypeCode(typeof(T));

            switch (sourceTypeCode)
            {
            case TypeCode.SByte:
            {
                SByte sbyteSource = (SByte)source;
                switch (destinationTypeCode)
                {
                case TypeCode.Int16:
                    result = (T)(object)(Int16)sbyteSource;
                    return(true);

                case TypeCode.Int32:
                    result = (T)(object)(Int32)sbyteSource;
                    return(true);

                case TypeCode.Int64:
                    result = (T)(object)(Int64)sbyteSource;
                    return(true);

                case TypeCode.Single:
                    result = (T)(object)(Single)sbyteSource;
                    return(true);

                case TypeCode.Double:
                    result = (T)(object)(Double)sbyteSource;
                    return(true);

                case TypeCode.Decimal:
                    result = (T)(object)(Decimal)sbyteSource;
                    return(true);
                }
                break;
            }

            case TypeCode.Byte:
            {
                Byte byteSource = (Byte)source;
                switch (destinationTypeCode)
                {
                case TypeCode.Int16:
                    result = (T)(object)(Int16)byteSource;
                    return(true);

                case TypeCode.UInt16:
                    result = (T)(object)(UInt16)byteSource;
                    return(true);

                case TypeCode.Int32:
                    result = (T)(object)(Int32)byteSource;
                    return(true);

                case TypeCode.UInt32:
                    result = (T)(object)(UInt32)byteSource;
                    return(true);

                case TypeCode.Int64:
                    result = (T)(object)(Int64)byteSource;
                    return(true);

                case TypeCode.UInt64:
                    result = (T)(object)(UInt64)byteSource;
                    return(true);

                case TypeCode.Single:
                    result = (T)(object)(Single)byteSource;
                    return(true);

                case TypeCode.Double:
                    result = (T)(object)(Double)byteSource;
                    return(true);

                case TypeCode.Decimal:
                    result = (T)(object)(Decimal)byteSource;
                    return(true);
                }
                break;
            }

            case TypeCode.Int16:
            {
                Int16 int16Source = (Int16)source;
                switch (destinationTypeCode)
                {
                case TypeCode.Int32:
                    result = (T)(object)(Int32)int16Source;
                    return(true);

                case TypeCode.Int64:
                    result = (T)(object)(Int64)int16Source;
                    return(true);

                case TypeCode.Single:
                    result = (T)(object)(Single)int16Source;
                    return(true);

                case TypeCode.Double:
                    result = (T)(object)(Double)int16Source;
                    return(true);

                case TypeCode.Decimal:
                    result = (T)(object)(Decimal)int16Source;
                    return(true);
                }
                break;
            }

            case TypeCode.UInt16:
            {
                UInt16 uint16Source = (UInt16)source;
                switch (destinationTypeCode)
                {
                case TypeCode.Int32:
                    result = (T)(object)(Int32)uint16Source;
                    return(true);

                case TypeCode.UInt32:
                    result = (T)(object)(UInt32)uint16Source;
                    return(true);

                case TypeCode.Int64:
                    result = (T)(object)(Int64)uint16Source;
                    return(true);

                case TypeCode.UInt64:
                    result = (T)(object)(UInt64)uint16Source;
                    return(true);

                case TypeCode.Single:
                    result = (T)(object)(Single)uint16Source;
                    return(true);

                case TypeCode.Double:
                    result = (T)(object)(Double)uint16Source;
                    return(true);

                case TypeCode.Decimal:
                    result = (T)(object)(Decimal)uint16Source;
                    return(true);
                }
                break;
            }

            case TypeCode.Int32:
            {
                Int32 int32Source = (Int32)source;
                switch (destinationTypeCode)
                {
                case TypeCode.Int64:
                    result = (T)(object)(Int64)int32Source;
                    return(true);

                case TypeCode.Single:
                    result = (T)(object)(Single)int32Source;
                    return(true);

                case TypeCode.Double:
                    result = (T)(object)(Double)int32Source;
                    return(true);

                case TypeCode.Decimal:
                    result = (T)(object)(Decimal)int32Source;
                    return(true);
                }
                break;
            }

            case TypeCode.UInt32:
            {
                UInt32 uint32Source = (UInt32)source;
                switch (destinationTypeCode)
                {
                case TypeCode.UInt32:
                    result = (T)(object)(UInt32)uint32Source;
                    return(true);

                case TypeCode.Int64:
                    result = (T)(object)(Int64)uint32Source;
                    return(true);

                case TypeCode.UInt64:
                    result = (T)(object)(UInt64)uint32Source;
                    return(true);

                case TypeCode.Single:
                    result = (T)(object)(Single)uint32Source;
                    return(true);

                case TypeCode.Double:
                    result = (T)(object)(Double)uint32Source;
                    return(true);

                case TypeCode.Decimal:
                    result = (T)(object)(Decimal)uint32Source;
                    return(true);
                }
                break;
            }

            case TypeCode.Int64:
            {
                Int64 int64Source = (Int64)source;
                switch (destinationTypeCode)
                {
                case TypeCode.Single:
                    result = (T)(object)(Single)int64Source;
                    return(true);

                case TypeCode.Double:
                    result = (T)(object)(Double)int64Source;
                    return(true);

                case TypeCode.Decimal:
                    result = (T)(object)(Decimal)int64Source;
                    return(true);
                }
                break;
            }

            case TypeCode.UInt64:
            {
                UInt64 uint64Source = (UInt64)source;
                switch (destinationTypeCode)
                {
                case TypeCode.Single:
                    result = (T)(object)(Single)uint64Source;
                    return(true);

                case TypeCode.Double:
                    result = (T)(object)(Double)uint64Source;
                    return(true);

                case TypeCode.Decimal:
                    result = (T)(object)(Decimal)uint64Source;
                    return(true);
                }
                break;
            }

            case TypeCode.Char:
            {
                Char charSource = (Char)source;
                switch (destinationTypeCode)
                {
                case TypeCode.UInt16:
                    result = (T)(object)(UInt16)charSource;
                    return(true);

                case TypeCode.Int32:
                    result = (T)(object)(Int32)charSource;
                    return(true);

                case TypeCode.UInt32:
                    result = (T)(object)(UInt32)charSource;
                    return(true);

                case TypeCode.Int64:
                    result = (T)(object)(Int64)charSource;
                    return(true);

                case TypeCode.UInt64:
                    result = (T)(object)(UInt64)charSource;
                    return(true);

                case TypeCode.Single:
                    result = (T)(object)(Single)charSource;
                    return(true);

                case TypeCode.Double:
                    result = (T)(object)(Double)charSource;
                    return(true);

                case TypeCode.Decimal:
                    result = (T)(object)(Decimal)charSource;
                    return(true);
                }
                break;
            }

            case TypeCode.Single:
            {
                if (destinationTypeCode == TypeCode.Double)
                {
                    result = (T)(object)(Double)(Single)source;
                    return(true);
                }
                break;
            }
            }

            result = default(T);
            return(false);
        }
示例#6
0
 public FatalException(string message, Exception innerException) : base(message, innerException)
 {
     // This can't throw something like ArgumentException because that would be worse than
     // throwing the fatal exception that was requested.
     Fx.Assert(innerException == null || !Fx.IsFatal(innerException), "FatalException can't be used to wrap fatal exceptions.");
 }