chr
2026-04-05 fe750b791d5b517cc4e9bc8e99a9a75139a0cfba
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
 
namespace OpenTap
{
    /// <summary> Marks that the annotated object is a picture. </summary>
    public interface IPictureAnnotation : IAnnotation
    {
        /// <summary>
        /// Specifies the path to the picture
        /// </summary>
        string Source { get; }
        
        /// <summary>
        /// Specifies a description of the picture. Can be used in non-gui applications as an alternative to showing the picture.
        /// </summary>
        string Description { get; }
    }
 
    class PictureAnnotation : IPictureAnnotation, IOwnedAnnotation
    {
        readonly AnnotationCollection annotation;
 
        public PictureAnnotation(AnnotationCollection annotation)
        {
            this.annotation = annotation;
        }
 
        public string Source { get; set; }
        public string Description { get; set; }
 
        public void Read(object source)
        {
            if (source == null) return;
            var mem = annotation.Get<IObjectValueAnnotation>()?.Value;
            if (mem is IPicture picture)
            {
                Source = picture.Source;
                Description = picture.Description;
            }
        }
 
        public void Write(object source)
        {
            var objSource = annotation.Get<IObjectValueAnnotation>();
            if (objSource == null) return;
            var mem = objSource?.Value;
            if (mem == null)
                mem = new Picture();
            if (mem is Picture picture)
            {
                picture.Source = Source;
                picture.Description = Description;
            }
 
            if (mem != null)
                annotation.Get<IObjectValueAnnotation>().Value = mem;
        }
    }
 
    /// <summary>
    /// Represents a picture resource
    /// </summary>
    public interface IPicture
    {
        /// <summary>
        /// Specifies the path to the picture
        /// </summary>
        string Source { get; }
 
        /// <summary>
        /// Specifies a description of the picture
        /// </summary>
        string Description { get; }
    }
 
    /// <summary>
    /// Represents a picture resource
    /// </summary>
    public class Picture : IPicture
    {
        /// <summary> Specifies the path to the picture. </summary>
        [FilePath]
        [Display("Picture File")]
        public string Source { get; set; }
        
        
        /// <summary> Specifies a description of the picture. </summary>
        public string Description { get; set; }
 
        /// <summary> Returns true if the two pictures are the same with respect to Source and Description. </summary>
        public override bool Equals(object obj) =>
            obj is Picture pic && pic.Source == Source && pic.Description == Description;
 
        /// <summary> Calculates a hash based on source and description. </summary>
        public override int GetHashCode() => (int)(0xaacd012
                                                   + (Description?.GetHashCode() ?? 0) * 0x801423bb
                                                   + (Source?.GetHashCode() ?? 0) * 0xf00b0834);
    }
}