mirror of https://github.com/icsharpcode/ILSpy.git
12 changed files with 481 additions and 118 deletions
@ -1,17 +0,0 @@
@@ -1,17 +0,0 @@
|
||||
using System; |
||||
|
||||
namespace ICSharpCode.Decompiler.Tests.TestCases.Ugly |
||||
{ |
||||
internal class NoGenericTypeInstantiation<TOnType> where TOnType : new() |
||||
{ |
||||
public static TOnType CreateTOnType() |
||||
{ |
||||
return Activator.CreateInstance<TOnType>(); |
||||
} |
||||
|
||||
public static TOnMethod CreateTOnMethod<TOnMethod>() where TOnMethod : new() |
||||
{ |
||||
return Activator.CreateInstance<TOnMethod>(); |
||||
} |
||||
} |
||||
} |
@ -1,15 +0,0 @@
@@ -1,15 +0,0 @@
|
||||
namespace ICSharpCode.Decompiler.Tests.TestCases.Ugly |
||||
{ |
||||
internal class NoGenericTypeInstantiation<TOnType> where TOnType : new() |
||||
{ |
||||
public static TOnType CreateTOnType() |
||||
{ |
||||
return new TOnType(); |
||||
} |
||||
|
||||
public static TOnMethod CreateTOnMethod<TOnMethod>() where TOnMethod : new() |
||||
{ |
||||
return new TOnMethod(); |
||||
} |
||||
} |
||||
} |
@ -0,0 +1,68 @@
@@ -0,0 +1,68 @@
|
||||
using System; |
||||
using System.Collections.Generic; |
||||
|
||||
namespace ICSharpCode.Decompiler.Tests.TestCases.Ugly |
||||
{ |
||||
internal class NoNewOfT<TOnType> where TOnType : new() |
||||
{ |
||||
public static TOnType CreateTOnType() |
||||
{ |
||||
#if !ROSLYN
|
||||
#if OPT
|
||||
if (default(TOnType) != null) |
||||
{ |
||||
return default(TOnType); |
||||
} |
||||
return Activator.CreateInstance<TOnType>(); |
||||
#else
|
||||
return (default(TOnType) == null) ? Activator.CreateInstance<TOnType>() : default(TOnType); |
||||
#endif
|
||||
#else
|
||||
return Activator.CreateInstance<TOnType>(); |
||||
#endif
|
||||
} |
||||
|
||||
public static T CreateUnconstrainedT<T>() where T : new() |
||||
{ |
||||
#if !ROSLYN
|
||||
#if OPT
|
||||
if (default(T) != null) |
||||
{ |
||||
return default(T); |
||||
} |
||||
return Activator.CreateInstance<T>(); |
||||
#else
|
||||
return (default(T) == null) ? Activator.CreateInstance<T>() : default(T); |
||||
#endif
|
||||
#else
|
||||
return Activator.CreateInstance<T>(); |
||||
#endif
|
||||
} |
||||
|
||||
public static T CreateClassT<T>() where T : class, new() |
||||
{ |
||||
return Activator.CreateInstance<T>(); |
||||
} |
||||
|
||||
public static T CollectionInitializer<T>() where T : IList<int>, new() |
||||
{ |
||||
#if ROSLYN
|
||||
T result = Activator.CreateInstance<T>(); |
||||
result.Add(1); |
||||
result.Add(2); |
||||
result.Add(3); |
||||
result.Add(4); |
||||
result.Add(5); |
||||
return result; |
||||
#else
|
||||
T val = ((default(T) == null) ? Activator.CreateInstance<T>() : default(T)); |
||||
val.Add(1); |
||||
val.Add(2); |
||||
val.Add(3); |
||||
val.Add(4); |
||||
val.Add(5); |
||||
return val; |
||||
#endif
|
||||
} |
||||
} |
||||
} |
@ -0,0 +1,27 @@
@@ -0,0 +1,27 @@
|
||||
using System.Collections.Generic; |
||||
|
||||
namespace ICSharpCode.Decompiler.Tests.TestCases.Ugly |
||||
{ |
||||
internal class NoNewOfT<TOnType> where TOnType : new() |
||||
{ |
||||
public static TOnType CreateTOnType() |
||||
{ |
||||
return new TOnType(); |
||||
} |
||||
|
||||
public static T CreateUnconstrainedT<T>() where T : new() |
||||
{ |
||||
return new T(); |
||||
} |
||||
|
||||
public static T CreateClassT<T>() where T : class, new() |
||||
{ |
||||
return new T(); |
||||
} |
||||
|
||||
public static T CollectionInitializer<T>() where T : IList<int>, new() |
||||
{ |
||||
return new T() { 1, 2, 3, 4, 5 }; |
||||
} |
||||
} |
||||
} |
Loading…
Reference in new issue