Read-Only List unable to copy if property setter is private.
Environment:
Windows 10, 64-bit
OpenTAP 9.12.1
Editor 9.12.0
Issue
The Example below is a combination of 'List of Objects Example' and 'Read-Only List Example'. It demonstrates how a Read-only list can be embedded in a list of objects and also that it can be copied when a row in the list of objects is copied.
- Demo 1 shows
- The list of objects can have any number of rows.
- The read-only list has a fixed number of rows which is the desired behaviour.
- The read-only list is copied when the row in the list of objects is copied.
- Demo 2 show that all the properties of the read-only list are still editable.
- Issue: It does not seem possible to create read-only properties and to also have the copy behaviour using the code below.
Question: Is it possible to have read-only properties in the read-only list and also have the read-only list be copied when it is embedded in a list of objects?
Demo 1:
Demo 2:
Code:
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using OpenTap;
namespace OpenTap.Plugins.PluginDevelopment
{
public enum Set
{
[Display("Set 1")] Set1,
[Display("Set 2")] Set2,
[Display("Set 3")] Set3
}
public enum Option
{
[Display("Option 1")] Option1,
[Display("Option 2")] Option2,
[Display("Option 3")] Option3
}
[Display("Read-Only List Example2", "Demonstrates how to use a list where items cannot be added or removed." +
" Elements themselves can be changed, but they are also mostly read-only.",
Groups: new[] { "Examples", "Plugin Development", "Advanced Examples" })]
public class ReadOnlyListExample2 : TestStep
{
public class Obj
{
[Display("Set Id", Order: 10.1)]
public Set Set { get; set; }
[Display("Elements", Order: 10.2)]
public IReadOnlyList<ReadOnlyListElement2> Elementsnew { get; set; } = new List<ReadOnlyListElement2>
{
new ReadOnlyListElement2 { Option = Option.Option1, Note = "Write notes here.."},
new ReadOnlyListElement2 { Option = Option.Option2, Note = "Write notes here.."},
new ReadOnlyListElement2 { Option = Option.Option3, Note = "Write notes here.." },
}.AsReadOnly();
}
public class ReadOnlyListElement2
{
[Browsable(true)]
[Display("Option", Order: 10.1)]
public Option Option { get; set; }
[Display("Comment", Order: 10.2)]
public string Note { get; set; }
}
[Display("List of obj")]
public List<Obj> LisOfObj { get; set; } = new List<Obj>();
public override void Run()
{
}
}
}
Edited by Jason Hicks