我有一些C#代碼添加到現有的VB.net項目。 C#類被設計爲一個html解析器C#VBNET轉換問題
已經初步使用在線轉換器,並且能夠獲得大部分類的工作,但下面的部分仍然無法正常工作。不幸的是我缺乏解決這個問題的知識。
我張貼整篇文章,但如果有人可以澄清第一對夫婦,我認爲這就夠了。 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;
}
})},
};
對不起,我正在使用VS2010,感謝您的信息。 – pophatis
@pophatis增加了一些例子,然後 –
謝謝J我能夠跨過這個障礙,並進一步。能夠解決一些其他問題,只是很高興得到一些編碼完成和進步。因此,沒有得到周圍感謝你遠行,謝謝! – pophatis