Browse Source

Default .NET assemblies are now loaded with Reflection instead of Cecil.

git-svn-id: svn://svn.sharpdevelop.net/sharpdevelop/trunk@2008 1ccf3a8d-04fe-1044-b7c0-cef0b8235c61
shortcuts
Daniel Grunwald 19 years ago
parent
commit
151ed555c2
  1. 11
      src/Main/Core/Project/Src/Services/PropertyService/Properties.cs
  2. 38
      src/Main/ICSharpCode.SharpDevelop.Dom/Project/Src/ProjectContent/ProjectContentRegistry.cs
  3. 2
      src/Main/ICSharpCode.SharpDevelop.Dom/Project/Src/ReflectionLayer/ReflectionLoader.cs

11
src/Main/Core/Project/Src/Services/PropertyService/Properties.cs

@ -269,7 +269,7 @@ namespace ICSharpCode.Core @@ -269,7 +269,7 @@ namespace ICSharpCode.Core
TypeConverter c = TypeDescriptor.GetConverter(typeof(T));
try {
o = c.ConvertFromInvariantString(o.ToString());
} catch (NotSupportedException ex) {
} catch (Exception ex) {
MessageService.ShowWarning("Error loading property '" + property + "': " + ex.Message);
o = defaultValue;
}
@ -279,16 +279,25 @@ namespace ICSharpCode.Core @@ -279,16 +279,25 @@ namespace ICSharpCode.Core
Type elementType = typeof(T).GetElementType();
Array arr = System.Array.CreateInstance(elementType, list.Count);
TypeConverter c = TypeDescriptor.GetConverter(elementType);
try {
for (int i = 0; i < arr.Length; ++i) {
if (list[i] != null) {
arr.SetValue(c.ConvertFromInvariantString(list[i].ToString()), i);
}
}
o = arr;
} catch (Exception ex) {
MessageService.ShowWarning("Error loading property '" + property + "': " + ex.Message);
o = defaultValue;
}
properties[property] = o; // store for future look up
} else if (!(o is string) && typeof(T) == typeof(string)) {
TypeConverter c = TypeDescriptor.GetConverter(typeof(T));
if (c.CanConvertTo(typeof(string))) {
o = c.ConvertToInvariantString(o);
} else {
o = o.ToString();
}
}
try {
return (T)o;

38
src/Main/ICSharpCode.SharpDevelop.Dom/Project/Src/ProjectContent/ProjectContentRegistry.cs

@ -150,13 +150,14 @@ namespace ICSharpCode.SharpDevelop.Dom @@ -150,13 +150,14 @@ namespace ICSharpCode.SharpDevelop.Dom
}
}
if (mscorlibContent == null) {
// TODO: switch back to reflection for mscorlib
// We're using Cecil now for everything to find bugs in CecilReader faster
mscorlibContent = CecilReader.LoadAssembly(MscorlibAssembly.Location, this);
//mscorlibContent = new ReflectionProjectContent(MscorlibAssembly);
//mscorlibContent = CecilReader.LoadAssembly(MscorlibAssembly.Location, this);
// After SD 2.1 Beta 2, we're back to Reflection
mscorlibContent = new ReflectionProjectContent(MscorlibAssembly, this);
if (time != 0) {
LoggingService.Debug("Loaded mscorlib with Cecil in " + (Environment.TickCount - time) + " ms");
//LoggingService.Debug("Loaded mscorlib with Reflection in " + (Environment.TickCount - time) + " ms");
//LoggingService.Debug("Loaded mscorlib with Cecil in " + (Environment.TickCount - time) + " ms");
LoggingService.Debug("Loaded mscorlib with Reflection in " + (Environment.TickCount - time) + " ms");
}
if (persistence != null) {
persistence.SaveProjectContent(mscorlibContent);
@ -308,22 +309,33 @@ namespace ICSharpCode.SharpDevelop.Dom @@ -308,22 +309,33 @@ namespace ICSharpCode.SharpDevelop.Dom
static Assembly GetDefaultAssembly(string shortName)
{
return null; // TODO: remove this line when CecilReader was tested enough and we can use Reflection again for the BCL
// These assemblies are already loaded by SharpDevelop, so we don't need to load
// them in a separate AppDomain.
// These assemblies are already loaded by SharpDevelop, so we
// don't need to load them in a separate AppDomain/with Cecil.
switch (shortName) {
case "System": // System != mscorlib !!!
return SystemAssembly;
case "System.Xml":
case "System.XML":
return typeof(XmlReader).Assembly;
case "System.Data":
case "System.Design":
case "System.Drawing":
case "System.Web.Services":
case "System.Windows.Forms":
return Assembly.Load(shortName);
case "System.Xml":
case "System.XML":
return typeof(XmlReader).Assembly;
case "System.Web":
case "System.ServiceProcess":
case "System.Security":
case "System.Runtime.Remoting":
case "System.Messaging":
case "System.Management":
case "System.Drawing.Design":
case "System.Deployment":
case "System.Configuration":
case "Microsoft.VisualBasic":
// Is not necessarily loaded by Dom-using application, but
// is a default .NET assembly and should be loaded with
// Reflection.
return ReflectionLoader.ReflectionLoadGacAssembly(shortName, false);
default:
return null;
}

2
src/Main/ICSharpCode.SharpDevelop.Dom/Project/Src/ReflectionLayer/ReflectionLoader.cs

@ -18,7 +18,7 @@ namespace ICSharpCode.SharpDevelop.Dom @@ -18,7 +18,7 @@ namespace ICSharpCode.SharpDevelop.Dom
return "ReflectionLoader in " + AppDomain.CurrentDomain.FriendlyName;
}
public Assembly ReflectionLoadGacAssembly(string partialName, bool reflectionOnly)
public static Assembly ReflectionLoadGacAssembly(string partialName, bool reflectionOnly)
{
if (reflectionOnly) {
AssemblyName name = GacInterop.FindBestMatchingAssemblyName(partialName);

Loading…
Cancel
Save