コード例 #1
0
 private static bool IsStrongNamed(ParsedAssemblyName name)
 {
     return(name.PublicKeyToken != null && name.PublicKeyToken != "null");
 }
コード例 #2
0
 private static bool IsPartial(ParsedAssemblyName name, Version version)
 {
     return(version == null || name.Culture == null || name.PublicKeyToken == null);
 }
コード例 #3
0
        static string GetRemappedPublicKeyToken(ref ParsedAssemblyName name, Version version)
        {
            if (name.Retargetable.GetValueOrDefault() && version < SilverlightVersion)
            {
                return(null);
            }
            if (name.PublicKeyToken == "ddd0da4d3e678217" && name.Name == "System.ComponentModel.DataAnnotations" && name.Retargetable.GetValueOrDefault())
            {
                return(PublicKeyTokenWinFX);
            }
            if (SilverlightVersionMinimum <= version && version <= SilverlightVersionMaximum)
            {
                switch (name.PublicKeyToken)
                {
                case PublicKeyTokenSilverlight:
                    switch (name.Name)
                    {
                    case "System":
                    case "System.Core":
                        return(PublicKeyTokenEcma);
                    }
                    if (name.Retargetable.GetValueOrDefault())
                    {
                        switch (name.Name)
                        {
                        case "System.Runtime.Serialization":
                        case "System.Xml":
                            return(PublicKeyTokenEcma);

                        case "System.Net":
                        case "System.Windows":
                            return(PublicKeyTokenMicrosoft);

                        case "System.ServiceModel.Web":
                            return(PublicKeyTokenWinFX);
                        }
                    }
                    break;

                case PublicKeyTokenWinFX:
                    switch (name.Name)
                    {
                    case "System.ComponentModel.Composition":
                        return(PublicKeyTokenEcma);
                    }
                    if (name.Retargetable.GetValueOrDefault())
                    {
                        switch (name.Name)
                        {
                        case "Microsoft.CSharp":
                            return(PublicKeyTokenMicrosoft);

                        case "System.Numerics":
                        case "System.ServiceModel":
                        case "System.Xml.Serialization":
                        case "System.Xml.Linq":
                            return(PublicKeyTokenEcma);
                        }
                    }
                    break;
                }
            }
            return(null);
        }
