/// <summary> /// Reads in the full string, parsing out the separate elements. These are not always in the specified order, /// and many times there are several optional elements. This class helps find the optional elements that are /// necessary. This does not support mulitple enclosed types yet, like dictionaries or something. We needed /// the single enclosed type for supporting the layer collection however. /// </summary> /// <param name="qualifiedName">The string qualified name.</param> public QualifiedTypeName(string qualifiedName) { if (qualifiedName.Contains("[[")) { // extract inner type: int start = qualifiedName.IndexOf("[["); int end = qualifiedName.IndexOf("]]"); string innerTypeText = qualifiedName.Substring(start + 2, end - (start + 2)); EnclosedName = new QualifiedTypeName(innerTypeText); qualifiedName = (qualifiedName.Substring(0, start + 2) + qualifiedName.Substring(end, qualifiedName.Length - end)); } string[] parts = qualifiedName.Split(','); TypeName = parts[0]; Assembly = parts[1].Trim(); for (int i = 2; i < parts.Length; i++) { string text = parts[i].Trim(); if (text.Substring(0, 8) == "Version=") { string version = text.Substring(8, text.Length - 8); Version = new Version(version); } if (text.Substring(0, 8) == "Culture=") { Culture = text.Substring(8, text.Length - 8); } if (text.Substring(0, 15) == "PublicKeyToken=") { string publicKeyToken = text.Substring(15, text.Length - 15); PublicKeyToken = publicKeyToken; } } }
/// <summary> /// Since the version, or even possibly the strong name may be dynamic, an older /// reference may need to be updated with local assembly information. /// </summary> /// <param name="invalidTypeName">The invalidated type name, usually because the version is out of date.</param> /// <returns>A string represnting the same type, but with a modern assmebly.</returns> public string UpdateTypename(string invalidTypeName) { QualifiedTypeName myType = new QualifiedTypeName(invalidTypeName); QualifiedTypeName type = myType; while (type != null) { UpdateVersion(type); type = type.EnclosedName; } return myType.ToString(); }
/// <summary> /// Since the version, or even possibly the strong name may be dynamic, an older /// reference may need to be updated with local assembly information. /// </summary> /// <param name="invalidTypeName">The invalidated type name, usually because the version is out of date.</param> /// <returns>A string representing the same type, but with a modern assembly.</returns> public string UpdateTypename(string invalidTypeName) { QualifiedTypeName myType = new QualifiedTypeName(invalidTypeName); QualifiedTypeName type = myType; while (type != null) { UpdateVersion(type); type = type.EnclosedName; } return(myType.ToString()); }
private void UpdateVersion(QualifiedTypeName myType) { if (!_loadedAssemblies.Keys.Contains(myType.Assembly)) { UpdateAssembly(myType.Assembly); } if (!_loadedAssemblies.Keys.Contains(myType.Assembly)) { // Don't throw an exception here, because we are just trying to update versions. // Since GAC and System libraries aren't discovered this way, we must // simply choose not to update those libraries and hope the reference // is not invalid because of a GAC or System library update. return; } AssemblyName myAssembly = _loadedAssemblies[myType.Assembly].GetName(); myType.Version = myAssembly.Version; string publicKeyToken = BitConverter.ToString(myAssembly.GetPublicKeyToken()); publicKeyToken = publicKeyToken.Replace("-", string.Empty).ToLower(); myType.PublicKeyToken = publicKeyToken; }