txt2bib/Records.cs

62 lines
2.2 KiB
C#

using System;
using System.Configuration;
using System.Linq;
using System.Text.RegularExpressions;
namespace Txt2Bib.Records
{
public interface IBib { public string ToString(); }
public record class ArticleBib : IBib
{
public string Type { get; init; } = "article";
public string[] Author { get; set; } = { "Gianni e Pinotto" };
public string Title { get; set; } = "";
public string Journal { get; set; } = "";
public ushort Year { get; set; } = 1950;
public ushort Volume { get; set; } = 1;
public byte? Issue { get; set; } = null;
public ushort FirstPage { get; set; } = 1;
public ushort LastPage { get; set; } = 1;
public string Doi { get; set; } = "";
public string Url { get; set; } = "";
public override string ToString()
{
return $"@{Type}" + "{" +$"{Author[0][..5]}_{Year},\n" +
$"\tauthor = \"{string.Join(" and ", Author)}\",\n" +
$"\ttitle = {{{Title}}},\n" +
$"\tjournal = \"{Journal}\",\n" +
$"\tyear = \"{Year}\",\n" +
$"\tvolume = \"{Volume}\",\n" +
$"\tnumber = \"{Issue}\",\n" +
$"\tpages = \"{FirstPage}--{LastPage}\",\n" +
$"\tdoi = \"{Doi}\",\n" +
$"\turl = \"{Url}\",\n" +
"}\n";
}
}
public record class BookBib : IBib
{
public string Type { get; init; } = "book";
public string[] Author { get; set; } = { "Gianni e Pinotto" };
public string Title { get; set; } = "";
public string Publisher { get; set; } = "";
public string Place { get; set; } = "";
public string Url { get; set; } = "";
public ushort Year { get; set; } = 1950;
public override string ToString()
{
return $"@{Type}" + "{" +$"{Author[0][..5]}_{Year},\n" +
$"\tauthor = \"{string.Join(" and", Author)}\",\n" +
$"\ttitle = \"{Title}\",\n" +
$"\tpublisher = \"{Publisher}\",\n" +
$"\taddress = \"{Place}\",\n" +
$"\tyear = \"{Year}\",\n" +
$"\turl = \"{Url}\",\n" +
"}\n";
}
}
}