DataTypeBase
IDataTypeBase is root interface for datatype descriptions. It carries no fields, but has some expected features.
/// <summary>Contains data type identity</summary>
public interface IDataTypeBase : IGraphComparable, IGraphEqualityComparable, ICloneable, IRecord
{
/// <summary>The interface type.</summary>
[IgnoreDataMember] Type IntfType { get; set; }
/// <summary>Component types</summary>
[IgnoreDataMember] IDataTypeBase[] Components { get; }
}
Third party datatypes inherit IDataTypeBase.
public interface IReferenceType : IDataTypeBase, INominable { }
DataTypeBase is base class which has base features already implemented. Sub-class should override IntfType, getComponents() and InternalValidate.
public class ReferenceType : DataTypeBase, IReferenceType
{
/// <summary>Interface Type</summary>
[IgnoreDataMember] public override Type IntfType { get => typeof(IReferenceType); set => CoreMessages.Instance.BadReadOnly.Throw(); }
/// <summary>Datatype identity</summary>
[IgnoreDataMember] protected IIdentity? name;
/// <summary>Override this to derive components from fields. This is called if <see cref="DataTypeBase.Components"/> is not explicitly assigned.</summary>
protected override IDataTypeBase[] getComponents() => NO_DATATYPEBASE;
/// <summary>Datatype identity</summary>
public IIdentity? Name { get => name; set => this.AssertWritable().name = value; }
/// <summary>Create reference type</summary>
public ReferenceType() : base() { }
/// <summary>Check validation.</summary>
protected override void InternalValidate(ref StructList1<IMessage> errorCodes)
{
// Call base implementation
base.InternalValidate(ref errorCodes);
// Test Name
if (Name == null) errorCodes.Add(DataTypeMessages.Instance.BadFieldNotFound.New("Name"));
}
}
IReferenceType referenceType = new ReferenceType();
Base class handles IComparable, IComparable<IDataTypeBase>, IGraphEqualityComparable, IGraphEqualityComparable<IDataTypeBase>, IGraphComparable and IGraphComparable<IDataTypeBase>.
ReferenceType referenceType1 = new ReferenceType
{
Name = IdentityAccessors.Default.TypeNameWithoutAssembly.Create(typeof(object))
};
ReferenceType referenceType2 = new ReferenceType
{
Name = Identities.CreateNamespace("System").AppendName("Object")
};
WriteLine(referenceType1.Equals(referenceType2)); // "True"
Base class implements ICloneable and IGraphCloneable.
ReferenceType referenceType3 = (ReferenceType)referenceType1.Clone();
Classes derived from base class implement IReadOnly and starts in mutable state.
referenceType3.SetReadOnly();
Extension method for IValidable asserts data type is valid.
ReferenceType referenceType = new ReferenceType();
IMessage statusCode = referenceType.ValidateSingle();
WriteLine(statusCode); // "Name: Not found."
Full Example
Full example
using System;
using System.Runtime.Serialization;
using Avalanche.Accessor;
using Avalanche.DataType;
using Avalanche.Identity;
using Avalanche.Utilities;
using Avalanche.Message;
using static System.Console;
public class datatypebase
{
public static void Run()
{
{
// <01>
IReferenceType referenceType = new ReferenceType();
// </01>
// <02>
referenceType.Name = IdentityAccessors.Default.TypeNameWithoutAssembly.Create(typeof(object));
// </02>
}
{
// <03>
ReferenceType referenceType1 = new ReferenceType
{
Name = IdentityAccessors.Default.TypeNameWithoutAssembly.Create(typeof(object))
};
ReferenceType referenceType2 = new ReferenceType
{
Name = Identities.CreateNamespace("System").AppendName("Object")
};
WriteLine(referenceType1.Equals(referenceType2)); // "True"
// </03>
// <04>
ReferenceType referenceType3 = (ReferenceType)referenceType1.Clone();
// </04>
// <05>
referenceType3.SetReadOnly();
// </05>
}
{
// <11>
ReferenceType referenceType = new ReferenceType();
IMessage statusCode = referenceType.ValidateSingle();
WriteLine(statusCode); // "Name: Not found."
// </11>
}
{
// <12>
// </12>
}
}
// <100>
public interface IReferenceType : IDataTypeBase, INominable { }
// </100>
// <101>
public class ReferenceType : DataTypeBase, IReferenceType
{
/// <summary>Interface Type</summary>
[IgnoreDataMember] public override Type IntfType { get => typeof(IReferenceType); set => CoreMessages.Instance.BadReadOnly.Throw(); }
/// <summary>Datatype identity</summary>
[IgnoreDataMember] protected IIdentity? name;
/// <summary>Override this to derive components from fields. This is called if <see cref="DataTypeBase.Components"/> is not explicitly assigned.</summary>
protected override IDataTypeBase[] getComponents() => NO_DATATYPEBASE;
/// <summary>Datatype identity</summary>
public IIdentity? Name { get => name; set => this.AssertWritable().name = value; }
/// <summary>Create reference type</summary>
public ReferenceType() : base() { }
/// <summary>Check validation.</summary>
protected override void InternalValidate(ref StructList1<IMessage> errorCodes)
{
// Call base implementation
base.InternalValidate(ref errorCodes);
// Test Name
if (Name == null) errorCodes.Add(DataTypeMessages.Instance.BadFieldNotFound.New("Name"));
}
}
// </101>
}