您最多选择25个主题 主题必须以中文或者字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符
 
 
 
 

70 行
2.0 KiB

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<string, object> 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<string, object> toJson()
{
return new Dictionary<string, object>
{
{"name", name},
{"size", size},
{"uri", uri},
{"height", height},
{"width", width}
};
}
}
}