Show / Hide Table of Contents

Class Registry<T>

Represents a thread-safe registry of T. This class is efficient for concurrent read access and is not designed for cases when frequent modifications happen. It is ideal for lookup of named instances (such as components) that have much longer time span than components that look them up. Registry performs lock-free lookup which speeds-up many concurrent operations that need to map names into objects. The enumeration over registry makes a snapshot of its data, hence a registry may be modified by other threads while being enumerated.

Inheritance
System.Object
Registry<T>
Bindings
Providers
Servers
OrderedRegistry<T>
Implements
IRegistry<T>
System.Collections.Generic.IEnumerable<T>
System.Collections.IEnumerable
Inherited Members
System.Object.Equals(System.Object)
System.Object.Equals(System.Object, System.Object)
System.Object.GetHashCode()
System.Object.GetType()
System.Object.MemberwiseClone()
System.Object.ReferenceEquals(System.Object, System.Object)
System.Object.ToString()
Namespace: NFX
Assembly: NFX.dll
Syntax
[Serializable]
public class Registry<T> : IRegistry<T>, IEnumerable<T>, IEnumerable where T : INamed
Type Parameters
Name Description
T

Constructors

Registry()

Declaration
public Registry()

Registry(Boolean)

Declaration
public Registry(bool caseSensitive)
Parameters
Type Name Description
System.Boolean caseSensitive

Registry(IEnumerable<T>)

Declaration
public Registry(IEnumerable<T> other)
Parameters
Type Name Description
System.Collections.Generic.IEnumerable<T> other

Registry(IEnumerable<T>, Boolean)

Declaration
public Registry(IEnumerable<T> other, bool caseSensitive)
Parameters
Type Name Description
System.Collections.Generic.IEnumerable<T> other
System.Boolean caseSensitive

Fields

m_Sync

Declaration
[NonSerialized]
protected object m_Sync
Field Value
Type Description
System.Object

Properties

Count

Returns the number of entries in the registry

Declaration
public int Count { get; }
Property Value
Type Description
System.Int32

IsCaseSensitive

Returns true if the instance differentiates names by case

Declaration
public bool IsCaseSensitive { get; }
Property Value
Type Description
System.Boolean

Item[String]

Returns a value by name or null if not found

Declaration
public T this[string name] { get; }
Parameters
Type Name Description
System.String name
Property Value
Type Description
T

Names

Declaration
public IEnumerable<string> Names { get; }
Property Value
Type Description
System.Collections.Generic.IEnumerable<System.String>

Values

Declaration
public IEnumerable<T> Values { get; }
Property Value
Type Description
System.Collections.Generic.IEnumerable<T>

Methods

Clear()

Deletes all items from registry

Declaration
public virtual void Clear()

ContainsName(String)

Declaration
public bool ContainsName(string name)
Parameters
Type Name Description
System.String name
Returns
Type Description
System.Boolean

GetEnumerator()

Declaration
public IEnumerator<T> GetEnumerator()
Returns
Type Description
System.Collections.Generic.IEnumerator<T>

GetOrRegister<TContext>(String, Func<TContext, T>, TContext)

Tries to find an item by name, and returns it if it is found, otherwise calls a factory function supplying context value and registers the obtained new item. The first lookup is performed in a lock-free way and if an item is found then it is immediately returned. The second check and factory call operation is performed atomically under the lock to ensure consistency

Declaration
public T GetOrRegister<TContext>(string name, Func<TContext, T> regFactory, TContext context)
Parameters
Type Name Description
System.String name
System.Func<TContext, T> regFactory
TContext context
Returns
Type Description
T
Type Parameters
Name Description
TContext

GetOrRegister<TContext>(String, Func<TContext, T>, TContext, out Boolean)

Tries to find an item by name, and returns it if it is found, otherwise calls a factory function supplying context value and registers the obtained new item. The first lookup is performed in a lock-free way and if an item is found then it is immediately returned. The second check and factory call operation is performed atomically under the lock to ensure consistency

Declaration
public T GetOrRegister<TContext>(string name, Func<TContext, T> regFactory, TContext context, out bool wasAdded)
Parameters
Type Name Description
System.String name
System.Func<TContext, T> regFactory
TContext context
System.Boolean wasAdded
Returns
Type Description
T
Type Parameters
Name Description
TContext

