Example #1
0
        /// <summary>
        /// Raises the given <see cref="TaggedException"/>
        /// </summary>
        /// <typeparam name="T">The type related to the exception.</typeparam>
        /// <param name="exception">The <see cref="System.Exception"/> which occured.</param>
        /// <param name="breakForResume">Indicates if the function should attach the debugger.</param>
        public static void RaiseAndAttachIfUnhandled <T>(this TaggedException <T> exception, bool breakForResume = true)
        {
            //If not attaching then fall back to TryRaise which hides the exception and return.
            if (false.Equals(breakForResume))
            {
                exception.TryRaise();

                return;
            }

            //Raise the exception
            try { exception.Raise(); }
            catch //Handle it
            {
                //If the debugger is not attached and it cannot be then return
                if (false.Equals(DebugExtensions.Attach()))
                {
                    return;
                }

                //Break if still attached
                DebugExtensions.BreakIfAttached();
            }
        }
Example #2
0
        /// <summary>
        /// Finds all types in all loaded assemblies which are a subclass of RtcpPacket and adds those types to either the InstanceMap or the AbstractionBag
        /// </summary>
        internal protected static void MapDerivedImplementations(AppDomain domain = null, bool breakOnError = false)
        {
            System.Type[] Types;

            //Get all loaded assemblies in the current application domain
            foreach (System.Reflection.Assembly assembly in (domain ?? AppDomain.CurrentDomain).GetAssemblies())
            {
                try { Types = assembly.GetTypes(); }
                catch { if (breakOnError)
                        {
                            DebugExtensions.BreakIfAttached();
                        }
                        continue; }

                //Iterate each derived type which is a SubClassOf RtcpPacket.
                foreach (System.Type derivedType in Types.Where(t => t.IsSubclassOf(RtcpPacketType)))
                {
                    //If the derivedType is an abstraction then add to the AbstractionBag and continue
                    if (derivedType.IsAbstract)
                    {
                        Abstractions.Add(derivedType);

                        continue;
                    }

                    //Get the TypeInfo
                    System.Reflection.TypeInfo typeInfo = System.Reflection.IntrospectionExtensions.GetTypeInfo(derivedType);

                    //Enumerate the fields of the typeInfo
                    foreach (System.Reflection.FieldInfo field in typeInfo.DeclaredFields)
                    {
                        //Obtain the field mapped to the derviedType which corresponds to the PayloadTypeField defined by the RtcpPacket implementation.
                        switch (field.Name)
                        {
                        default: continue;

                        case PayloadTypeField:
                        {
                            //Unbox the payloadType from an integer to a byte via reflection
                            byte payloadType = (byte)((int)field.GetValue(derivedType));

                            //if the mapping was not successful and the debbuger is attached break.
                            if (false == TryMapImplementation(payloadType, derivedType) && System.Diagnostics.Debugger.IsAttached)
                            {
                                //Another type was already mapped to the given payloadTypeField
                                System.Diagnostics.Debugger.Break();
                            }

                            //Finished
                            goto Continue;
                        }
                        }
                    }

                    Continue:
                    continue;
                }
            }

            Types = null;
        }