public static IClrTypeName GetExceptionType(this IThrowStatement throwStatement) { Contract.Requires(throwStatement != null); var declaredElement = throwStatement .With(x => x.Exception) .With(x => x as IObjectCreationExpression) .With(x => x.TypeReference) .With(x => x.Resolve()) .With(x => x.DeclaredElement) .With(x => x as IClrDeclaredElement); var clrName = declaredElement .With(x => x.GetContainingType()) .Return(x => x.GetClrName()); if (clrName != null) { return(clrName); } if (declaredElement == null) { return(null); } // Unfortunately in the following code GetContainingType always returns null // although this approach works perfectly for determining CallSiteType! // This is terrible hack, but I don't know how to solve this! // declaredElement.ToString() returns "Class:Fullname" so I'll remove first part! return(new ClrTypeName(declaredElement.ToString().Replace("Class:", ""))); }
public static IEnumerable <ICSharpArgument> GetArguments(this IThrowStatement throwStatement) { Contract.Requires(throwStatement != null); Contract.Ensures(Contract.Result <IEnumerable <ICSharpArgument> >() != null); return (throwStatement .With(x => x.Exception) .With(x => x as IObjectCreationExpression) .Return(x => x.Arguments, Enumerable.Empty <ICSharpArgument>())); }