當前位置: 首頁>>代碼示例>>C#>>正文


C# AtomicComposition.TryGetValue方法代碼示例

本文整理匯總了C#中AtomicComposition.TryGetValue方法的典型用法代碼示例。如果您正苦於以下問題:C# AtomicComposition.TryGetValue方法的具體用法?C# AtomicComposition.TryGetValue怎麽用?C# AtomicComposition.TryGetValue使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在AtomicComposition的用法示例。


在下文中一共展示了AtomicComposition.TryGetValue方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的C#代碼示例。

示例1: SetValue_ToNull_ShouldBeAllowed

        public void SetValue_ToNull_ShouldBeAllowed()
        {
            var ct = new AtomicComposition();

            ct.SetValue(ct, null);

            object value = new object();

            Assert.IsTrue(ct.TryGetValue(ct, out value));
            Assert.IsNull(value);
        }
開發者ID:nlhepler,項目名稱:mono,代碼行數:11,代碼來源:CompositionTransactionTests.cs

示例2: AfterComplete_AllMethodsShouldThrow

        public void AfterComplete_AllMethodsShouldThrow()
        {
            var ct = new AtomicComposition();

            ct.Complete();

            ExceptionAssert.Throws<InvalidOperationException>(() => ct.AddCompleteAction(() => ct = null));
            ExceptionAssert.Throws<InvalidOperationException>(() => ct.Complete());
            ExceptionAssert.Throws<InvalidOperationException>(() => ct.SetValue(ct, 10));
            object value;
            ExceptionAssert.Throws<InvalidOperationException>(() => ct.TryGetValue(ct, out value));
        }
開發者ID:nlhepler,項目名稱:mono,代碼行數:12,代碼來源:CompositionTransactionTests.cs

示例3: Dispose_AllMethodsShouldThrow

        public void Dispose_AllMethodsShouldThrow()
        {
            var ct = new AtomicComposition();

            ct.Dispose();

            ExceptionAssert.ThrowsDisposed(ct, () => ct.AddCompleteAction(() => ct = null));
            ExceptionAssert.ThrowsDisposed(ct, () => ct.Complete());
            ExceptionAssert.ThrowsDisposed(ct, () => ct.SetValue(ct, 10));
            object value;
            ExceptionAssert.ThrowsDisposed(ct, () => ct.TryGetValue(ct, out value));
        }
開發者ID:nlhepler,項目名稱:mono,代碼行數:12,代碼來源:CompositionTransactionTests.cs

示例4: SetValue_Reference_ShouldBeAllowed

        public void SetValue_Reference_ShouldBeAllowed()
        {
            var ct = new AtomicComposition();

            var sb = new StringBuilder();
            ct.SetValue(ct, sb);

            StringBuilder value;

            Assert.IsTrue(ct.TryGetValue(ct, out value));
            Assert.AreEqual(sb, value);
        }
開發者ID:nlhepler,項目名稱:mono,代碼行數:12,代碼來源:CompositionTransactionTests.cs

示例5: SetValue_ValueType_ShouldBeAllowed

        public void SetValue_ValueType_ShouldBeAllowed()
        {
            var ct = new AtomicComposition();

            ct.SetValue(ct, 45);

            int value;

            Assert.IsTrue(ct.TryGetValue(ct, out value));
            Assert.AreEqual(45, value);
        }
開發者ID:nlhepler,項目名稱:mono,代碼行數:11,代碼來源:CompositionTransactionTests.cs

示例6: SetQuery

 private void SetQuery(AtomicComposition context, object key, Func<int, Func<int, bool>, bool> query)
 {
     Func<int, bool> parentQuery;
     context.TryGetValue(key, out parentQuery);
     Func<int, bool> queryFunction = parameter => { return query(parameter, parentQuery); };
     context.SetValue(key, queryFunction);
 }
開發者ID:nlhepler,項目名稱:mono,代碼行數:7,代碼來源:CompositionTransactionTests.cs

示例7: TestValue

 private void TestValue(AtomicComposition context, object key, string expectedValue)
 {
     string value;
     Assert.IsTrue(context.TryGetValue(key, out value));
     Assert.AreEqual(expectedValue, value);
 }
開發者ID:nlhepler,項目名稱:mono,代碼行數:6,代碼來源:CompositionTransactionTests.cs

示例8: TestQuery

 private void TestQuery(AtomicComposition context, object key, int parameter, bool expectation)
 {
     Func<int, bool> query;
     if (context.TryGetValue(key, out query))
         Assert.AreEqual(expectation, query(parameter));
 }
開發者ID:nlhepler,項目名稱:mono,代碼行數:6,代碼來源:CompositionTransactionTests.cs

