using System; using System.Collections.Generic; namespace ChatComponents { public class PartialImage { /// The name of the file public readonly string name; /// Size of the file in bytes public readonly int size; /// The file source (either a remote URL or a local resource) public readonly string uri; public readonly float? width; public readonly float? height; /// Creates a partial file message with all variables file can have. /// Use [FileMessage] to create a full message. /// You can use [FileMessage.fromPartial] constructor to create a full /// message from a partial one. public PartialImage( string name, int size, string uri, float? height = null, float? width = null ) { this.name = name; this.size = size; this.uri = uri; this.height = height; this.width = width; } /// Creates a partial file message from a map (decoded JSON). public PartialImage fromJson(Dictionary json) { return new PartialImage( name: json["name"] as string, size: Convert.ToInt32(json["size"]), uri: json["uri"] as string, height: Convert.ToDouble(json["height"]) is float ? (float) Convert.ToDouble(json["height"]) : 0f, width: Convert.ToDouble(json["width"]) is float ? (float) Convert.ToDouble(json["width"]) : 0f ); } /// Converts a partial file message to the map representation, encodable to JSON. private Dictionary toJson() { return new Dictionary { {"name", name}, {"size", size}, {"uri", uri}, {"height", height}, {"width", width} }; } } }