|
|
|
@ -17,6 +17,8 @@
@@ -17,6 +17,8 @@
|
|
|
|
|
// DEALINGS IN THE SOFTWARE.
|
|
|
|
|
|
|
|
|
|
using System; |
|
|
|
|
using System.Collections; |
|
|
|
|
using System.Collections.Generic; |
|
|
|
|
using ICSharpCode.NRefactory.Semantics; |
|
|
|
|
using ICSharpCode.NRefactory.TypeSystem; |
|
|
|
|
using NUnit.Framework; |
|
|
|
@ -61,11 +63,152 @@ namespace ICSharpCode.NRefactory.CSharp.Resolver
@@ -61,11 +63,152 @@ namespace ICSharpCode.NRefactory.CSharp.Resolver
|
|
|
|
|
string program = @"using System;
|
|
|
|
|
class TestClass { |
|
|
|
|
static void Main() { |
|
|
|
|
var contact = {id = 54321}; |
|
|
|
|
$contact$.ToString(); |
|
|
|
|
} }";
|
|
|
|
|
var contact = {id = 54321}; |
|
|
|
|
$contact$.ToString(); |
|
|
|
|
} }";
|
|
|
|
|
var lrr = Resolve<LocalResolveResult>(program); |
|
|
|
|
Assert.AreEqual(SpecialType.UnknownType, lrr.Type); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
[Test] |
|
|
|
|
public void Foreach_InferFromArrayType() |
|
|
|
|
{ |
|
|
|
|
string program = @"using System;
|
|
|
|
|
class TestClass { |
|
|
|
|
static void Method(int[] arr) { |
|
|
|
|
foreach ($var$ x in arr) {} |
|
|
|
|
} }";
|
|
|
|
|
var rr = Resolve<TypeResolveResult>(program); |
|
|
|
|
Assert.AreEqual("System.Int32", rr.Type.ReflectionName); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
[Test] |
|
|
|
|
public void Foreach_InferFromDynamic() |
|
|
|
|
{ |
|
|
|
|
string program = @"using System;
|
|
|
|
|
class TestClass { |
|
|
|
|
static void Method(dynamic c) { |
|
|
|
|
foreach ($var$ x in c) {} |
|
|
|
|
} }";
|
|
|
|
|
var rr = Resolve<TypeResolveResult>(program); |
|
|
|
|
Assert.AreEqual(TypeKind.Dynamic, rr.Type.Kind); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
[Test] |
|
|
|
|
public void Foreach_InferFromListOfInt() |
|
|
|
|
{ |
|
|
|
|
string program = @"using System;
|
|
|
|
|
using System.Collections.Generic; |
|
|
|
|
class TestClass { |
|
|
|
|
static void Method(List<int> c) { |
|
|
|
|
foreach ($var$ x in c) {} |
|
|
|
|
} }";
|
|
|
|
|
var rr = Resolve<TypeResolveResult>(program); |
|
|
|
|
Assert.AreEqual("System.Int32", rr.Type.ReflectionName); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
[Test] |
|
|
|
|
public void Foreach_InferFromICollectionOfInt() |
|
|
|
|
{ |
|
|
|
|
string program = @"using System;
|
|
|
|
|
using System.Collections.Generic; |
|
|
|
|
class TestClass { |
|
|
|
|
static void Method(ICollection<int> c) { |
|
|
|
|
foreach ($var$ x in c) {} |
|
|
|
|
} }";
|
|
|
|
|
var rr = Resolve<TypeResolveResult>(program); |
|
|
|
|
Assert.AreEqual("System.Int32", rr.Type.ReflectionName); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
[Test] |
|
|
|
|
public void Foreach_InferFromCustomCollection_WithoutIEnumerable() |
|
|
|
|
{ |
|
|
|
|
string program = @"using System;
|
|
|
|
|
using System.Collections.Generic; |
|
|
|
|
class TestClass { |
|
|
|
|
static void Method(CustomCollection c) { |
|
|
|
|
foreach ($var$ x in c) {} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
class CustomCollection { |
|
|
|
|
public MyEnumerator GetEnumerator() {} |
|
|
|
|
public struct MyEnumerator { |
|
|
|
|
public string Current { get { return null; } } |
|
|
|
|
public bool MoveNext() { return false; } |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
";
|
|
|
|
|
var rr = Resolve<TypeResolveResult>(program); |
|
|
|
|
Assert.AreEqual("System.String", rr.Type.ReflectionName); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
[Test] |
|
|
|
|
public void Foreach_InferFromCustomCollection_WithIEnumerableAndPublicGetEnumerator() |
|
|
|
|
{ |
|
|
|
|
string program = @"using System;
|
|
|
|
|
using System.Collections.Generic; |
|
|
|
|
class TestClass { |
|
|
|
|
static void Method(CustomCollection c) { |
|
|
|
|
foreach ($var$ x in c) {} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
class CustomCollection : IEnumerable<int> { |
|
|
|
|
public MyEnumerator GetEnumerator() {} |
|
|
|
|
public struct MyEnumerator { |
|
|
|
|
public string Current { get { return null; } } |
|
|
|
|
public bool MoveNext() { return false; } |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
";
|
|
|
|
|
var rr = Resolve<TypeResolveResult>(program); |
|
|
|
|
Assert.AreEqual("System.String", rr.Type.ReflectionName); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
[Test] |
|
|
|
|
public void Foreach_InferFromCustomCollection_WithIEnumerableAndInternalGetEnumerator() |
|
|
|
|
{ |
|
|
|
|
string program = @"using System;
|
|
|
|
|
using System.Collections.Generic; |
|
|
|
|
class TestClass { |
|
|
|
|
static void Method(CustomCollection c) { |
|
|
|
|
foreach ($var$ x in c) {} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
class CustomCollection : IEnumerable<int> { |
|
|
|
|
internal MyEnumerator GetEnumerator() {} |
|
|
|
|
public struct MyEnumerator { |
|
|
|
|
public string Current { get { return null; } } |
|
|
|
|
public bool MoveNext() { return false; } |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
";
|
|
|
|
|
var rr = Resolve<TypeResolveResult>(program); |
|
|
|
|
Assert.AreEqual("System.Int32", rr.Type.ReflectionName); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
[Test] |
|
|
|
|
public void Foreach_InferFromCustomCollection_WithIEnumerableAndGetEnumeratorExtensionMethod() |
|
|
|
|
{ |
|
|
|
|
string program = @"using System;
|
|
|
|
|
using System.Collections.Generic; |
|
|
|
|
class TestClass { |
|
|
|
|
static void Method(CustomCollection c) { |
|
|
|
|
foreach ($var$ x in c) {} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
class CustomCollection : IEnumerable<int> { |
|
|
|
|
public struct MyEnumerator { |
|
|
|
|
public string Current { get { return null; } } |
|
|
|
|
public bool MoveNext() { return false; } |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
static class ExtMethods { |
|
|
|
|
public static CustomCollection.MyEnumerator GetEnumerator(this CustomCollection c) { |
|
|
|
|
throw new NotImplementedException(); |
|
|
|
|
} |
|
|
|
|
}";
|
|
|
|
|
var rr = Resolve<TypeResolveResult>(program); |
|
|
|
|
Assert.AreEqual("System.Int32", rr.Type.ReflectionName); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|