示例#1
0
 public AssemblyName(AssemblyNameResolution resolution, string name, int majorVersion, int minorVersion, int buildNumber, int revisionNumber, string culture, byte[] publicKeyToken, AssemblyName redirectFrom)
 {
     Name = name;
     if (resolution == AssemblyNameResolution.NameVersion || resolution == AssemblyNameResolution.Full)
     {
         MajorVersion   = majorVersion;
         MinorVersion   = minorVersion;
         BuildNumber    = buildNumber;
         RevisionNumber = revisionNumber;
     }
     if (resolution == AssemblyNameResolution.Full)
     {
         if (culture != null)
         {
             culture = culture.ToLower();
             if (culture.Equals(defaultCulture, StringComparison.Ordinal))
             {
                 culture = null;
             }
             Culture = culture;
         }
     }
     if (resolution == AssemblyNameResolution.Full)
     {
         if (publicKeyToken != null && publicKeyToken.Length != 0)
         {
             if (publicKeyToken.Length > 8)
             {
                 var sha1 = new System.Security.Cryptography.SHA1CryptoServiceProvider();
                 var hash = sha1.ComputeHash(publicKeyToken);
                 publicKeyToken = new byte[8];
                 for (var i = 0; i < 8; i++)
                 {
                     publicKeyToken[i] = hash[hash.Length - 1 - i];
                 }
             }
             PublicKeyToken = publicKeyToken;
         }
     }
     RedirectFrom = redirectFrom != null && redirectFrom.RedirectFrom != null
                        ? redirectFrom.RedirectFrom
                        : redirectFrom;
 }
示例#2
0
 public AssemblyName(AssemblyNameResolution resolution, AssemblyName redirectFrom)
     : this(resolution, null, 0, 0, 0, 0, null, null, redirectFrom)
 {
 }
示例#3
0
 public AssemblyName(AssemblyNameResolution resolution, string name, int majorVersion, int minorVersion, int buildNumber, int revisionNumber, string culture, byte[] publicKeyToken) :
     this(resolution, name, majorVersion, minorVersion, buildNumber, revisionNumber, culture, publicKeyToken, null)
 {
 }
示例#4
0
        public static AssemblyName FromReflectionName(AssemblyNameResolution resolution, string strongName)
        {
            if (string.IsNullOrEmpty(strongName))
            {
                return(null);
            }
            var name           = default(string);
            var majorVersion   = 0;
            var minorVersion   = 0;
            var buildNumber    = 0;
            var revisionNumber = 0;
            var culture        = default(string);
            var publicKeyToken = default(byte[]);
            var i = strongName.IndexOf(',');

            if (i < 0)
            {
                name = strongName;
            }
            else
            {
                name = strongName.Substring(0, i);
                i++;
                SkipWS(strongName, ref i);
                while (i < strongName.Length)
                {
                    var kwd = GetKeyword(strongName, ref i);
                    if (string.Equals(kwd, versionKeyword, StringComparison.OrdinalIgnoreCase))
                    {
                        var version = GetValue(strongName, ref i);
                        if (version == null)
                        {
                            return(null);
                        }
                        var j = 0;
                        majorVersion = GetNum(version, ref j);
                        if (majorVersion < 0)
                        {
                            return(null);
                        }
                        if (!SkipDot(version, ref j))
                        {
                            return(null);
                        }
                        minorVersion = GetNum(version, ref j);
                        if (minorVersion < 0)
                        {
                            return(null);
                        }
                        if (!SkipDot(version, ref j))
                        {
                            return(null);
                        }
                        buildNumber = GetNum(version, ref j);
                        if (buildNumber < 0)
                        {
                            return(null);
                        }
                        if (!SkipDot(version, ref j))
                        {
                            return(null);
                        }
                        revisionNumber = GetNum(version, ref j);
                        if (revisionNumber < 0)
                        {
                            return(null);
                        }
                    }
                    else if (string.Equals(kwd, cultureKeyword, StringComparison.OrdinalIgnoreCase))
                    {
                        culture = GetValue(strongName, ref i);
                        if (culture == null)
                        {
                            return(null);
                        }
                    }
                    else if (string.Equals(kwd, publicKeyTokenKeyword, StringComparison.OrdinalIgnoreCase))
                    {
                        var hex = GetValue(strongName, ref i);
                        if (hex == null)
                        {
                            return(null);
                        }
                        if (!hex.Equals(defaultPublicKeyToken, StringComparison.OrdinalIgnoreCase))
                        {
                            if (hex.Length % 2 != 0)
                            {
                                return(null);
                            }
                            var j = 0;
                            publicKeyToken = new byte[hex.Length / 2];
                            for (var k = 0; k < publicKeyToken.Length; k++)
                            {
                                var v = GetByte(hex, ref j);
                                if (v < 0)
                                {
                                    return(null);
                                }
                                publicKeyToken[k] = (byte)v;
                            }
                        }
                    }
                    else
                    {
                        return(null);
                    }
                }
            }
            return(new AssemblyName(resolution, name, majorVersion, minorVersion, buildNumber, revisionNumber, culture, publicKeyToken));
        }
示例#5
0
 public AssemblyName(AssemblyNameResolution resolution, AssemblyName name, AssemblyName redirectFrom)
     : this(resolution, name.Name, name.MajorVersion, name.MinorVersion, name.BuildNumber, name.RevisionNumber, name.Culture, name.PublicKeyToken, redirectFrom)
 {
 }