Hi,
I want to create a custom annotation to get a drop down of values and select one. Simular as selecting a Instrument in a TestStep. My example code shows a drop down in the Editor, but selecting doesn’t work.
Any ideas how to solve/implement this?
namespace AvailableValuesAnnotationDemo
{
public class MyInt
{
public int Value { get; set; }
public override string ToString()
{
return Value.ToString();
}
}
public class MyIntAnnotation : IAvailableValuesAnnotation, IStringReadOnlyValueAnnotation
{
AnnotationCollection annotations;
public MyIntAnnotation(AnnotationCollection annotations)
{
this.annotations = annotations;
}
public IEnumerable AvailableValues
{
get
{
for (int i = 0; i < 10; i++)
yield return new MyInt() { Value = i + 1 };
}
}
public string Value
{
get => (annotations.Get<IObjectValueAnnotation>()?.Value as MyInt)?.ToString();
set => throw new NotSupportedException("not supported");
}
}
public class MyIntAnnotator : IAnnotator
{
public double Priority => 5;
public void Annotate(AnnotationCollection annotations)
{
var member = annotations.Get<IMemberAnnotation>()?.Member;
if (member == null)
return;
if (member.TypeDescriptor == TypeData.FromType(typeof(MyInt)) == false) return;
annotations.Add(new MyIntAnnotation(annotations));
}
}
}