示例9: NoComplete_ShouldNotCopyValuesToInner

        public void NoComplete_ShouldNotCopyValuesToInner()
        {
            var innerAtomicComposition = new AtomicComposition();

            object value;
            using (var ct = new AtomicComposition(innerAtomicComposition))
            {
                ct.SetValue(this, 21);

                Assert.IsFalse(innerAtomicComposition.TryGetValue(this, out value));

                // Do not call complete
            }

            // reverify after dispose
            Assert.IsFalse(innerAtomicComposition.TryGetValue(this, out value));
        }
開發者ID:nlhepler,項目名稱:mono,代碼行數:17,代碼來源:CompositionTransactionTests.cs

示例10: TestNoValue

 private void TestNoValue(AtomicComposition context, object key)
 {
     string value;
     Assert.IsFalse(context.TryGetValue(key, out value));
 }
開發者ID:nlhepler,項目名稱:mono,代碼行數:5,代碼來源:CompositionTransactionTests.cs

示例11: Complete_ShouldCopyValuesToInner

        public void Complete_ShouldCopyValuesToInner()
        {
            var innerAtomicComposition = new AtomicComposition();

            object value;
            using (var ct = new AtomicComposition(innerAtomicComposition))
            {
                ct.SetValue(this, 21);

                Assert.IsFalse(innerAtomicComposition.TryGetValue(this, out value));

                ct.Complete();

                Assert.IsTrue(innerAtomicComposition.TryGetValue(this, out value));
                Assert.AreEqual(21, value);
            }

            // reverify after dispose
            Assert.IsTrue(innerAtomicComposition.TryGetValue(this, out value));
            Assert.AreEqual(21, value);
        }
開發者ID:nlhepler,項目名稱:mono,代碼行數:21,代碼來源:CompositionTransactionTests.cs

示例12: SetValue_ChangeOuterValuesWhileHaveInner_ShouldThrow

        public void SetValue_ChangeOuterValuesWhileHaveInner_ShouldThrow()
        {
            var ct = new AtomicComposition();

            var ct2 = new AtomicComposition(ct);

            var key = new object();
            ExceptionAssert.Throws<InvalidOperationException>(() => ct.SetValue(key, 1));

            object value;
            Assert.IsFalse(ct2.TryGetValue(key, out value));
            Assert.IsFalse(ct.TryGetValue(key, out value));

            // remove the inner atomicComposition so the outer one becomes unlocked.
            ct2.Dispose();

            ct.SetValue(key, 2);
            Assert.IsTrue(ct.TryGetValue(key, out value));
            Assert.AreEqual(2, value);
        }
開發者ID:nlhepler,項目名稱:mono,代碼行數:20,代碼來源:CompositionTransactionTests.cs

示例13: SetValue_CauseResize_ShouldWorkFine

        public void SetValue_CauseResize_ShouldWorkFine()
        {
            var ct = new AtomicComposition();

            var keys = new List<object>();
            var values = new List<object>();


            for (int i = 0; i < 20; i++)
            {
                var key = new object();
                keys.Add(key);
                values.Add(i);
                ct.SetValue(key, i);
            }

            for (int i = 0; i < keys.Count; i++)
            {
                object value;
                Assert.IsTrue(ct.TryGetValue(keys[i], out value));
                Assert.AreEqual(i, value);
            }
        }
開發者ID:nlhepler,項目名稱:mono,代碼行數:23,代碼來源:CompositionTransactionTests.cs

示例14: GetExportsCore

            protected override IEnumerable<Export> GetExportsCore(ImportDefinition importDefinition, AtomicComposition context)
            {
                IEnumerable<Export> contextExports;

                if (context == null || !context.TryGetValue(this, out contextExports))
                {
                    contextExports = this._exports;
                }

                List<Export> exports = new List<Export>();
                var func = importDefinition.Constraint.Compile();
                foreach (Export export in contextExports)
                {
                    if (func(export.Definition))
                    {
                        exports.Add(export);
                    }
                }
                return exports;
            }
開發者ID:JackFong,項目名稱:FreeRadical,代碼行數:20,代碼來源:ExportProviderFactory.RecomposableExportProvider.cs

示例15: GetEngineContext

        private EngineContext GetEngineContext(AtomicComposition atomicComposition)
        {
            Assumes.NotNull(atomicComposition);

            EngineContext engineContext;
            if (!atomicComposition.TryGetValue(this, true, out engineContext))
            {
                EngineContext parentContext;
                atomicComposition.TryGetValue(this, false, out parentContext);
                engineContext = new EngineContext(this, parentContext);
                atomicComposition.SetValue(this, engineContext);
                atomicComposition.AddCompleteAction(engineContext.Complete);
            }
            return engineContext;
        }
開發者ID:GuySrinivasan,項目名稱:mono,代碼行數:15,代碼來源:ImportEngine.cs


注:本文中的AtomicComposition.TryGetValue方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。