// the Free Software Foundation, Inc., 51 Franklin Street - Fifth Floor,
// Boston, MA 02110-1301, USA.
+#nullable enable
+
using System;
using System.Drawing;
using System.IO;
bool IsImage { get; }
/// <summary>
+ /// 代替テキスト (アップロード先が対応している必要がある)
+ /// </summary>
+ string? AltText { get; set; }
+
+ /// <summary>
/// 表示用の MemoryImage を作成する
/// </summary>
/// <remarks>
public class FileMediaItem : IMediaItem
{
public FileInfo FileInfo { get; }
+ public string? AltText { get; set; }
public FileMediaItem(string path)
- {
- this.FileInfo = new FileInfo(path);
- }
+ => this.FileInfo = new FileInfo(path);
public FileMediaItem(FileInfo fileInfo)
: this(fileInfo.FullName)
}
public string Path
- {
- get { return this.FileInfo.FullName; }
- }
+ => this.FileInfo.FullName;
public string Name
- {
- get { return this.FileInfo.Name; }
- }
+ => this.FileInfo.Name;
public string Extension
- {
- get { return this.FileInfo.Extension; }
- }
+ => this.FileInfo.Extension;
public bool Exists
- {
- get { return this.FileInfo.Exists; }
- }
+ => this.FileInfo.Exists;
public long Size
- {
- get { return this.FileInfo.Length; }
- }
+ => this.FileInfo.Length;
public bool IsImage
{
public MemoryImage CreateImage()
{
- using (var fs = this.FileInfo.OpenRead())
- {
- return MemoryImage.CopyFromStream(fs);
- }
+ using var fs = this.FileInfo.OpenRead();
+ return MemoryImage.CopyFromStream(fs);
}
public Stream OpenRead()
- {
- return this.FileInfo.OpenRead();
- }
+ => this.FileInfo.OpenRead();
public void CopyTo(Stream stream)
{
- using (var fs = this.FileInfo.OpenRead())
- {
- fs.CopyTo(stream);
- }
+ using var fs = this.FileInfo.OpenRead();
+ fs.CopyTo(stream);
}
}
{
public const string PathPrefix = "<>MemoryImage://";
private static int _fileNumber = 0;
-
- private bool _disposed = false;
-
private readonly MemoryImage _image;
+ public bool IsDisposed { get; private set; } = false;
+
public MemoryImageMediaItem(MemoryImage image)
{
- if (image == null)
- throw new ArgumentNullException(nameof(image));
-
- this._image = image;
+ this._image = image ?? throw new ArgumentNullException(nameof(image));
var num = Interlocked.Increment(ref _fileNumber);
this.Path = PathPrefix + num + this._image.ImageFormatExt;
}
public string Path { get; }
+ public string? AltText { get; set; }
public string Name
- {
- get { return this.Path.Substring(PathPrefix.Length); }
- }
+ => this.Path.Substring(PathPrefix.Length);
public string Extension
- {
- get { return this._image.ImageFormatExt; }
- }
+ => this._image.ImageFormatExt;
public bool Exists
- {
- get { return this._image != null; }
- }
+ => this._image != null;
public long Size
- {
- get { return this._image.Stream.Length; }
- }
+ => this._image.Stream.Length;
public bool IsImage
- {
- get { return true; }
- }
-
- public bool IsDisposed
- {
- get { return this._disposed; }
- }
+ => true;
public MemoryImage CreateImage()
- {
- return this._image.Clone();
- }
+ => this._image.Clone();
public Stream OpenRead()
{
- MemoryStream memstream = null;
+ MemoryStream? memstream = null;
try
{
// コピーを作成する
}
public void CopyTo(Stream stream)
- {
- this._image.Stream.WriteTo(stream);
- }
+ => this._image.Stream.WriteTo(stream);
protected virtual void Dispose(bool disposing)
{
- if (this._disposed) return;
+ if (this.IsDisposed) return;
if (disposing)
{
this._image.Dispose();
}
- this._disposed = true;
+ this.IsDisposed = true;
}
public void Dispose()
}
~MemoryImageMediaItem()
- {
- this.Dispose(false);
- }
+ => this.Dispose(false);
}
}