Browse Source

Replaced LoadWithPartialName through Assembly.Load, it seems to do the same job in .NET 2.0.

Optimized the StringParser a bit.

git-svn-id: svn://svn.sharpdevelop.net/sharpdevelop/trunk@110 1ccf3a8d-04fe-1044-b7c0-cef0b8235c61
shortcuts
Daniel Grunwald 21 years ago
parent
commit
f17c72e038
  1. 2
      src/AddIns/Misc/HighlightingEditor/Project/Src/Nodes/EnvironmentNode.cs
  2. 2
      src/Main/Base/Project/Src/Gui/Pads/ClassBrowser/Nodes/ReferenceFolderNode.cs
  3. 2
      src/Main/Base/Project/Src/Project/Items/ReferenceProjectItem.cs
  4. 2
      src/Main/Base/Project/Src/Services/ParserService/ProjectContentRegistry.cs
  5. 126
      src/Main/Core/Project/Src/Services/StringParser/StringParser.cs

2
src/AddIns/Misc/HighlightingEditor/Project/Src/Nodes/EnvironmentNode.cs

@ -43,7 +43,7 @@ namespace ICSharpCode.SharpDevelop.AddIns.HighlightingEditor.Nodes
EnvironmentNode.ColorNames = (string[])envColorNames.ToArray(typeof(string)); EnvironmentNode.ColorNames = (string[])envColorNames.ToArray(typeof(string));
this.ColorDescs = (string[])envColorDescriptions.ToArray(typeof(string)); this.ColorDescs = (string[])envColorDescriptions.ToArray(typeof(string));
this.Colors = (EditorHighlightColor[])envColors.ToArray(typeof(EditorHighlightColor)); this.Colors = (EditorHighlightColor[])envColors.ToArray(typeof(EditorHighlightColor));
StringParser.Parse(ref ColorDescs); StringParser.Parse(ColorDescs);
Text = ResNodeName("EnvironmentColors"); Text = ResNodeName("EnvironmentColors");

2
src/Main/Base/Project/Src/Gui/Pads/ClassBrowser/Nodes/ReferenceFolderNode.cs

