IRecordDescription
IRecordDescription is description of record (namespace Avalanche.Utilities.Record).
/// <summary>Record description</summary>
public interface IRecordDescription : IAnnotable
{
/// <summary>Record name, typically as <see cref="string"/> or <![CDATA[IIdentity]]>.</summary>
object Name { get; set; }
/// <summary>Record type</summary>
Type Type { get; set; }
/// <summary>All record constructors</summary>
IConstructorDescription[]? Constructors { get; set; }
/// <summary>Describes record deconstructor such as <see cref="MethodInfo"/>, <see cref="Delegate"/>, <![CDATA[IWriterBase]]></summary>
object? Deconstructor { get; set; }
/// <summary>Fields</summary>
IFieldDescription[] Fields { get; set; }
/// <summary>Selected construction strategy, typically <see cref="IConstructionDescription"/>.</summary>
object? Construction { get; set; }
}
RecordDescription is the default implementation.
IRecordDescription recordDescription = new RecordDescription
{
Name = "",
Type = typeof(MyClass),
Constructors = new IConstructorDescription[0],
Deconstructor = null,
Fields = new IFieldDescription[0],
Annotations = new object[0],
Construction = null
}.SetReadOnly();
There is a setter method for each field.
IRecordDescription recordDescription =
new RecordDescription()
.SetName("")
.SetType(typeof(MyClass))
.SetConstructors(new IConstructorDescription[0])
.SetDeconstructor(null)
.SetFields(new IFieldDescription[0])
.SetAnnotations(new object[0])
.SetConstruction(null)
.SetReadOnly();
.Clone() makes a copy.
IRecordDescription clone = recordDescription.Clone().SetReadOnly();
.Read() reads and assigns name, type, fields and annotations. .AssignConstructors() reads and assigns constructors. .ChooseConstruction() tries to assign best construction strategy.
// Read info
IRecordDescription recordDescription = new RecordDescription()
.Read(typeof(MyClass))
.AssignConstructors()
.ChooseConstruction()
.SetReadOnly();
RecordDescription.Create is IProvider<Type, IRecordDescription> that creates new description instance.
RecordDescription.Cached is IProvider<Type, IRecordDescription> that creates and caches with weak Type key.
[IgnoreDataMember] indicates that fields and properties that are not intended data members.
[DataMember(Order)] forces fields and properites into explicit order.IRecordDescription recordDescription = RecordDescription.Create[typeof(MyClass)];
IRecordDescription recordDescription = RecordDescription.Cached[typeof(MyClass)];
public class MyClass
{
[IgnoreDataMember]
public bool HasCache => false;
[DataMember(Order = 1)]
public readonly int value;
public MyClass(int value)
{
this.value = value;
}
}
Full Example
Full example
using System.Runtime.Serialization;
using Avalanche.Utilities;
using Avalanche.Utilities.Record;
class recorddescription
{
public static void Run()
{
{
// <01>
IRecordDescription recordDescription = new RecordDescription
{
Name = "",
Type = typeof(MyClass),
Constructors = new IConstructorDescription[0],
Deconstructor = null,
Fields = new IFieldDescription[0],
Annotations = new object[0],
Construction = null
}.SetReadOnly();
// </01>
}
{
// <02>
IRecordDescription recordDescription =
new RecordDescription()
.SetName("")
.SetType(typeof(MyClass))
.SetConstructors(new IConstructorDescription[0])
.SetDeconstructor(null)
.SetFields(new IFieldDescription[0])
.SetAnnotations(new object[0])
.SetConstruction(null)
.SetReadOnly();
// </02>
// <03>
IRecordDescription clone = recordDescription.Clone().SetReadOnly();
// </03>
}
{
// <04>
// Read info
IRecordDescription recordDescription = new RecordDescription()
.Read(typeof(MyClass))
.AssignConstructors()
.ChooseConstruction()
.SetReadOnly();
// </04>
}
{
// <05>
IRecordDescription recordDescription = RecordDescription.Create[typeof(MyClass)];
// </05>
}
{
// <06>
IRecordDescription recordDescription = RecordDescription.Cached[typeof(MyClass)];
// </06>
}
}
// <99>
public class MyClass
{
[IgnoreDataMember]
public bool HasCache => false;
[DataMember(Order = 1)]
public readonly int value;
public MyClass(int value)
{
this.value = value;
}
}
// </99>
}