Show / Hide Table of Contents

Class Extensions

Provides various extension methods useful for working with XML and the Colectica model.

Inheritance
object
Extensions
Inherited Members
object.ToString()
object.Equals(object)
object.Equals(object, object)
object.ReferenceEquals(object, object)
object.GetHashCode()
object.GetType()
object.MemberwiseClone()
Namespace: Algenta.Colectica.Model.Utility
Assembly: Algenta.Colectica.Model.dll
Syntax
public static class Extensions

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

See http://ericlippert.com/2010/06/28/computing-a-cartesian-product-with-linq/

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

EnsureCollectionInstantiation(CommitOptions)

Ensure that all collections are instantiated. The contract deserializer may set them to null from non-colectica sdk clients

Declaration
public static void EnsureCollectionInstantiation(this CommitOptions options)
Parameters
Type Name Description
CommitOptions options

EnsureCollectionInstantiation(GraphSearchFacet)

Ensure that all collections are instantiated. The contract deserializer may set them to null from non-colectica sdk clients

Declaration
public static void EnsureCollectionInstantiation(this GraphSearchFacet item)
Parameters
Type Name Description
GraphSearchFacet item

EnsureCollectionInstantiation(SearchFacet)

Ensure that all collections are instantiated. The contract deserializer may set them to null from non-colectica sdk clients

Declaration
public static void EnsureCollectionInstantiation(this SearchFacet facet)
Parameters
Type Name Description
SearchFacet facet

EnsureCollectionInstantiation(SetSearchFacet)

Ensure that all collections are instantiated. The contract deserializer may set them to null from non-colectica sdk clients

Declaration
public static void EnsureCollectionInstantiation(this SetSearchFacet item)
Parameters
Type Name Description
SetSearchFacet item

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

FromBase64(string)

Converts a string from Base64.

Declaration
public static string FromBase64(this string str)
Parameters
Type Name Description
string str

The string.

Returns
Type Description
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.

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
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<string> languageSortOrder
Returns
Type Description
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<string> languageSortOrder

The language sort order.

string defaultText

The default text, in case the MultilingualString contains no content.

Returns
Type Description
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
string str

The string.

Returns
Type Description
XElement

An XML element if the string can be converted to XHTML; otherwise null.

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
int

IsStringLikelyXml(string)

Determines whether a string is likely XML.

Declaration
public static bool IsStringLikelyXml(this string str)
Parameters
Type Name Description
string str

The string.

Returns
Type Description
bool

true if the string starts and ends with angle brackets; otherwise false.

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
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
int
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
string str

The string.

Returns
Type Description
string

A Base64 string.

ToChunks<T>(IEnumerable<T>, int)

Converts a list into multiple lists, each with the specified number of items.

Declaration
public static IEnumerable<IEnumerable<T>> ToChunks<T>(this IEnumerable<T> enumerable, int chunkSize)
Parameters
Type Name Description
IEnumerable<T> enumerable

The list that will be converted into multiple lists.

int 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
string value

The string to be converted.

Returns
Type Description
T

The enumeration value

Type Parameters
Name Description
T

The type of the enumeration

Exceptions
Type Condition
InvalidOperationException

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
string

A JSON string.

ToTypedIdentifierCollection(IEnumerable<IVersionable>)

Converts an enumeration of IVersionable objects to a collection.

Declaration
public static Collection<TypedIdTriple> ToTypedIdentifierCollection(this IEnumerable<IVersionable> versionables)
Parameters
Type Name Description
IEnumerable<IVersionable> versionables

The IVersionable objects.

Returns
Type Description
Collection<TypedIdTriple>

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.

In this article
Back to top Generated by DocFX