IRecordDelegates
IRecordDelegates contains delegates for record. (namespace Avalanche.Utilities.Record).
/// <summary>Record delegates</summary>
public interface IRecordDelegates
{
/// <summary>Record Type</summary>
Type RecordType { get; set; }
/// <summary>Creates record with initial values <![CDATA[Func<object[], Record>]]></summary>
Delegate? RecordCreate { get; set; }
/// <summary>Field delegates</summary>
IFieldDelegates[]? FieldDelegates { get; set; }
/// <summary></summary>
IRecordDescription? RecordDescription { get; set; }
}
/// <summary>Record delegates</summary>
public interface IRecordDelegates<Record> : IRecordDelegates
{
/// <summary>Creates record with initial values <![CDATA[Func<object[], Record>]]></summary>
new Func<object[], Record>? RecordCreate { get; set; }
}
RecordDelegates is the default implementation.
IRecordDelegates<MyClass> recordDelegates =
new RecordDelegates<MyClass>
{
RecordCreate = null,
FieldDelegates = new IFieldDelegates[0],
RecordDescription = null
}.SetReadOnly();
There is a setter method for each field.
IRecordDelegates recordDelegates =
RecordDelegates
.Create(typeof(MyClass))
.SetRecordCreate(null)
.SetFieldDelegates(null)
.SetRecordDescription(null)
.SetReadOnly();
.Clone() makes a copy.
IRecordDelegates clone = recordDelegates.Clone().SetReadOnly();
.CreateRecordDelegates() and .CreateRecordDelegates<T>() create delegates.
IRecordDelegates<MyClass> recordDelegates = recordDescription.CreateRecordDelegates<MyClass>();
Delegates can be also be created and cached with IRecordDescription.
IRecordDelegates<MyClass> recordDelegates = RecordProviders.Cached.GetRecordDelegates<MyClass>().AssertValue();
CreateRecord delegate constructs record.
MyClass myClass = recordDelegates.RecordCreate!(new object[] { 5 });
.FieldDelegates property contains a field specific delegates
FieldRead<MyClass, int> reader =
(FieldRead<MyClass, int>)
recordDelegates
.FieldDelegates!
.GetByName("value")
.FieldRead!;
// Read
int value = reader(ref myClass);
public class MyClass
{
public int value;
public MyClass(int value)
{
this.value = value;
}
}
Full Example
Full example
using Avalanche.Utilities;
using Avalanche.Utilities.Record;
using Avalanche.Utilities.Provider;
class recorddelegates
{
public static void Run()
{
{
// <01>
IRecordDelegates<MyClass> recordDelegates =
new RecordDelegates<MyClass>
{
RecordCreate = null,
FieldDelegates = new IFieldDelegates[0],
RecordDescription = null
}.SetReadOnly();
// </01>
}
{
// <02>
IRecordDelegates recordDelegates =
RecordDelegates
.Create(typeof(MyClass))
.SetRecordCreate(null)
.SetFieldDelegates(null)
.SetRecordDescription(null)
.SetReadOnly();
// </02>
// <03>
IRecordDelegates clone = recordDelegates.Clone().SetReadOnly();
// </03>
}
{
// Read description
IRecordDescription recordDescription = new RecordDescription()
.Read(typeof(MyClass))
.AssignConstructors()
.ChooseConstruction()
.SetReadOnly();
// <04>
IRecordDelegates<MyClass> recordDelegates = recordDescription.CreateRecordDelegates<MyClass>();
// </04>
}
{
// <05>
IRecordDelegates<MyClass> recordDelegates = RecordProviders.Cached.GetRecordDelegates<MyClass>().AssertValue();
// </05>
// <06>
MyClass myClass = recordDelegates.RecordCreate!(new object[] { 5 });
// </06>
// <07>
FieldRead<MyClass, int> reader =
(FieldRead<MyClass, int>)
recordDelegates
.FieldDelegates!
.GetByName("value")
.FieldRead!;
// Read
int value = reader(ref myClass);
// </07>
}
{
// <08>
// </08>
}
{
// <09>
// </09>
}
}
// <99>
public class MyClass
{
public int value;
public MyClass(int value)
{
this.value = value;
}
}
// </99>
}