/// <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)); }
public static NetPortableProfile Parse(string profileValue, bool treatOptionalFrameworksAsSupportedFrameworks = false, NetPortableProfileTable portableProfileTable = null) { portableProfileTable = portableProfileTable ?? NetPortableProfileTable.Default; if (string.IsNullOrEmpty(profileValue)) { throw new ArgumentException(CommonResources.Argument_Cannot_Be_Null_Or_Empty, "profileValue"); } NetPortableProfile profile = portableProfileTable.GetProfile(profileValue); if (profile != null) { if (treatOptionalFrameworksAsSupportedFrameworks) { profile = new NetPortableProfile(profile.Name, profile.SupportedFrameworks.Concat <FrameworkName>(profile.OptionalFrameworks), null); } return(profile); } if (profileValue.StartsWith("Profile", StringComparison.OrdinalIgnoreCase)) { return(null); } VersionUtility.ValidatePortableFrameworkProfilePart(profileValue); char[] separator = new char[] { '+' }; return(new NetPortableProfile(profileValue, Enumerable.Select <string, FrameworkName>(profileValue.Split(separator, StringSplitOptions.RemoveEmptyEntries), new Func <string, FrameworkName>(VersionUtility.ParseFrameworkName)), null)); }
/// <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 ArgumentException(CommonResources.Argument_Cannot_Be_Null_Or_Empty, "profileValue"); } if (profileValue.StartsWith("Profile", StringComparison.OrdinalIgnoreCase)) { return(NetPortableProfileTable.GetProfile(profileValue)); } VersionUtility.ValidatePortableFrameworkProfilePart(profileValue); var supportedFrameworks = profileValue.Split(new [] { '+' }, StringSplitOptions.RemoveEmptyEntries) .Select(VersionUtility.ParseFrameworkName); return(new NetPortableProfile(profileValue, supportedFrameworks)); }