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
-
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
collection
IEnumerable<CultureInfo>
LanguageSet(SerializationInfo, StreamingContext)
protected LanguageSet(SerializationInfo info, StreamingContext context)
Parameters
info
SerializationInfocontext
StreamingContext
LanguageSet(string)
Deserializes a space-separated list of languages codes.
public LanguageSet(string value)
Parameters
value
stringA 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 InvariantCulture rather than raising an ArgumentException.
Methods
Add(string)
Adds a language identified by a string to the collection.
[CollectionAccess(CollectionAccessType.UpdatedContent)]
public bool Add(string langCode)
Parameters
langCode
stringThe string identifying the language to add.
Returns
- bool
true
if the language could be added,false
otherwise.
Exceptions
- ArgumentException
langCode
is 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
targets
IEnumerable<CultureInfo>The language set to match against.
ignoreCountry
booltrue
to compare only the two-letter language name;false
to also compare the country code.
Returns
ToString()
Serializes the list as a space-separated list of languages codes.
public override string ToString()