namespace OpenTap { /// Marks that the annotated object is a picture. public interface IPictureAnnotation : IAnnotation { /// /// Specifies the path to the picture /// string Source { get; } /// /// Specifies a description of the picture. Can be used in non-gui applications as an alternative to showing the picture. /// 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()?.Value; if (mem is IPicture picture) { Source = picture.Source; Description = picture.Description; } } public void Write(object source) { var objSource = annotation.Get(); 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().Value = mem; } } /// /// Represents a picture resource /// public interface IPicture { /// /// Specifies the path to the picture /// string Source { get; } /// /// Specifies a description of the picture /// string Description { get; } } /// /// Represents a picture resource /// public class Picture : IPicture { /// Specifies the path to the picture. [FilePath] [Display("Picture File")] public string Source { get; set; } /// Specifies a description of the picture. public string Description { get; set; } /// Returns true if the two pictures are the same with respect to Source and Description. public override bool Equals(object obj) => obj is Picture pic && pic.Source == Source && pic.Description == Description; /// Calculates a hash based on source and description. public override int GetHashCode() => (int)(0xaacd012 + (Description?.GetHashCode() ?? 0) * 0x801423bb + (Source?.GetHashCode() ?? 0) * 0xf00b0834); } }