Class AttributeRegistry<TObject, TAttribute>
An attribute registry allows attributes to be associated with objects.
Inherited Members
Namespace: Microsoft.ML.Probabilistic.Compiler
Assembly: Microsoft.ML.Probabilistic.Compiler.dll
Syntax
public class AttributeRegistry<TObject, TAttribute> : IEnumerable<KeyValuePair<TObject, Set<TAttribute>>>, IEnumerable, ICloneable where TObject : class where TAttribute : class
Type Parameters
Name | Description |
---|---|
TObject | |
TAttribute |
Constructors
AttributeRegistry(Boolean)
Attribute registry constructor
Declaration
public AttributeRegistry(bool useIdentityEquality)
Parameters
Type | Name | Description |
---|---|---|
Boolean | useIdentityEquality | Attributes are consider equal if they reference the same instance |
Fields
registry
The attribute registry - dictionary from objects to attributes
Declaration
protected Dictionary<TObject, Set<TAttribute>> registry
Field Value
Type | Description |
---|---|
Dictionary<TObject, Set<TAttribute>> |
Properties
IsIdentityEquality
Declaration
protected bool IsIdentityEquality { get; }
Property Value
Type | Description |
---|---|
Boolean |
Methods
Add(TObject, TAttribute)
Registers an attribute against the specified object. Unlike Set, the attribute need not be unique.
Declaration
public void Add(TObject obj, TAttribute attr)
Parameters
Type | Name | Description |
---|---|---|
TObject | obj | The object to associate the attribute with |
TAttribute | attr | The attribute to associate |
Clone()
Declaration
public object Clone()
Returns
Type | Description |
---|---|
Object |
CopyObjectAttributesTo(TObject, AttributeRegistry<TObject, TAttribute>, TObject)
Copies object attributes associated with source object to target object in a target registry
Declaration
public void CopyObjectAttributesTo(TObject sourceObject, AttributeRegistry<TObject, TAttribute> targetRegistry, TObject targetObject)
Parameters
Type | Name | Description |
---|---|---|
TObject | sourceObject | Source object |
AttributeRegistry<TObject, TAttribute> | targetRegistry | Target registry |
TObject | targetObject | Target object |
CopyObjectAttributesTo<T>(TObject, AttributeRegistry<TObject, TAttribute>, TObject)
Copies object attributes of type T associated with source object to target object in a target registry
Declaration
public void CopyObjectAttributesTo<T>(TObject sourceObject, AttributeRegistry<TObject, TAttribute> targetRegistry, TObject targetObject)
Parameters
Type | Name | Description |
---|---|---|
TObject | sourceObject | Source object |
AttributeRegistry<TObject, TAttribute> | targetRegistry | Target registry |
TObject | targetObject | Target object |
Type Parameters
Name | Description |
---|---|
T | Attribute type |
Get<T>(TObject)
Gets the unique attribute of a given type. Returns null if none. Throws an exception if not unique.
Declaration
public T Get<T>(TObject obj)
where T : class, TAttribute
Parameters
Type | Name | Description |
---|---|---|
TObject | obj | The object |
Returns
Type | Description |
---|---|
T | The attribute or null |
Type Parameters
Name | Description |
---|---|
T | The type |
GetAll<T>(TObject)
Returns the attributes of type T associated with the specified object.
Declaration
public List<T> GetAll<T>(TObject mi)
where T : TAttribute
Parameters
Type | Name | Description |
---|---|---|
TObject | mi |
Returns
Type | Description |
---|---|
List<T> |
Type Parameters
Name | Description |
---|---|
T |
GetEnumerator()
Gets an enumerator that iterates through the attribute registry
Declaration
public IEnumerator<KeyValuePair<TObject, Set<TAttribute>>> GetEnumerator()
Returns
Type | Description |
---|---|
IEnumerator<KeyValuePair<TObject, Set<TAttribute>>> |
GetOrCreate<T>(TObject, Func<T>)
Gets an attribute of a given type, or creates one if it doesn't already exist
Declaration
public T GetOrCreate<T>(TObject obj, Func<T> generator)
where T : class, TAttribute
Parameters
Type | Name | Description |
---|---|---|
TObject | obj | The object |
Func<T> | generator |
Returns
Type | Description |
---|---|
T | The attribute |
Type Parameters
Name | Description |
---|---|
T | The type |
Has<T>(TObject)
Whether an object has an attribute of a particular type
Declaration
public bool Has<T>(TObject obj)
where T : class, TAttribute
Parameters
Type | Name | Description |
---|---|---|
TObject | obj | The object |
Returns
Type | Description |
---|---|
Boolean |
Type Parameters
Name | Description |
---|---|
T | The type |
HasAttributes(TObject)
Whether a given object has attributes
Declaration
public bool HasAttributes(TObject obj)
Parameters
Type | Name | Description |
---|---|---|
TObject | obj | The object |
Returns
Type | Description |
---|---|
Boolean |
Remove<T>(TObject)
Removes all attributes of the specified object assignable to class T.
Declaration
public void Remove<T>(TObject obj)
where T : TAttribute
Parameters
Type | Name | Description |
---|---|---|
TObject | obj | Specified object |
Type Parameters
Name | Description |
---|---|
T | Specified type |
RemoveOfType(TObject, Type)
Removes all attributes of the specified object assignable to class T.
Declaration
public void RemoveOfType(TObject obj, Type t)
Parameters
Type | Name | Description |
---|---|---|
TObject | obj | Specified object |
Type | t | Specified type |
Set<T>(TObject, T)
Sets the unique attribute of a given type against an object. Throws an exception if not unique.
Declaration
public void Set<T>(TObject obj, T attr)
where T : class, TAttribute
Parameters
Type | Name | Description |
---|---|---|
TObject | obj | The object to associate the attribute with |
T | attr | The attribute to associate |
Type Parameters
Name | Description |
---|---|
T |
WriteObjectAttributesTo(TObject, TextWriter)
Write out the attributes of a specified object to a text writer
Declaration
public void WriteObjectAttributesTo(TObject obj, TextWriter writer)
Parameters
Type | Name | Description |
---|---|---|
TObject | obj | |
TextWriter | writer |
WriteTo(TextWriter)
Write out the resgistry and the keyed registry to a text writer
Declaration
public void WriteTo(TextWriter writer)
Parameters
Type | Name | Description |
---|---|---|
TextWriter | writer |
Explicit Interface Implementations
IEnumerable.GetEnumerator()
Declaration
IEnumerator IEnumerable.GetEnumerator()
Returns
Type | Description |
---|---|
IEnumerator |