JustRegistered(T)

Declaration
protected virtual void JustRegistered(T item)
Parameters
Type Name Description
T item

JustReplaced(T, T)

Declaration
protected virtual void JustReplaced(T existingItem, T newItem)
Parameters
Type Name Description
T existingItem
T newItem

JustUnregistered(T)

Declaration
protected virtual void JustUnregistered(T item)
Parameters
Type Name Description
T item

Register(T)

Registers item and returns true if it was registered, false if this named instance already existed in the list

Declaration
public bool Register(T item)
Parameters
Type Name Description
T item
Returns
Type Description
System.Boolean

RegisterOrReplace(T)

Registers item and returns true if it was registered, false if this named instance already existed and was replaced

Declaration
public bool RegisterOrReplace(T item)
Parameters
Type Name Description
T item
Returns
Type Description
System.Boolean

RegisterOrReplace(T, out T)

Registers item and returns true if it was registered, false if this named instance already existed and was replaced

Declaration
public bool RegisterOrReplace(T item, out T existing)
Parameters
Type Name Description
T item
T existing
Returns
Type Description
System.Boolean

TryGetValue(String, out T)

Declaration
public bool TryGetValue(string name, out T value)
Parameters
Type Name Description
System.String name
T value
Returns
Type Description
System.Boolean

Unregister(T)

Unregisters item and returns true if it was unregistered, false if it did not exist

Declaration
public bool Unregister(T item)
Parameters
Type Name Description
T item
Returns
Type Description
System.Boolean

Unregister(String)

Unregisters item by name and returns true if it was unregistered, false if it did not exist

Declaration
public bool Unregister(string name)
Parameters
Type Name Description
System.String name
Returns
Type Description
System.Boolean

Explicit Interface Implementations

IEnumerable.GetEnumerator()

Declaration
IEnumerator IEnumerable.GetEnumerator()
Returns
Type Description
System.Collections.IEnumerator

Implements

IRegistry<T>
System.Collections.Generic.IEnumerable<T>
System.Collections.IEnumerable

Extension Methods