@ -88,7 +88,7 @@ namespace ICSharpCode.SharpDevelop.Gui
assembly = Assembly.ReflectionOnlyLoadFrom(item.FileName); assembly = Assembly.ReflectionOnlyLoadFrom(item.FileName);
} catch (Exception) { } catch (Exception) {
try { try {
assembly = Assembly.LoadWithPartialName(item.Include); assembly = Assembly.ReflectionOnlyLoad(item.Include);
} catch (Exception e) { } catch (Exception e) {
Console.WriteLine("Can't load assembly '{0}' : " + e.Message, item.Include); Console.WriteLine("Can't load assembly '{0}' : " + e.Message, item.Include);
} }

2
src/Main/Base/Project/Src/Project/Items/ReferenceProjectItem.cs

@ -99,7 +99,7 @@ namespace ICSharpCode.SharpDevelop.Project
if (info.Length < 4) { if (info.Length < 4) {
try { try {
Assembly refAssembly = Assembly.LoadWithPartialName(referenceName); Assembly refAssembly = Assembly.Load(referenceName);
// if it failed, then return just the short name // if it failed, then return just the short name
if (refAssembly == null) { if (refAssembly == null) {

2
src/Main/Base/Project/Src/Services/ParserService/ProjectContentRegistry.cs

@ -57,7 +57,7 @@ namespace ICSharpCode.Core
} }
} catch (Exception) { } catch (Exception) {
try { try {
assembly = Assembly.LoadWithPartialName(item.Include); assembly = Assembly.ReflectionOnlyLoad(item.Include);
if (assembly != null) { if (assembly != null) {
contents[item.Include] = CaseSensitiveProjectContent.Create(assembly); contents[item.Include] = CaseSensitiveProjectContent.Create(assembly);
return contents[item.Include]; return contents[item.Include];

126
src/Main/Core/Project/Src/Services/StringParser/StringParser.cs

@ -24,9 +24,9 @@ namespace ICSharpCode.Core
/// </summary> /// </summary>
public static class StringParser public static class StringParser
{ {
static Dictionary<string, string> properties = new Dictionary<string, string>(); readonly static Dictionary<string, string> properties;
static Dictionary<string, IStringTagProvider> stringTagProviders = new Dictionary<string, IStringTagProvider>(); readonly static Dictionary<string, IStringTagProvider> stringTagProviders;
static Dictionary<string, object> propertyObjects = new Dictionary<string, object>(); readonly static Dictionary<string, object> propertyObjects;
public static Dictionary<string, string> Properties { public static Dictionary<string, string> Properties {
get { get {
@ -42,13 +42,16 @@ namespace ICSharpCode.Core
static StringParser() static StringParser()
{ {
Assembly entryAssembly = System.Reflection.Assembly.GetEntryAssembly(); Assembly entryAssembly = Assembly.GetEntryAssembly();
properties = new Dictionary<string, string>(StringComparer.InvariantCultureIgnoreCase);
stringTagProviders = new Dictionary<string, IStringTagProvider>(StringComparer.InvariantCultureIgnoreCase);
propertyObjects = new Dictionary<string, object>();
// entryAssembly == null might happen in unit test mode // entryAssembly == null might happen in unit test mode
if (entryAssembly != null) { if (entryAssembly != null) {
string exeName = entryAssembly.Location; string exeName = entryAssembly.Location;
propertyObjects["exe"] = FileVersionInfo.GetVersionInfo(exeName); propertyObjects["exe"] = FileVersionInfo.GetVersionInfo(exeName);
} }
properties["USER"] = Environment.UserName;
} }
public static string Parse(string input) public static string Parse(string input)
@ -57,11 +60,11 @@ namespace ICSharpCode.Core
} }
/// <summary> /// <summary>
/// Parses an array and replaces the elements /// Parses an array and replaces the elements in the existing array.
/// </summary> /// </summary>
public static void Parse(ref string[] inputs) public static void Parse(string[] inputs)
{ {
for (int i = inputs.GetLowerBound(0); i <= inputs.GetUpperBound(0); ++i) { for (int i = 0; i < inputs.Length; ++i) {
inputs[i] = Parse(inputs[i], null); inputs[i] = Parse(inputs[i], null);
} }
} }
@ -73,7 +76,7 @@ namespace ICSharpCode.Core
} }
} }
readonly static Regex pattern = new Regex(@"\$\{([^\}]*)\}"); readonly static Regex pattern = new Regex(@"\$\{([^\}]*)\}", RegexOptions.Compiled | RegexOptions.CultureInvariant);
/// <summary> /// <summary>
/// Expands ${xyz} style property values. /// Expands ${xyz} style property values.
@ -87,84 +90,79 @@ namespace ICSharpCode.Core
string token = m.ToString(); string token = m.ToString();
string propertyName = m.Groups[1].Captures[0].Value; string propertyName = m.Groups[1].Captures[0].Value;
string propertyNameUpper= propertyName.ToUpper(); string propertyValue = GetValue(propertyName, customTags);
string propertyValue = null;
switch (propertyName.ToUpper()) { if (propertyValue != null) {
case "USER": // current user if (m.Length == input.Length) {
propertyValue = Environment.UserName; // safe a replace operation when input is a property on its own.
break; return propertyValue;
case "DATE": // current date }
propertyValue = DateTime.Today.ToShortDateString(); output = output.Replace(token, propertyValue);
break; }
case "TIME": // current time }
propertyValue = DateTime.Now.ToShortTimeString(); }
break; }
default: return output;
propertyValue = null; }
static string GetValue(string propertyName, string[,] customTags)
{
if (propertyName.StartsWith("res:")) {
// most properties start with res: in lowercase,
// so we can safe 2 string allocations here
try {
return Parse(ResourceService.GetString(propertyName.Substring(4)), customTags);
} catch (ResourceNotFoundException) {
return null;
}
}
if (propertyName.Equals("DATE", StringComparison.InvariantCultureIgnoreCase))
return DateTime.Today.ToShortDateString();
if (propertyName.Equals("TIME", StringComparison.InvariantCultureIgnoreCase))
return DateTime.Now.ToShortTimeString();
if (customTags != null) { if (customTags != null) {
for (int j = 0; j < customTags.GetLength(0); ++j) { for (int j = 0; j < customTags.GetLength(0); ++j) {
if (propertyName.ToUpper() == customTags[j, 0].ToUpper()) { if (propertyName.Equals(customTags[j, 0], StringComparison.InvariantCultureIgnoreCase)) {
propertyValue = customTags[j, 1]; return customTags[j, 1];
break;
} }
} }
} }
if (propertyValue == null && properties.ContainsKey(propertyName)) { if (properties.ContainsKey(propertyName)) {
propertyValue = properties[propertyName]; return properties[propertyName];
} }
if (propertyValue == null && properties.ContainsKey(propertyNameUpper)) { if (stringTagProviders.ContainsKey(propertyName)) {
propertyValue = properties[propertyNameUpper]; return stringTagProviders[propertyName].Convert(propertyName);
}
if (propertyValue == null && stringTagProviders.ContainsKey(propertyName)) {
propertyValue = stringTagProviders[propertyName].Convert(propertyName);
} }
if (propertyValue == null) {
int k = propertyName.IndexOf(':'); int k = propertyName.IndexOf(':');
if (k > 0) { if (k <= 0)
switch (propertyName.Substring(0, k).ToUpper()) { return null;
string prefix = propertyName.Substring(0, k);
switch (prefix.ToUpper()) {
case "ENV": case "ENV":
propertyValue = Environment.GetEnvironmentVariable(propertyName.Substring(k + 1)); return Environment.GetEnvironmentVariable(propertyName.Substring(k + 1));
break;
case "RES": case "RES":
try { try {
propertyValue = Parse(ResourceService.GetString(propertyName.Substring(k + 1)), customTags); return Parse(ResourceService.GetString(propertyName.Substring(k + 1)), customTags);
} catch (Exception) { } catch (ResourceNotFoundException) {
propertyValue = null; return null;
} }
break;
case "PROPERTY": case "PROPERTY":
propertyValue = PropertyService.Get(propertyName.Substring(k + 1)); return PropertyService.Get(propertyName.Substring(k + 1));
break;
default: default:
object obj = propertyObjects[propertyName.Substring(0, k)]; if (propertyObjects.ContainsKey(prefix)) {
propertyValue = Get(obj, propertyName.Substring(k + 1)); return Get(propertyObjects[prefix], propertyName.Substring(k + 1));
break; } else {
} return null;
}
}
break;
}
if (propertyValue != null) {
output = output.Replace(token, propertyValue);
}
}
} }
} }
return output;
} }
static string Get(object obj, string name) static string Get(object obj, string name)
{ {
if (obj == null) {
return null;
}
Type type = obj.GetType(); Type type = obj.GetType();
PropertyInfo prop = type.GetProperty(name); PropertyInfo prop = type.GetProperty(name);
if (prop != null) { if (prop != null) {

Loading…
Cancel
Save