Пример #1
0
        internal static void ParseParts(String fullName, out FrameworkIdentifiers framework, out Version version)
        {
            framework = FrameworkIdentifiers.Unsupported;
            version   = null;

            List <String> parts = fullName.Split(new Char[] { ',' }, StringSplitOptions.RemoveEmptyEntries).ToList();

            if (parts.TryTake(part => part.Trim().StartsWith("Version=v"), out String versionPart))
            {
                String tmp = versionPart.Trim().TrimStartOnce("Version=v");

                try {
                    version = new Version(tmp);
                } catch { /* Don't worry about exceptions here */ }
            }

            Predicate <String> match = part => {
                try {
                    Enum.Parse(typeof(FrameworkIdentifiers), part.Trim().TrimStartOnce('.'), true);
                    return(true);
                } catch { return(false); }
            };

            if (parts.TryTake(match, out String frameworkPart))
            {
                framework = (FrameworkIdentifiers)Enum.Parse(typeof(FrameworkIdentifiers), frameworkPart.Trim().TrimStartOnce('.'), true);
            }
        }
Пример #2
0
        internal static Boolean SplitTFM(String tfm, out FrameworkIdentifiers identifier, out Version version)
        {
            identifier = FrameworkIdentifiers.Unsupported;
            version    = null;

            if (!String.IsNullOrWhiteSpace(tfm))
            {
                String _tfm        = tfm.Trim().ToLower();
                String _identifier = String.Concat(_tfm.TakeWhile(Char.IsLetter));
                String _version    = _tfm.Substring(_identifier.Length);

                identifier = _identifier switch {
                    "netstandard" => FrameworkIdentifiers.NETStandard,
                    "netcoreapp" => FrameworkIdentifiers.NETCoreApp,
                    "net" => _version.Contains('.') ? FrameworkIdentifiers.NETCoreApp : FrameworkIdentifiers.NETFramework,
                    _ => FrameworkIdentifiers.Unsupported,
                };

                if (identifier != FrameworkIdentifiers.Unsupported && _version.All(c => Char.IsDigit(c) || c == '.'))
                {
                    if (!Version.TryParse(_version, out version))
                    {
                        version = new Version(String.Join(".", _version.Select(c => c.ToString())));
                    }
                }
            }

            return(Enum.IsDefined(typeof(FrameworkIdentifiers), identifier) && version != null);
        }
Пример #3
0
        /// <summary>
        /// Appends <paramref name="data"/> to the <see cref="Payload"/> <see cref="MemoryStream"/>.
        /// </summary>
        /// <param name="data">The data object.</param>
        /// <returns>The current <see cref="IMessage"/>.</returns>
        public IMessage Append(FrameworkIdentifiers data)
        {
            using (BinaryWriter bw = new BinaryWriter(Payload, Encoding.Default, true)) {
                bw.Write((Int32)data);
            }

            return(this);
        }
Пример #4
0
        /// <summary>
        /// Creates a new instance of <see cref="RuntimeInfo"/>.
        /// </summary>
        /// <param name="framework">The targeted framework.</param>
        /// <param name="version">The framework version.</param>
        public RuntimeInfo(FrameworkIdentifiers framework, Version version)
        {
            Throw.IfNot.Enum.IsDefined <FrameworkIdentifiers>(framework, nameof(framework));
            Throw.If.Object.IsNull(version, nameof(version));

            Framework = framework;
            Version   = version;
        }
Пример #5
0
        void Compare(FrameworkIdentifiers input1, FrameworkIdentifiers input2, Int32 expected)
        {
            IComparer <FrameworkIdentifiers> comparer = new FrameworkIdentifiersComparer();
            Int32 result = default;

            Test.IfNot.Action.ThrowsException(() => result = comparer.Compare(input1, input2), out Exception ex);

            Test.If.Value.IsEqual(result, expected);
        }
        void Constructor(FrameworkIdentifiers input1, Version input2, FrameworkIdentifiers framework, Version version)
        {
            RuntimeInfo info = null;

            Test.IfNot.Action.ThrowsException(() => info = new RuntimeInfo(input1, input2), out Exception ex);

            Test.If.Value.IsEqual(info.Framework, framework);
            Test.If.Value.IsEqual(info.Version, version);
        }