Class Extensions
Provides various extension methods useful for working with XML and the Colectica model.
Inheritance
Namespace: Algenta.Colectica.Model.Utility
Assembly: Algenta.Colectica.Model.dll
Syntax
public static class Extensions : object
Methods
CartesianProduct<T>(IEnumerable<IEnumerable<T>>)
Calculates the cartesian product of a list of lists.
Declaration
public static IEnumerable<IEnumerable<T>> CartesianProduct<T>(this IEnumerable<IEnumerable<T>> sequences)
Parameters
Type | Name | Description |
---|---|---|
IEnumerable<IEnumerable<T>> | sequences |
Returns
Type | Description |
---|---|
IEnumerable<IEnumerable<T>> | The cartesian product of the lists. |
Type Parameters
Name | Description |
---|---|
T |
Remarks
ElementOrDefault(XElement, XName)
Returns the element with the specified name.
Declaration
public static XElement ElementOrDefault(this XElement element, XName name)
Parameters
Type | Name | Description |
---|---|---|
XElement | element | The element under which elements will be searched. |
XName | name | The name of the element to find. |
Returns
Type | Description |
---|---|
XElement |
FindXPath(XElement)
Finds the XPath of the element within its document.
Declaration
public static string FindXPath(this XElement element)
Parameters
Type | Name | Description |
---|---|---|
XElement | element | The element for which the XPath is found. |
Returns
Type | Description |
---|---|
System.String |
FindXPath(XmlNode)
Finds the XPath of the node within its document.
Declaration
public static string FindXPath(this XmlNode node)
Parameters
Type | Name | Description |
---|---|---|
XmlNode | node | The node for which the XPath is found. |
Returns
Type | Description |
---|---|
System.String |
FromBase64(String)
Converts a string from Base64.
Declaration
public static string FromBase64(this string str)
Parameters
Type | Name | Description |
---|---|---|
System.String | str | The string. |
Returns
Type | Description |
---|---|
System.String | A regular string. |
FromJson(MultilingualString, String)
Populates a MultilingualString from a JSON representation.
Declaration
public static void FromJson(this MultilingualString item, string json)
Parameters
Type | Name | Description |
---|---|---|
MultilingualString | item | The item to be populated. |
System.String | json | The JSON representation of the item. |
GetAggregateMessage(AggregateException)
Returns the text of all messages found in an AggregateException.
Declaration
public static string GetAggregateMessage(this AggregateException ex)
Parameters
Type | Name | Description |
---|---|---|
AggregateException | ex |
Returns
Type | Description |
---|---|
System.String |
GetBestCulture(MultilingualString, List<String>)
Returns the current multilingual string culture if a value exists, or returns the first culture with a value based on the language sort order
Declaration
public static string GetBestCulture(this MultilingualString mls, List<string> languageSortOrder)
Parameters
Type | Name | Description |
---|---|---|
MultilingualString | mls | |
List<System.String> | languageSortOrder |
Returns
Type | Description |
---|---|
System.String |
GetBestString(MultilingualString, List<String>, String)
Gets the string for the first language that has content.
Declaration
public static string GetBestString(this MultilingualString mls, List<string> languageSortOrder, string defaultText)
Parameters
Type | Name | Description |
---|---|---|
MultilingualString | mls | The MultilingualString from which a single string will be returned. |
List<System.String> | languageSortOrder | The language sort order. |
System.String | defaultText | The default text, in case the MultilingualString contains no content. |
Returns
Type | Description |
---|---|
System.String |
GetXhtmlElement(String)
Converts the string to an XHTML XML element. If the string cannot be converted, the method returns null
.
Declaration
public static XElement GetXhtmlElement(this string str)
Parameters
Type | Name | Description |
---|---|---|
System.String | str | The string. |
Returns
Type | Description |
---|---|
XElement | An XML element if the string can be converted to XHTML; otherwise |
IndexPosition(XElement)
Get the index of the given XElement relative to its siblings with identical names. If the given element is the root, -1 is returned.
Declaration
public static int IndexPosition(this XElement element)
Parameters
Type | Name | Description |
---|---|---|
XElement | element | The element to get the index of. |
Returns
Type | Description |
---|---|
System.Int32 |
IsStringLikelyXml(String)
Determines whether a string is likely XML.
Declaration
public static bool IsStringLikelyXml(this string str)
Parameters
Type | Name | Description |
---|---|---|
System.String | str | The string. |
Returns
Type | Description |
---|---|
System.Boolean |
|
LogException(Exception)
Logs an exception, including all its inner exceptions.
Declaration
public static void LogException(Exception ex)
Parameters
Type | Name | Description |
---|---|---|
Exception | ex |
Merge<T>(ICollection<T>, IEnumerable<T>)
Merges two collections.
Declaration
public static void Merge<T>(this ICollection<T> first, IEnumerable<T> second)
Parameters
Type | Name | Description |
---|---|---|
ICollection<T> | first | The first, into which the second collection is merged. |
IEnumerable<T> | second | The second collection, which is merged into the first collection. |
Type Parameters
Name | Description |
---|---|
T | The type of items in the collections. |
OuterXml(XElement)
Gets a string with the XML of the element.
Declaration
public static string OuterXml(this XElement el)
Parameters
Type | Name | Description |
---|---|---|
XElement | el | The element. |
Returns
Type | Description |
---|---|
System.String | A string of XML. |
ReplaceChild<T>(IList<T>, IdentifierTriple, IVersionable)
Replaces the specified child in the provided list.
Declaration
public static int ReplaceChild<T>(this IList<T> items, IdentifierTriple toReplace, IVersionable child)where T : class, IVersionable
Parameters
Type | Name | Description |
---|---|---|
IList<T> | items | The list of items in which the child will be replaced. |
IdentifierTriple | toReplace | The identifier of the item to be replaced. |
IVersionable | child | The new child. |
Returns
Type | Description |
---|---|
System.Int32 |
Type Parameters
Name | Description |
---|---|
T | The type of the child to be replaced. |
Sort(IEnumerable<RepositoryItemMetadata>)
Sorts the specified list of item descriptions by item type, agency, identifier, and version.
Declaration
public static IEnumerable<RepositoryItemMetadata> Sort(this IEnumerable<RepositoryItemMetadata> value)
Parameters
Type | Name | Description |
---|---|---|
IEnumerable<RepositoryItemMetadata> | value | The list of item descriptions to be sorted. |
Returns
Type | Description |
---|---|
IEnumerable<RepositoryItemMetadata> |
ToBase64(String)
Converts the string to Base64.
Declaration
public static string ToBase64(this string str)
Parameters
Type | Name | Description |
---|---|---|
System.String | str | The string. |
Returns
Type | Description |
---|---|
System.String | A Base64 string. |
ToChunks<T>(Collection<T>, Int32)
Converts a list into multiple lists, each with the specified number of items.
Declaration
public static IEnumerable<IEnumerable<T>> ToChunks<T>(this Collection<T> enumerable, int chunkSize)
Parameters
Type | Name | Description |
---|---|---|
Collection<T> | enumerable | The list that will be converted into multiple lists. |
System.Int32 | chunkSize | The size of each of the newly created lists. |
Returns
Type | Description |
---|---|
IEnumerable<IEnumerable<T>> | An enumeration of lists. |
Type Parameters
Name | Description |
---|---|
T | The type of item contained in the list. |
ToCollection(IEnumerable<IVersionable>)
Converts an enumeration of IVersionable objects to a Collection.
Declaration
public static Collection<IVersionable> ToCollection(this IEnumerable<IVersionable> items)
Parameters
Type | Name | Description |
---|---|---|
IEnumerable<IVersionable> | items | The items. |
Returns
Type | Description |
---|---|
Collection<IVersionable> |
ToEnum<T>(String)
Converts a string to a value from an enumeration.
Declaration
public static T ToEnum<T>(this string value)
Parameters
Type | Name | Description |
---|---|---|
System.String | value | The string to be converted. |
Returns
Type | Description |
---|---|
T | The enumeration value |
Type Parameters
Name | Description |
---|---|
T | The type of the enumeration |
ToIdentifierCollection(IEnumerable<IVersionable>)
Converts a list of IVersionable items to a list of identifiers.
Declaration
public static Collection<IdentifierTriple> ToIdentifierCollection(this IEnumerable<IVersionable> items)
Parameters
Type | Name | Description |
---|---|---|
IEnumerable<IVersionable> | items | The items. |
Returns
Type | Description |
---|---|
Collection<IdentifierTriple> | The list of identifiers. |
ToIdentifierCollection(IEnumerable<IdentifierTriple>)
Converts an enumeration of IdentifierTriple objects to a collection of IdentifierTriple objects.
Declaration
public static Collection<IdentifierTriple> ToIdentifierCollection(this IEnumerable<IdentifierTriple> identifiers)
Parameters
Type | Name | Description |
---|---|---|
IEnumerable<IdentifierTriple> | identifiers | The identifiers to convert. |
Returns
Type | Description |
---|---|
Collection<IdentifierTriple> | A collection of IdentifierTriple objects. |
ToIdentifierCollection(IEnumerable<TypedIdTriple>)
Converts a list of TypedIdTriple items to a list of IdentifierTriple items.
Declaration
public static Collection<IdentifierTriple> ToIdentifierCollection(this IEnumerable<TypedIdTriple> typedIdentifiers)
Parameters
Type | Name | Description |
---|---|---|
IEnumerable<TypedIdTriple> | typedIdentifiers | The typed identifiers. |
Returns
Type | Description |
---|---|
Collection<IdentifierTriple> | The list of IdentifierTriple items. |
ToIdentifierHashSet(Collection<IdentifierTriple>)
Converts a collection of IdentifierTriple objects to a HashSet
.
Declaration
public static HashSet<IdentifierTriple> ToIdentifierHashSet(this Collection<IdentifierTriple> identifiers)
Parameters
Type | Name | Description |
---|---|---|
Collection<IdentifierTriple> | identifiers | The identifiers. |
Returns
Type | Description |
---|---|
HashSet<IdentifierTriple> |
ToIdentifierHashSet(Collection<TypedIdTriple>)
Converts a collection of TypedIdTriple objects to a HashSet
.
Declaration
public static HashSet<IdentifierTriple> ToIdentifierHashSet(this Collection<TypedIdTriple> typedIdentifiers)
Parameters
Type | Name | Description |
---|---|---|
Collection<TypedIdTriple> | typedIdentifiers | The typed identifiers. |
Returns
Type | Description |
---|---|
HashSet<IdentifierTriple> |
ToJson(MultilingualString)
Converst a MultilingualString to a JSON representation.
Declaration
public static string ToJson(this MultilingualString item)
Parameters
Type | Name | Description |
---|---|---|
MultilingualString | item | The item to be converted to JSON. |
Returns
Type | Description |
---|---|
System.String | A JSON string. |
ToTypedIdentifierCollection(IEnumerable<TypedIdTriple>)
Converts an enumeration of TypedIdTriple objects to a collection.
Declaration
public static Collection<TypedIdTriple> ToTypedIdentifierCollection(this IEnumerable<TypedIdTriple> typedIdentifiers)
Parameters
Type | Name | Description |
---|---|---|
IEnumerable<TypedIdTriple> | typedIdentifiers | The typed identifiers. |
Returns
Type | Description |
---|---|
Collection<TypedIdTriple> |
Yield<T>(T)
Wraps this object instance into an IEnumerable<T> consisting of a single item.
Declaration
public static IEnumerable<T> Yield<T>(this T item)
Parameters
Type | Name | Description |
---|---|---|
T | item | The object to wrap. |
Returns
Type | Description |
---|---|
IEnumerable<T> | An IEnumerable<T> consisting of a single item. |
Type Parameters
Name | Description |
---|---|
T | Type of the wrapped object. |