コード例 #4
0
        internal static ParseAssemblyResult ParseAssemblyName(string fullName, out ParsedAssemblyName parsedName)
        {
            parsedName = new ParsedAssemblyName();
            int pos;
            ParseAssemblyResult res = ParseAssemblySimpleName(fullName, out pos, out parsedName.Name);

            if (res != ParseAssemblyResult.OK)
            {
                return(res);
            }
            else
            {
                const int ERROR_SXS_IDENTITIES_DIFFERENT = unchecked ((int)0x80073716);
                System.Collections.Generic.Dictionary <string, string> unknownAttributes = null;
                bool   hasProcessorArchitecture = false;
                bool   hasContentType           = false;
                bool   hasPublicKeyToken        = false;
                string publicKeyToken;
                while (pos != fullName.Length)
                {
                    string key   = null;
                    string value = null;
                    if (!TryParseAssemblyAttribute(fullName, ref pos, ref key, ref value))
                    {
                        return(ParseAssemblyResult.GenericError);
                    }
                    key = key.ToLowerInvariant();
                    switch (key)
                    {
                    case "version":
                        if (parsedName.Version != null)
                        {
                            return(ParseAssemblyResult.DuplicateKey);
                        }
                        parsedName.Version = value;
                        break;

                    case "culture":
                        if (parsedName.Culture != null)
                        {
                            return(ParseAssemblyResult.DuplicateKey);
                        }
                        if (!ParseCulture(value, out parsedName.Culture))
                        {
                            return(ParseAssemblyResult.GenericError);
                        }
                        break;

                    case "publickeytoken":
                        if (hasPublicKeyToken)
                        {
                            return(ParseAssemblyResult.DuplicateKey);
                        }
                        if (!ParsePublicKeyToken(value, out publicKeyToken))
                        {
                            return(ParseAssemblyResult.GenericError);
                        }
                        if (parsedName.HasPublicKey && parsedName.PublicKeyToken != publicKeyToken)
                        {
                            Marshal.ThrowExceptionForHR(ERROR_SXS_IDENTITIES_DIFFERENT);
                        }
                        parsedName.PublicKeyToken = publicKeyToken;
                        hasPublicKeyToken         = true;
                        break;

                    case "publickey":
                        if (parsedName.HasPublicKey)
                        {
                            return(ParseAssemblyResult.DuplicateKey);
                        }
                        if (!ParsePublicKey(value, out publicKeyToken))
                        {
                            return(ParseAssemblyResult.GenericError);
                        }
                        if (hasPublicKeyToken && parsedName.PublicKeyToken != publicKeyToken)
                        {
                            Marshal.ThrowExceptionForHR(ERROR_SXS_IDENTITIES_DIFFERENT);
                        }
                        parsedName.PublicKeyToken = publicKeyToken;
                        parsedName.HasPublicKey   = true;
                        break;

                    case "retargetable":
                        if (parsedName.Retargetable.HasValue)
                        {
                            return(ParseAssemblyResult.DuplicateKey);
                        }
                        switch (value.ToLowerInvariant())
                        {
                        case "yes":
                            parsedName.Retargetable = true;
                            break;

                        case "no":
                            parsedName.Retargetable = false;
                            break;

                        default:
                            return(ParseAssemblyResult.GenericError);
                        }
                        break;

                    case "processorarchitecture":
                        if (hasProcessorArchitecture)
                        {
                            return(ParseAssemblyResult.DuplicateKey);
                        }
                        hasProcessorArchitecture = true;
                        switch (value.ToLowerInvariant())
                        {
                        case "none":
                            parsedName.ProcessorArchitecture = ProcessorArchitecture.None;
                            break;

                        case "msil":
                            parsedName.ProcessorArchitecture = ProcessorArchitecture.MSIL;
                            break;

                        case "x86":
                            parsedName.ProcessorArchitecture = ProcessorArchitecture.X86;
                            break;

                        case "ia64":
                            parsedName.ProcessorArchitecture = ProcessorArchitecture.IA64;
                            break;

                        case "amd64":
                            parsedName.ProcessorArchitecture = ProcessorArchitecture.Amd64;
                            break;

                        case "arm":
                            parsedName.ProcessorArchitecture = ProcessorArchitecture.Arm;
                            break;

                        default:
                            return(ParseAssemblyResult.GenericError);
                        }
                        break;

                    case "contenttype":
                        if (hasContentType)
                        {
                            return(ParseAssemblyResult.DuplicateKey);
                        }
                        hasContentType = true;
                        if (!value.Equals("windowsruntime", StringComparison.OrdinalIgnoreCase))
                        {
                            return(ParseAssemblyResult.GenericError);
                        }
                        parsedName.WindowsRuntime = true;
                        break;

                    default:
                        if (key.Length == 0)
                        {
                            return(ParseAssemblyResult.GenericError);
                        }
                        if (unknownAttributes == null)
                        {
                            unknownAttributes = new System.Collections.Generic.Dictionary <string, string>();
                        }
                        if (unknownAttributes.ContainsKey(key))
                        {
                            return(ParseAssemblyResult.DuplicateKey);
                        }
                        unknownAttributes.Add(key, null);
                        break;
                    }
                }
                return(ParseAssemblyResult.OK);
            }
        }
