Table of Contents

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 SerializationInfo
context StreamingContext

LanguageSet(string)

Deserializes a space-separated list of languages codes.

public LanguageSet(string value)

Parameters

value string

A 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 string

The 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 bool

true to compare only the two-letter language name; false to 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