diff --git a/src/AddIns/BackendBindings/Python/PythonBinding/Project/Src/NRefactoryToPythonConverter.cs b/src/AddIns/BackendBindings/Python/PythonBinding/Project/Src/NRefactoryToPythonConverter.cs
index 4b59e60844..fe463eea8f 100644
--- a/src/AddIns/BackendBindings/Python/PythonBinding/Project/Src/NRefactoryToPythonConverter.cs
+++ b/src/AddIns/BackendBindings/Python/PythonBinding/Project/Src/NRefactoryToPythonConverter.cs
@@ -1118,9 +1118,6 @@ namespace ICSharpCode.PythonBinding
return null;
}
- ///
- /// Converts a unary operator expression to a code dom expression.
- ///
public object VisitUnaryOperatorExpression(UnaryOperatorExpression unaryOperatorExpression, object data)
{
switch (unaryOperatorExpression.Op) {
@@ -1209,10 +1206,6 @@ namespace ICSharpCode.PythonBinding
return null;
}
- ///
- /// Converts an NRefactory MemberReferenceExpression to a
- /// code dom's CodeFieldReferenceExpression.
- ///
public object VisitMemberReferenceExpression(MemberReferenceExpression memberReferenceExpression, object data)
{
memberReferenceExpression.TargetObject.AcceptVisitor(this, data);
@@ -1387,10 +1380,13 @@ namespace ICSharpCode.PythonBinding
{
IdentifierExpression identifierExpression = foreachStatement.Expression as IdentifierExpression;
InvocationExpression invocationExpression = foreachStatement.Expression as InvocationExpression;
+ MemberReferenceExpression memberRefExpression = foreachStatement.Expression as MemberReferenceExpression;
if (identifierExpression != null) {
Append(identifierExpression.Identifier);
} else if (invocationExpression != null) {
invocationExpression.AcceptVisitor(this, null);
+ } else if (memberRefExpression != null) {
+ memberRefExpression.AcceptVisitor(this, null);
}
}
diff --git a/src/AddIns/BackendBindings/Python/PythonBinding/Test/Converter/ForeachConversionTestFixture.cs b/src/AddIns/BackendBindings/Python/PythonBinding/Test/Converter/ForeachConversionTestFixture.cs
index 64c95da284..aeecc1fd16 100644
--- a/src/AddIns/BackendBindings/Python/PythonBinding/Test/Converter/ForeachConversionTestFixture.cs
+++ b/src/AddIns/BackendBindings/Python/PythonBinding/Test/Converter/ForeachConversionTestFixture.cs
@@ -18,33 +18,65 @@ namespace PythonBinding.Tests.Converter
[TestFixture]
public class ForeachConversionTestFixture
{
- string csharp = "class Foo\r\n" +
+ string intArrayCode = "class Foo\r\n" +
"{\r\n" +
- "\tpublic int GetCount(int[] items)\r\n" +
- "\t{\r\n" +
- "\t\tint count = 0;\r\n" +
- "\t\tforeach (int item in items) {\r\n" +
- "\t\t\tcount++;\r\n" +
- "\t\t}\r\n" +
- "\t\treturn count;\r\n" +
- "\t}\r\n" +
+ " public int GetCount(int[] items)\r\n" +
+ " {\r\n" +
+ " int count = 0;\r\n" +
+ " foreach (int item in items) {\r\n" +
+ " count++;\r\n" +
+ " }\r\n" +
+ " return count;\r\n" +
+ " }\r\n" +
"}";
-
+
+ string dictionaryCode = "class Foo\r\n" +
+ "{\r\n" +
+ " public void DisplayItems()\r\n" +
+ " {\r\n" +
+ " Dictionary record = new Dictionary();\r\n" +
+ " record.Add(\"a\", \"b\");\r\n" +
+ " record.Add(\"c\", \"d\");\r\n" +
+ " foreach (string key in record.Keys) {\r\n" +
+ " Console.WriteLine(\"Key: \" + key);\r\n" +
+ " }\r\n" +
+ " }\r\n" +
+ "}";
+
[Test]
- public void ConvertedPythonCode()
+ public void ConvertedIntArrayCode()
{
NRefactoryToPythonConverter converter = new NRefactoryToPythonConverter(SupportedLanguage.CSharp);
- string code = converter.Convert(csharp);
+ converter.IndentString = " ";
+ string code = converter.Convert(intArrayCode);
string expectedCode = "class Foo(object):\r\n" +
- "\tdef GetCount(self, items):\r\n" +
- "\t\tcount = 0\r\n" +
- "\t\tenumerator = items.GetEnumerator()\r\n" +
- "\t\twhile enumerator.MoveNext():\r\n" +
- "\t\t\titem = enumerator.Current\r\n" +
- "\t\t\tcount += 1\r\n" +
- "\t\treturn count";
+ " def GetCount(self, items):\r\n" +
+ " count = 0\r\n" +
+ " enumerator = items.GetEnumerator()\r\n" +
+ " while enumerator.MoveNext():\r\n" +
+ " item = enumerator.Current\r\n" +
+ " count += 1\r\n" +
+ " return count";
Assert.AreEqual(expectedCode, code);
}
+
+ [Test]
+ public void ConvertedDictionaryCode()
+ {
+ NRefactoryToPythonConverter converter = new NRefactoryToPythonConverter(SupportedLanguage.CSharp);
+ converter.IndentString = " ";
+ string code = converter.Convert(dictionaryCode);
+ string expectedCode = "class Foo(object):\r\n" +
+ " def DisplayItems(self):\r\n" +
+ " record = Dictionary[str, str]()\r\n" +
+ " record.Add(\"a\", \"b\")\r\n" +
+ " record.Add(\"c\", \"d\")\r\n" +
+ " enumerator = record.Keys.GetEnumerator()\r\n" +
+ " while enumerator.MoveNext():\r\n" +
+ " key = enumerator.Current\r\n" +
+ " Console.WriteLine(\"Key: \" + key)";
+ Assert.AreEqual(expectedCode, code);
+ }
}
}
diff --git a/src/AddIns/BackendBindings/Python/PythonBinding/Test/Converter/ForeachConversionWithMethodCallTestFixture.cs b/src/AddIns/BackendBindings/Python/PythonBinding/Test/Converter/ForeachConversionWithMethodCallTestFixture.cs
index afdafd1e42..94afc501de 100644
--- a/src/AddIns/BackendBindings/Python/PythonBinding/Test/Converter/ForeachConversionWithMethodCallTestFixture.cs
+++ b/src/AddIns/BackendBindings/Python/PythonBinding/Test/Converter/ForeachConversionWithMethodCallTestFixture.cs
@@ -25,18 +25,7 @@ namespace PythonBinding.Tests.Converter
" }\r\n" +
" }\r\n" +
"}";
-
- string intCode = "class Foo\r\n" +
- "{\r\n" +
- " public void PrintIntegers(int[] items)\r\n" +
- " {\r\n" +
- " foreach (int i in items)\r\n" +
- " {\r\n" +
- " Console.WriteLine(i);\r\n" +
- " }\r\n" +
- " }\r\n" +
- "}";
-
+
[Test]
public void ConvertedEnvironmentSpecialFolderCode()
{
@@ -50,21 +39,6 @@ namespace PythonBinding.Tests.Converter
" folder = enumerator.Current\r\n" +
" Console.WriteLine(\"{0}={1}\\n\", folder, Environment.GetFolderPath(folder))";
Assert.AreEqual(expectedCode, code);
- }
-
- [Test]
- public void ConvertedIntCode()
- {
- NRefactoryToPythonConverter converter = new NRefactoryToPythonConverter(SupportedLanguage.CSharp);
- converter.IndentString = " ";
- string code = converter.Convert(intCode);
- string expectedCode = "class Foo(object):\r\n" +
- " def PrintIntegers(self, items):\r\n" +
- " enumerator = items.GetEnumerator()\r\n" +
- " while enumerator.MoveNext():\r\n" +
- " i = enumerator.Current\r\n" +
- " Console.WriteLine(i)";
- Assert.AreEqual(expectedCode, code);
}
}
}