Esempio n. 1
0
        public void BasicThreadLocal()
        {
            Assert.IsNull(ThreadLocalSingleton.Get <object>());
            Assert.AreEqual(0, ThreadLocalSingleton.Count <object>());
            Assert.AreSame(ThreadLocalSingleton.GetOrCreate <object>(), ThreadLocalSingleton.GetOrCreate(() => new object()));
            Assert.AreEqual(1, ThreadLocalSingleton.Count <object>());
            var o = ThreadLocalSingleton.Get <object>();

            Assert.AreSame(o, ThreadLocalSingleton.Reset <object>());
            Assert.AreEqual(0, ThreadLocalSingleton.Count <object>());
            Assert.IsNull(ThreadLocalSingleton.Get <object>());
            Assert.AreEqual(0, ThreadLocalSingleton.Count <object>());
            Assert.IsNotNull(ThreadLocalSingleton.GetOrDefault(new object()));
            Assert.AreEqual(0, ThreadLocalSingleton.Count <object>());
            Assert.IsNull(ThreadLocalSingleton.Set(new object()));
            Assert.AreEqual(1, ThreadLocalSingleton.Count <object>());
            Assert.AreSame(ThreadLocalSingleton.Get <object>(), ThreadLocalSingleton.GetOrCreate <object>());
            Assert.AreEqual(1, ThreadLocalSingleton.Count <object>());
        }
Esempio n. 2
0
            static CommentVM()
            {
                edit = AsyncCommand <Comment> .Create(async (s, c) =>
                {
                    var dialog             = ThreadLocalSingleton.GetOrCreate <EditCommentDialog>();
                    dialog.EditableComment = c;
                    await dialog.ShowAsync();
                }, (s, c) => c != null && c.CanEdit);

                edit.ReentrancyHandler = ReentrancyHandler.LastQueued <Comment>();
                reply = AsyncCommand <Comment> .Create(async (s, c) =>
                {
                    var dialog             = ThreadLocalSingleton.GetOrCreate <ReplyCommentDialog>();
                    dialog.ReplyingComment = c;
                    await dialog.ShowAsync();
                }, (s, c) => c != null && !c.CanEdit);

                reply.ReentrancyHandler = ReentrancyHandler.LastQueued <Comment>();
            }