OneOfAttribute
[OneOf(types)] attribute is a way to define an oneOf type for a referable type. DataTypeRequest<NetOneOf> requests for .net type as one-of. (Avalanche.DataType.Net.dll)
// Create service
IService service = Services.Create(NetTypeHandlers.Instance);
// Create request
DataTypeRequest<NetOneOf> request = new(typeof(IResponse));
// Query
IOneOfType datatype = service.GetRequired<DataTypeRequest<NetOneOf>, IOneOfType>(request);
[OneOf(typeof(Result), typeof(Error))]
public interface IResponse
{
public sealed class Result : IResponse
{
public string? Value;
}
public sealed class Error : IResponse
{
public int ErrorCode;
public string? Message;
}
}
oneoftype+IResponse, docs, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null : IOneOfType ├── Fields[0] = 1 : IFieldType │ └── Value = IResponse+Result, docs, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null : IRecordType │ └── Fields[0] = Value : IFieldType │ └── Value = string : IStringType │ └── Element = byte : IIntegerType └── Fields[1] = 2 : IFieldType └── Value = IResponse+Error, docs, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null : IRecordType ├── Fields[0] = ErrorCode : IFieldType │ └── Value = int32 : IIntegerType └── Fields[1] = Message : IFieldType └── Value = string : IStringType
Full Example
Full example
using Avalanche.DataType;
using Avalanche.Identity;
using Avalanche.Service;
using static System.Console;
public class oneofattribute
{
public static void Run()
{
{
// <04>
// Create service
IService service = Services.Create(NetTypeHandlers.Instance);
// Create request
DataTypeRequest<NetOneOf> request = new(typeof(IResponse));
// Query
IOneOfType datatype = service.GetRequired<DataTypeRequest<NetOneOf>, IOneOfType>(request);
// </04>
// Print
WriteLine(datatype.PrintTree());
}
}
// <100>
[OneOf(typeof(Result), typeof(Error))]
public interface IResponse
{
public sealed class Result : IResponse
{
public string? Value;
}
public sealed class Error : IResponse
{
public int ErrorCode;
public string? Message;
}
}
// </100>
}