NuGet.VersionUtility.ValidatePortableFrameworkProfilePart C# (CSharp) Method

ValidatePortableFrameworkProfilePart() static private method

static private ValidatePortableFrameworkProfilePart ( string profilePart ) : bool
profilePart string
return bool
        internal static bool ValidatePortableFrameworkProfilePart(string profilePart)
        {
            if (String.IsNullOrEmpty(profilePart))
            {
                return false;
            }

            if (profilePart.Contains('-'))
            {
                return false;
            }

            if (profilePart.Contains(' '))
            {
                return false;
            }

            string[] parts = profilePart.Split('+');
            if (parts.Any(p => String.IsNullOrEmpty(p)))
            {
                return false;
            }

            // Prevent portable framework inside a portable framework - Inception
            if (parts.Any(p => p.StartsWith("portable", StringComparison.OrdinalIgnoreCase)) ||
                parts.Any(p => p.StartsWith("NETPortable", StringComparison.OrdinalIgnoreCase)) ||
                parts.Any(p => p.StartsWith(".NETPortable", StringComparison.OrdinalIgnoreCase)))
            {
                return false;
            }

            return true;
        }

Usage Example

示例#1
0
        /// <summary>
        /// Attempt to parse a profile string into an instance of <see cref="NetPortableProfile"/>.
        /// The profile string can be either ProfileXXX or sl4+net45+wp7
        /// </summary>
        public static NetPortableProfile Parse(string profileValue)
        {
            if (String.IsNullOrEmpty(profileValue))
            {
                throw new ArgumentNullException("profileValue");
            }

            // Previously, only the full "ProfileXXX" long .NET name could be used for this method.
            // This was inconsistent with the way the "custom profile string" (like "sl4+net45+wp7")
            // was supported in other places. By fixing the way the profile table indexes the cached
            // profiles, we can now indeed access by either naming, so we don't need the old check
            // for the string starting with "Profile".
            var result = NetPortableProfileTable.GetProfile(profileValue);

            if (result != null)
            {
                return(result);
            }

            if (profileValue.StartsWith("Profile", StringComparison.OrdinalIgnoreCase))
            {
                // This can happen if profileValue is an unrecognized profile, or
                // for some rare cases, the Portable Profile files are missing on disk.
                return(null);
            }

            VersionUtility.ValidatePortableFrameworkProfilePart(profileValue);

            var supportedFrameworks = profileValue.Split(new [] { '+' }, StringSplitOptions.RemoveEmptyEntries)
                                      .Select(VersionUtility.ParseFrameworkName);

            return(new NetPortableProfile(profileValue, supportedFrameworks));
        }
All Usage Examples Of NuGet.VersionUtility::ValidatePortableFrameworkProfilePart