コード例 #5
0
        static bool IsFrameworkAssembly(ParsedAssemblyName name)
        {
            // Framework assemblies use different unification rules, so when
            // a new framework is released the new assemblies need to be added.
            switch (name.Name)
            {
            case "System":
            case "System.Core":
            case "System.Data":
            case "System.Data.DataSetExtensions":
            case "System.Data.Linq":
            case "System.Data.OracleClient":
            case "System.Data.Services":
            case "System.Data.Services.Client":
            case "System.IdentityModel":
            case "System.IdentityModel.Selectors":
            case "System.IO.Compression":
            case "System.Numerics":
            case "System.Reflection.Context":
            case "System.Runtime.Remoting":
            case "System.Runtime.Serialization":
            case "System.Runtime.WindowsRuntime":
            case "System.Runtime.WindowsRuntime.UI.Xaml":
            case "System.ServiceModel":
            case "System.Transactions":
            case "System.Windows.Forms":
            case "System.Xml":
            case "System.Xml.Linq":
            case "System.Xml.Serialization":
                return(name.PublicKeyToken == PublicKeyTokenEcma);

            case "Microsoft.CSharp":
            case "Microsoft.VisualBasic":
            case "System.Collections":
            case "System.Collections.Concurrent":
            case "System.ComponentModel":
            case "System.ComponentModel.Annotations":
            case "System.ComponentModel.EventBasedAsync":
            case "System.Configuration":
            case "System.Configuration.Install":
            case "System.Design":
            case "System.Diagnostics.Contracts":
            case "System.Diagnostics.Debug":
            case "System.Diagnostics.Tools":
            case "System.Diagnostics.Tracing":
            case "System.DirectoryServices":
            case "System.Drawing":
            case "System.Drawing.Design":
            case "System.Dynamic.Runtime":
            case "System.EnterpriseServices":
            case "System.Globalization":
            case "System.IO":
            case "System.Linq":
            case "System.Linq.Expressions":
            case "System.Linq.Parallel":
            case "System.Linq.Queryable":
            case "System.Management":
            case "System.Messaging":
            case "System.Net":
            case "System.Net.Http":
            case "System.Net.Http.Rtc":
            case "System.Net.NetworkInformation":
            case "System.Net.Primitives":
            case "System.Net.Requests":
            case "System.ObjectModel":
            case "System.Reflection":
            case "System.Reflection.Extensions":
            case "System.Reflection.Primitives":
            case "System.Resources.ResourceManager":
            case "System.Runtime":
            case "System.Runtime.Extensions":
            case "System.Runtime.InteropServices":
            case "System.Runtime.InteropServices.WindowsRuntime":
            case "System.Runtime.Numerics":
            case "System.Runtime.Serialization.Formatters.Soap":
            case "System.Runtime.Serialization.Json":
            case "System.Runtime.Serialization.Primitives":
            case "System.Runtime.Serialization.Xml":
            case "System.Security":
            case "System.Security.Principal":
            case "System.ServiceModel.Duplex":
            case "System.ServiceModel.Http":
            case "System.ServiceModel.NetTcp":
            case "System.ServiceModel.Primitives":
            case "System.ServiceModel.Security":
            case "System.ServiceProcess":
            case "System.Text.Encoding":
            case "System.Text.Encoding.Extensions":
            case "System.Text.RegularExpressions":
            case "System.Threading":
            case "System.Threading.Tasks":
            case "System.Threading.Tasks.Parallel":
            case "System.Web":
            case "System.Web.Mobile":
            case "System.Web.Services":
            case "System.Windows":
            case "System.Xml.ReaderWriter":
            case "System.Xml.XDocument":
            case "System.Xml.XmlSerializer":
                return(name.PublicKeyToken == PublicKeyTokenMicrosoft);

            case "System.ComponentModel.DataAnnotations":
            case "System.ServiceModel.Web":
            case "System.Web.Abstractions":
            case "System.Web.Extensions":
            case "System.Web.Extensions.Design":
            case "System.Web.DynamicData":
            case "System.Web.Routing":
                return(name.PublicKeyToken == PublicKeyTokenWinFX);
            }

            return(false);
        }