CollectionUtils.ForEach<T>(IEnumerable<T>, Action<T>)
CollectionUtils.ForEach<T>(IEnumerable<T>, Action<T, Int32>)
CollectionUtils.SkipLast<T>(IEnumerable<T>)
CollectionUtils.SkipLast<T>(IEnumerable<T>, Int32)
CollectionUtils.FirstMin<TResult, TComparand>(IEnumerable<TResult>, Func<TResult, TComparand>)
CollectionUtils.FirstMin<TResult, TComparand>(IEnumerable<TResult>, Func<TResult, TComparand>, out TComparand)
CollectionUtils.FirstMax<TResult, TComparand>(IEnumerable<TResult>, Func<TResult, TComparand>)
CollectionUtils.FirstMax<TResult, TComparand>(IEnumerable<TResult>, Func<TResult, TComparand>, out TComparand)
CollectionUtils.FirstOrAnyOrDefault<TResult>(IEnumerable<TResult>, Func<TResult, Boolean>)
CollectionUtils.Distinct<TResult, TKey>(IEnumerable<TResult>, Func<TResult, TKey>)
MiscUtils.NonNull<T>(T, Func<Exception>, String)
ObjectValueConversion.AsString(Object, String, ConvertErrorHandling)
ObjectValueConversion.AsNonNullOrEmptyString(Object)
ObjectValueConversion.AsLaconicConfig(Object, ConfigSectionNode, String, ConvertErrorHandling)
ObjectValueConversion.AsJSONConfig(Object, ConfigSectionNode, String, ConvertErrorHandling)
ObjectValueConversion.AsXMLConfig(Object, ConfigSectionNode, ConvertErrorHandling)
ObjectValueConversion.AsChar(Object, Char, ConvertErrorHandling)
ObjectValueConversion.AsNullableChar(Object, Nullable<Char>, ConvertErrorHandling)
ObjectValueConversion.AsByte(Object, Byte, ConvertErrorHandling)
ObjectValueConversion.AsNullableByte(Object, Nullable<Byte>, ConvertErrorHandling)
ObjectValueConversion.AsSByte(Object, SByte, ConvertErrorHandling)
ObjectValueConversion.AsNullableSByte(Object, Nullable<SByte>, ConvertErrorHandling)
ObjectValueConversion.AsShort(Object, Int16, ConvertErrorHandling)
ObjectValueConversion.AsNullableShort(Object, Nullable<Int16>, ConvertErrorHandling)
ObjectValueConversion.AsUShort(Object, UInt16, ConvertErrorHandling)
ObjectValueConversion.AsNullableUShort(Object, Nullable<UInt16>, ConvertErrorHandling)
ObjectValueConversion.AsInt(Object, Int32, ConvertErrorHandling)
ObjectValueConversion.AsNullableInt(Object, Nullable<Int32>, ConvertErrorHandling)
ObjectValueConversion.AsUInt(Object, UInt32, ConvertErrorHandling)
ObjectValueConversion.AsNullableUInt(Object, Nullable<UInt32>, ConvertErrorHandling)
ObjectValueConversion.AsLong(Object, Int64, ConvertErrorHandling)
ObjectValueConversion.AsNullableLong(Object, Nullable<Int64>, ConvertErrorHandling)
ObjectValueConversion.AsULong(Object, UInt64, ConvertErrorHandling)
ObjectValueConversion.AsNullableULong(Object, Nullable<UInt64>, ConvertErrorHandling)
ObjectValueConversion.AsDouble(Object, Double, ConvertErrorHandling)
ObjectValueConversion.AsNullableDouble(Object, Nullable<Double>, ConvertErrorHandling)
ObjectValueConversion.AsFloat(Object, Single, ConvertErrorHandling)
ObjectValueConversion.AsNullableFloat(Object, Nullable<Single>, ConvertErrorHandling)
ObjectValueConversion.AsDecimal(Object, Decimal, ConvertErrorHandling)
ObjectValueConversion.AsNullableDecimal(Object, Nullable<Decimal>, ConvertErrorHandling)
ObjectValueConversion.AsBool(Object, Boolean, ConvertErrorHandling)
ObjectValueConversion.AsNullableBool(Object, Nullable<Boolean>, ConvertErrorHandling)
ObjectValueConversion.AsGUID(Object, Guid, ConvertErrorHandling)
ObjectValueConversion.AsNullableGUID(Object, Nullable<Guid>, ConvertErrorHandling)
ObjectValueConversion.AsDateTime(Object)
ObjectValueConversion.AsDateTime(Object, DateTime, ConvertErrorHandling)
ObjectValueConversion.AsNullableDateTime(Object, Nullable<DateTime>, ConvertErrorHandling)
ObjectValueConversion.AsGDID(Object)
ObjectValueConversion.AsGDID(Object, GDID, ConvertErrorHandling)
ObjectValueConversion.AsNullableGDID(Object, Nullable<GDID>, ConvertErrorHandling)
ObjectValueConversion.AsGDIDSymbol(Object)
ObjectValueConversion.AsGDIDSymbol(Object, GDIDSymbol, ConvertErrorHandling)
ObjectValueConversion.AsNullableGDIDSymbol(Object, Nullable<GDIDSymbol>, ConvertErrorHandling)
ObjectValueConversion.AsTimeSpan(Object)
ObjectValueConversion.AsTimeSpan(Object, TimeSpan, ConvertErrorHandling)
ObjectValueConversion.AsNullableTimeSpan(Object, Nullable<TimeSpan>, ConvertErrorHandling)
ObjectValueConversion.AsEnum<TEnum>(Object, TEnum, ConvertErrorHandling)
ObjectValueConversion.AsNullableEnum<TEnum>(Object, Nullable<TEnum>, ConvertErrorHandling)
ObjectValueConversion.AsUri(Object, Uri, ConvertErrorHandling)
LookAheadExtensions.AsLookAheadEnumerable<T>(IEnumerable<T>)
JSONExtensions.ToJSON(Object, JSONWritingOptions)
JSONExtensions.ToJSON(Object, TextWriter, JSONWritingOptions)
JSONExtensions.ToJSON(Object, Stream, JSONWritingOptions, Encoding)
ErlObject.ToErlObject(Object)
ErlObject.ToErlObject(Object, ErlTypeOrder, Boolean)
Back to top Copyright © 2006-2018 Agnicore Inc
Generated by DocFX