2009-12-30 6 views
1

이 코드를 C#에서 VB로 변환하려고합니다. 타사 도구를 사용하려했지만 성공하지 못했습니다. 어떤 사람이 나를 도울 수 있습니까? 고마워요C#에서 VB로 변환 할 때의 문제

private static string RemoveInvalidHtmlTags(this string text) 
{ 
    return HtmlTagExpression.Replace(text, new MatchEvaluator((Match m) => 
    { 
     if (!ValidHtmlTags.ContainsKey(m.Groups["tag"].Value)) 
      return String.Empty; 

     string generatedTag = String.Empty; 

     System.Text.RegularExpressions.Group tagStart = m.Groups["tag_start"]; 
     System.Text.RegularExpressions.Group tagEnd = m.Groups["tag_end"]; 
     System.Text.RegularExpressions.Group tag = m.Groups["tag"]; 
     System.Text.RegularExpressions.Group tagAttributes = m.Groups["attr"]; 

     generatedTag += (tagStart.Success ? tagStart.Value : "<"); 
     generatedTag += tag.Value; 

     foreach (Capture attr in tagAttributes.Captures) 
     { 
      int indexOfEquals = attr.Value.IndexOf('='); 

      // don't proceed any futurer if there is no equal sign or just an equal sign 
      if (indexOfEquals < 1) 
       continue; 

      string attrName = attr.Value.Substring(0, indexOfEquals); 

      // check to see if the attribute name is allowed and write attribute if it is 
      if (ValidHtmlTags[tag.Value].Contains(attrName)) 
       generatedTag += " " + attr.Value; 
     } 

     // add nofollow to all hyperlinks 
     //if (tagStart.Success && tagStart.Value == "<" && tag.Value.Equals("a", StringComparison.OrdinalIgnoreCase)) 
     // generatedTag += " rel=\"nofollow\""; 

     if (tag.Value.ToString() == "object") 
     { 
      generatedTag += (tagEnd.Success ? " height=\"374\" width=\"416\"" + tagEnd.Value : ">"); 
     } 
     else 
     { 
      generatedTag += (tagEnd.Success ? tagEnd.Value : ">"); 
     } 


     return generatedTag; 
    })); 
} 
+4

어떤 부분에서 문제가 발생합니까? –

+0

일리노이로 컴파일 한 다음 리플렉터를 사용해야하는 이유는 무엇입니까? –

+0

문제는 3 행과 5 행 사이입니다. vb 변환은 다음과 같습니다 - 행 4 열 5 : VB는 명령문 본문이있는 익명 메소드/람다 표현식을 지원하지 않습니다. – vamsivanka

답변

6

이 코드 변환 문제는 당신이 여러 줄 문 시체와 함께 람다 식을 가지고있다 대신 자신의 기능 :

Private Function GetValue(m As Match) As String 
    ....a lot of code 
End Function 

는 그런 다음 RemoveInvalidHtmlTags 코드는 다음과 같이 표시됩니다

Return HtmlTagExpression.Replace(text, new MatchEvaluator(AddressOf GetValue)) 

무료 도구를 사용하여 나머지 코드를 번역 할 수 있습니다.

+0

나는 그것을 시도하고 알려 드리겠습니다. 감사합니다 – vamsivanka

+0

+1. 이것이 OP에서 인용 한 오류 메시지의 의미입니다. "VB는 익명 메서드/문장 본문이있는 람다 식을 지원하지 않습니다." – MarkJ

+0

Meta-Knight, 감사합니다. 솔루션이 효과적이었습니다. – vamsivanka

2

시도해 보셨습니까 free tool? VB9가이 기능을 지원하지 않기 때문에

(Match m) => 
{ 
    ...a lot of code 
} 

, 당신은에 괄호에있는 코드를 삽입 할 수 있습니다 :

+0

예, 저는 같은 도구를 사용하여 변환했습니다. 그러나 나에게 오류를주고있다. – vamsivanka

관련 문제