既存のVB.netプロジェクトに追加するC#コードがいくつかあります。C#クラスはhtmlパーサーとして設計されています
最初にオンラインコンバーターを使用し、クラスのほとんどを機能させることができましたが、以下の部分はまだ機能していません。残念ながら、これを修正するための知識が不足しています。
全体を投稿していますが、最初の数行を誰かが明確にできれば、それで十分だと思います。AttributeNameValuePairは、属性を保持する別個のクラスです。
さらに下にいくつかのインライン関数が使用されていますが、その例もありがたいです。または、これらを個別の関数として作成し、内部に参照のみを残す方が簡単でしょうか?
よろしくお願いします。
private readonly Dictionary<string, Action<DocumentModel, IEnumerable<AttributeNameValuePair>>> commandsDictionary = new Dictionary<string, Action<DocumentModel, IEnumerable<AttributeNameValuePair>>>()
{
{ "b", new Action<DocumentModel, IEnumerable<AttributeNameValuePair>>((doc, args) => GetLastRun(doc).CharacterFormat.Bold = true) },
{ "i", new Action<DocumentModel, IEnumerable<AttributeNameValuePair>>((doc, args) => GetLastRun(doc).CharacterFormat.Italic = true) },
{ "u", new Action<DocumentModel, IEnumerable<AttributeNameValuePair>>((doc, args) => GetLastRun(doc).CharacterFormat.UnderlineStyle = UnderlineType.Single) },
{ "strike", new Action<DocumentModel, IEnumerable<AttributeNameValuePair>>((doc, args) => GetLastRun(doc).CharacterFormat.Strikethrough = true) },
{ "sub", new Action<DocumentModel, IEnumerable<AttributeNameValuePair>>((doc, args) => GetLastRun(doc).CharacterFormat.Subscript = true) },
{ "sup", new Action<DocumentModel, IEnumerable<AttributeNameValuePair>>((doc, args) => GetLastRun(doc).CharacterFormat.Superscript = true) },
{ "div", new Action<DocumentModel, IEnumerable<AttributeNameValuePair>>((doc, args) =>
{
foreach(var arg in args)
{
if(arg.AttributeName == "align")
{
HorizontalAlignment align;
switch(arg.AttributeValue)
{
case "center":
align = HorizontalAlignment.Center;
break;
case "right":
align = HorizontalAlignment.Right;
break;
case "justify":
align = HorizontalAlignment.Justify;
break;
default:
align = HorizontalAlignment.Left;
break;
}
}
}
})},
{ "br", new Action<DocumentModel, IEnumerable<AttributeNameValuePair>>((doc, args) => doc.Sections[0].Blocks.Add(new Paragraph(doc))) },
{ "span", new Action<DocumentModel, IEnumerable<AttributeNameValuePair>>((doc, args) => {})},
{ "font", new Action<DocumentModel, IEnumerable<AttributeNameValuePair>>((doc, args) =>
{
foreach(AttributeNameValuePair arg in args)
{
int? size = null;
string fontName = null;
// Some dummy values.
if (arg.AttributeName == "size")
size = 10 + 3 * int.Parse(arg.AttributeValue);
else if (arg.AttributeName == "face")
fontName = arg.AttributeValue.Split(',').First();
var lastFormat = GetLastRun(doc).CharacterFormat;
if (size.HasValue)
lastFormat.Size = size.Value;
if (fontName != null)
lastFormat.FontName = fontName;
}
})},
};