From 497f51f040d2e94b3c41163be567aeee036cfe80 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?David=20Srbeck=C3=BD?= Date: Mon, 26 Jul 2010 15:39:08 +0000 Subject: [PATCH] Crash earlier when type is not found by name git-svn-id: svn://svn.sharpdevelop.net/sharpdevelop/trunk@6250 1ccf3a8d-04fe-1044-b7c0-cef0b8235c61 --- .../Debugger.Core/MetaData/DebugType.cs | 30 ++++++++++++------- .../Ast/ExpressionExtensionMethods.cs | 4 +-- 2 files changed, 22 insertions(+), 12 deletions(-) diff --git a/src/AddIns/Debugger/Debugger.Core/MetaData/DebugType.cs b/src/AddIns/Debugger/Debugger.Core/MetaData/DebugType.cs index 4ceb864d7c..42e5a28e71 100644 --- a/src/AddIns/Debugger/Debugger.Core/MetaData/DebugType.cs +++ b/src/AddIns/Debugger/Debugger.Core/MetaData/DebugType.cs @@ -867,10 +867,7 @@ namespace Debugger.MetaData if (type.DeclaringType != null) declaringType = CreateFromType(module, type.DeclaringType); - DebugType result = CreateFromName(module, type.FullName, declaringType); - if (result == null) - throw new DebuggerException("Type not found: " + type); - return result; + return CreateFromName(module, type.FullName, declaringType); } public static DebugType CreateFromType(AppDomain appDomain, System.Type type, params DebugType[] genericArgumentsOverride) @@ -897,19 +894,24 @@ namespace Debugger.MetaData declaringType = null; } - DebugType result = CreateFromName(appDomain, name, declaringType, genericArgumentsOverride); - if (result == null) - throw new DebuggerException("Type not found: " + type); - return result; + return CreateFromName(appDomain, name, declaringType, genericArgumentsOverride); } public static DebugType CreateFromName(AppDomain appDomain, string name, DebugType declaringType, params DebugType[] genericArguments) + { + DebugType type = CreateFromNameOrNull(appDomain, name, declaringType, genericArguments); + if (type == null) + throw new DebuggerException("Type not found: " + name + (declaringType != null ? " (declaring type = " + declaringType.FullName + ")" : string.Empty)); + return type; + } + + public static DebugType CreateFromNameOrNull(AppDomain appDomain, string name, DebugType declaringType, params DebugType[] genericArguments) { if (declaringType != null) - return CreateFromName(declaringType.DebugModule, name, declaringType, genericArguments); + return CreateFromNameOrNull(declaringType.DebugModule, name, declaringType, genericArguments); foreach(Module module in appDomain.Process.Modules) { if (module.AppDomain != appDomain) continue; - DebugType result = CreateFromName(module, name, declaringType, genericArguments); + DebugType result = CreateFromNameOrNull(module, name, declaringType, genericArguments); if (result != null) return result; } @@ -917,6 +919,14 @@ namespace Debugger.MetaData } public static DebugType CreateFromName(Module module, string name, DebugType declaringType, params DebugType[] genericArguments) + { + DebugType type = CreateFromNameOrNull(module, name, declaringType, genericArguments); + if (type == null) + throw new DebuggerException("Type not found: " + name + (declaringType != null ? " (declaring type = " + declaringType.FullName + ")" : string.Empty)); + return type; + } + + public static DebugType CreateFromNameOrNull(Module module, string name, DebugType declaringType, params DebugType[] genericArguments) { if (declaringType != null && declaringType.DebugModule != module) throw new DebuggerException("Declaring type must be in the same module"); diff --git a/src/AddIns/Debugger/Debugger.Core/NRefactory/Ast/ExpressionExtensionMethods.cs b/src/AddIns/Debugger/Debugger.Core/NRefactory/Ast/ExpressionExtensionMethods.cs index 9eb13c5cd1..2e6a03dcf3 100644 --- a/src/AddIns/Debugger/Debugger.Core/NRefactory/Ast/ExpressionExtensionMethods.cs +++ b/src/AddIns/Debugger/Debugger.Core/NRefactory/Ast/ExpressionExtensionMethods.cs @@ -307,7 +307,7 @@ namespace ICSharpCode.NRefactory.Ast // If there are generic types up in the tree, it must be nested type if (genArgs.Length == typeRef.GenericTypes.Count) { string name = GetNameWithArgCounts(typeRef); - type = DebugType.CreateFromName(appDomain, name, null, genArgs); + type = DebugType.CreateFromNameOrNull(appDomain, name, null, genArgs); } // Try to construct nested type @@ -318,7 +318,7 @@ namespace ICSharpCode.NRefactory.Ast DebugType outter = ResolveTypeInternal(((InnerClassTypeReference)typeRef).BaseType, outterGenArgs, appDomain); string nestedName = typeRef.GenericTypes.Count == 0 ? typeRef.Type : typeRef.Type + "`" + typeRef.GenericTypes.Count; - type = DebugType.CreateFromName(appDomain, nestedName, outter, genArgs); + type = DebugType.CreateFromNameOrNull(appDomain, nestedName, outter, genArgs); } if (type == null)