public class SortDescriptionCollection : Collection<SortDescription>, INotifyCollectionChanged
{
- public static readonly SortDescriptionCollection Empty = new SortDescriptionCollection ();
+ public static readonly SortDescriptionCollection Empty = new SortDescriptionCollection (true);
- public SortDescriptionCollection ()
+ readonly bool isReadOnly;
+
+ public SortDescriptionCollection () : this (false)
+ {
+ }
+
+ SortDescriptionCollection (bool isReadOnly)
{
+ this.isReadOnly = isReadOnly;
}
event NotifyCollectionChangedEventHandler INotifyCollectionChanged.CollectionChanged {
protected override void ClearItems ()
{
+ if (isReadOnly)
+ throw new NotSupportedException ();
+
base.ClearItems ();
OnCollectionChanged (NotifyCollectionChangedAction.Reset);
}
protected override void InsertItem (int index, SortDescription item)
{
+ if (isReadOnly)
+ throw new NotSupportedException ();
+
item.Seal ();
base.InsertItem (index, item);
OnCollectionChanged (NotifyCollectionChangedAction.Add, item, index);
protected override void RemoveItem (int index)
{
+ if (isReadOnly)
+ throw new NotSupportedException ();
+
SortDescription sd = base [index];
base.RemoveItem (index);
OnCollectionChanged (NotifyCollectionChangedAction.Remove, sd, index);
protected override void SetItem (int index, SortDescription item)
{
+ if (isReadOnly)
+ throw new NotSupportedException ();
+
SortDescription old = base [index];
item.Seal ();
base.SetItem (index, item);
Assert.AreEqual (ListSortDirection.Descending, addedItem.Direction, "ADD_#2");
Assert.AreEqual (true, addedItem.IsSealed, "ADD_#3");
}
+
+ [Test]
+ public void GetEmptyCollection ()
+ {
+ var collection = SortDescriptionCollection.Empty;
+ CollectionAssert.IsEmpty (collection, "A1");
+ }
+
+ [Test]
+ [ExpectedException (typeof(NotSupportedException))]
+ public void AddToEmptyCollection ()
+ {
+ var collection = SortDescriptionCollection.Empty;
+ collection.Add (new SortDescription ());
+ }
+
+ [Test]
+ public void RemoveFromEmptyCollection ()
+ {
+ var collection = SortDescriptionCollection.Empty;
+ Assert.IsFalse (collection.Remove (new SortDescription ()), "A1");
+ }
+
+ [Test]
+ [ExpectedException (typeof(NotSupportedException))]
+ public void RemoveAtIndexFromEmptyCollection ()
+ {
+ var collection = SortDescriptionCollection.Empty;
+ collection.RemoveAt (0);
+ }
+
+ [Test]
+ [ExpectedException (typeof(NotSupportedException))]
+ public void ClearEmptyCollection ()
+ {
+ var collection = SortDescriptionCollection.Empty;
+ collection.Clear ();
+ }
+
+ [Test]
+ [ExpectedException (typeof(NotSupportedException))]
+ public void InsertIntoEmptyCollection ()
+ {
+ var collection = SortDescriptionCollection.Empty;
+ collection.Insert (0, new SortDescription ());
+ }
}
}
public static AsyncTaskMethodBuilder Create ()
{
- var task = new Task<object> (TaskActionInvoker.Empty, null, CancellationToken.None, TaskCreationOptions.None, null);
+ var task = new Task<object> (TaskActionInvoker.Promise, null, CancellationToken.None, TaskCreationOptions.None, null);
task.SetupScheduler (TaskScheduler.Current);
return new AsyncTaskMethodBuilder (task);
}
public static AsyncTaskMethodBuilder<TResult> Create ()
{
- var task = new Task<TResult> (TaskActionInvoker.Empty, null, CancellationToken.None, TaskCreationOptions.None, null);
+ var task = new Task<TResult> (TaskActionInvoker.Promise, null, CancellationToken.None, TaskCreationOptions.None, null);
task.SetupScheduler (TaskScheduler.Current);
return new AsyncTaskMethodBuilder<TResult> (task);
}
if (IsContinuation)
throw new InvalidOperationException ("Start may not be called on a continuation task");
+ if (IsPromise)
+ throw new InvalidOperationException ("Start may not be called on a promise-style task");
+
SetupScheduler (scheduler);
Schedule ();
}
if (IsContinuation)
throw new InvalidOperationException ("RunSynchronously may not be called on a continuation task");
+ if (IsPromise)
+ throw new InvalidOperationException ("RunSynchronously may not be called on a promise-style task");
+
RunSynchronouslyCore (scheduler);
}
}
}
+ bool IsPromise {
+ get {
+ return invoker == TaskActionInvoker.Promise;
+ }
+ }
+
internal Task ContinuationAncestor {
get {
return contAncestor;
abstract class TaskActionInvoker
{
public static readonly TaskActionInvoker Empty = new EmptyTaskActionInvoker ();
+ public static readonly TaskActionInvoker Promise = new EmptyTaskActionInvoker ();
public static readonly TaskActionInvoker Delay = new DelayTaskInvoker ();
sealed class EmptyTaskActionInvoker : TaskActionInvoker
//
using System;
+using System.Linq;
using System.Collections.Generic;
using System.Runtime.InteropServices;
using System.Security;
}
}
+ public override void GetCompletionStartingWith (string prefix, List<string> results)
+ {
+ base.GetCompletionStartingWith (prefix, results);
+
+ var bt = base_type;
+ while (bt != null) {
+ results.AddRange (MemberCache.GetCompletitionMembers (this, bt, prefix).Where (l => l.IsStatic).Select (l => l.Name));
+ bt = bt.BaseType;
+ }
+ }
+
protected override TypeSpec[] ResolveBaseTypes (out FullNamedExpression base_class)
{
var ifaces = base.ResolveBaseTypes (out base_class);
}
opt_enum_member_declarations
{
+ lexer.parsing_modifiers = true;
+
// here will be evaluated after CLOSE_BLACE is consumed.
if (doc_support)
Lexer.doc_state = XmlCommentState.Allowed;
if (parser == null){
return null;
}
-
- Class parser_result = parser.InteractiveResult;
+
+ Class host = parser.InteractiveResult;
+
+ var base_class_imported = importer.ImportType (base_class);
+ var baseclass_list = new List<FullNamedExpression> (1) {
+ new TypeExpression (base_class_imported, host.Location)
+ };
+ host.SetBaseTypes (baseclass_list);
#if NET_4_0
var access = AssemblyBuilderAccess.RunAndCollect;
module.SetDeclaringAssembly (a);
// Need to setup MemberCache
- parser_result.CreateContainer ();
+ host.CreateContainer ();
+ // Need to setup base type
+ host.DefineContainer ();
- var method = parser_result.Members[0] as Method;
+ var method = host.Members[0] as Method;
BlockContext bc = new BlockContext (method, method.Block, ctx.BuiltinTypes.Void);
try {
}
}
+class D
+{
+ enum E {}
+
+ async Task M ()
+ {
+ }
+}
+
class async
{
async (async arg)
--- /dev/null
+using System;
+using System.Threading;
+using System.Threading.Tasks;
+
+class Test
+{
+ public static int Main ()
+ {
+ Task<int> t = TestMethod ();
+
+ try {
+ t.Start ();
+ return 1;
+ } catch (InvalidOperationException) {
+ }
+
+ try {
+ t.RunSynchronously ();
+ return 2;
+ } catch (InvalidOperationException) {
+ }
+
+ Console.WriteLine ("ok");
+ return 0;
+ }
+
+ async static Task<int> TestMethod ()
+ {
+ await Task.Delay (100000);
+ return 1;
+ }
+}
\ No newline at end of file
<size>13</size>\r
</method>\r
</type>\r
+ <type name="D">\r
+ <method name="System.Threading.Tasks.Task M()" attrs="129">\r
+ <size>33</size>\r
+ </method>\r
+ <method name="Void .ctor()" attrs="6278">\r
+ <size>7</size>\r
+ </method>\r
+ </type>\r
+ <type name="D+<M>c__async0">\r
+ <method name="Void MoveNext()" attrs="486">\r
+ <size>31</size>\r
+ </method>\r
+ <method name="Void SetStateMachine(IAsyncStateMachine)" attrs="486">\r
+ <size>13</size>\r
+ </method>\r
+ </type>\r
</test>\r
<test name="test-async-23.cs">\r
<type name="MyContext">\r
</method>\r
</type>\r
</test>\r
+ <test name="test-async-56.cs">\r
+ <type name="Test">\r
+ <method name="Int32 Main()" attrs="150">\r
+ <size>70</size>\r
+ </method>\r
+ <method name="System.Threading.Tasks.Task`1[System.Int32] TestMethod()" attrs="145">\r
+ <size>33</size>\r
+ </method>\r
+ <method name="Void .ctor()" attrs="6278">\r
+ <size>7</size>\r
+ </method>\r
+ </type>\r
+ <type name="Test+<TestMethod>c__async0">\r
+ <method name="Void MoveNext()" attrs="486">\r
+ <size>169</size>\r
+ </method>\r
+ <method name="Void SetStateMachine(IAsyncStateMachine)" attrs="486">\r
+ <size>13</size>\r
+ </method>\r
+ </type>\r
+ </test>\r
<test name="test-cls-00.cs">\r
<type name="CLSCLass_6">\r
<method name="Void add_Disposed(Delegate)" attrs="2182">\r