Class LanguageSet
- Namespace
- NanoByte.Common.Collections
- Assembly
- NanoByte.Common.dll
A set of languages that can be serialized as a simple space-separated list of ISO language codes.
[Serializable]
[TypeConverter(typeof(StringConstructorConverter<LanguageSet>))]
public class LanguageSet : SortedSet<CultureInfo>
- Inheritance
-
objectSortedSet<CultureInfo>LanguageSet
- Extension Methods
Remarks
Uses Unix-style language codes with an underscore (_) separator.
Constructors
LanguageSet()
Creates a new empty language collection.
public LanguageSet()
LanguageSet(IEnumerable<CultureInfo>)
Creates a new language collection pre-filled with a set of languages.
public LanguageSet(IEnumerable<CultureInfo> collection)
Parameters
collectionIEnumerable<CultureInfo>
LanguageSet(SerializationInfo, StreamingContext)
protected LanguageSet(SerializationInfo info, StreamingContext context)
Parameters
infoSerializationInfocontextStreamingContext
LanguageSet(string)
Deserializes a space-separated list of languages codes.
public LanguageSet(string value)
Parameters
valuestringA space-separated list of languages codes (in the same format as used by the LANG environment variable).
Remarks
Unknown language codes in value are replaced with System.Globalization.CultureInfo.InvariantCulture rather than raising an System.ArgumentException.
Methods
Add(string)
Adds a language identified by a string to the collection.
[CollectionAccess(CollectionAccessType.UpdatedContent)]
public bool Add(string langCode)
Parameters
langCodestringThe string identifying the language to add.
Returns
- bool
trueif the language could be added,falseotherwise.
Exceptions
- ArgumentException
langCodeis not a valid language code.
ContainsAny(IEnumerable<CultureInfo>, bool)
Determines whether this language set contains any of a set of target languages.
[CollectionAccess(CollectionAccessType.Read)]
public bool ContainsAny(IEnumerable<CultureInfo> targets, bool ignoreCountry = false)
Parameters
targetsIEnumerable<CultureInfo>The language set to match against.
ignoreCountrybooltrueto compare only the two-letter language name;falseto also compare the country code.
Returns
- bool
ToString()
Serializes the list as a space-separated list of languages codes.
public override string ToString()
Returns
- string