private static object InvokeConstructor(Type targetType) { object result = null; bool flag = false; try { result = ((targetType == typeof(string)) ? string.Empty : Activator.CreateInstance(targetType)); } catch (MissingMethodException) { using (IEnumerator <ConstructorInfo> enumerator = targetType.GetTypeInfo().DeclaredConstructors.GetEnumerator()) { if (enumerator.MoveNext()) { ConstructorInfo constructorInfo = enumerator.Current; flag = true; ParameterInfo[] parameters = constructorInfo.GetParameters(); object[] array = new object[parameters.Length]; int num = 0; foreach (ParameterInfo parameterInfo in parameters) { array[num] = FaultInjectionTrace.InvokeConstructor(parameterInfo.ParameterType); num++; } result = constructorInfo.Invoke(array); } } if (!flag) { throw new InvalidOperationException("Type Specified Does Not Have Any Constructors : " + targetType.FullName); } } return(result); }
private static Exception GenericExceptionCallback(string exceptionTypeNameParams) { Exception ex = null; if (exceptionTypeNameParams != null) { Regex regex = new Regex("([A-Za-z.]+)(?:\\((?:(?:((?:[0-9]+)|(?:'[A-Za-z0-9,.?:;!@_ ]*')))[, ]*)+\\))*"); char[] trimChars = new char[] { '\'' }; string text = string.Empty; string[] array = new string[0]; if (regex.IsMatch(exceptionTypeNameParams)) { using (IEnumerator enumerator = regex.Matches(exceptionTypeNameParams).GetEnumerator()) { while (enumerator.MoveNext()) { object obj = enumerator.Current; Match match = (Match)obj; if (match.Groups.Count == 3) { text = match.Groups[1].Value; if (match.Groups[1].Captures.Count > 0) { array = new string[match.Groups[2].Captures.Count]; int num = 0; foreach (object obj2 in match.Groups[2].Captures) { Capture capture = (Capture)obj2; array[num] = capture.Value.Trim(trimChars); num++; } } } } goto IL_157; } goto IL_146; IL_157: Type targetType = FaultInjectionTrace.LookUpType(text); if (text == null) { throw new InvalidOperationException("No Type Exists In Current Calling Assembly Or Referenced Assemblies With The Name : " + exceptionTypeNameParams); } if (array.Length == 0) { ex = (FaultInjectionTrace.InvokeConstructor(targetType) as Exception); } else { ex = (FaultInjectionTrace.InvokeConstructorWithParams(targetType, array) as Exception); } if (ex == null) { throw new InvalidOperationException("Type Name Specified For The Exception Callback Is Not A Valid Exception Type : " + exceptionTypeNameParams); } return(ex); } IL_146: throw new InvalidOperationException("The exception string is not valid. ExceptionTypeNameParams: " + exceptionTypeNameParams); } return(ex); }