当前位置: 首页>>代码示例>>C#>>正文


C# TempDataDictionary.TryGetValue方法代码示例

本文整理汇总了C#中TempDataDictionary.TryGetValue方法的典型用法代码示例。如果您正苦于以下问题:C# TempDataDictionary.TryGetValue方法的具体用法?C# TempDataDictionary.TryGetValue怎么用?C# TempDataDictionary.TryGetValue使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在TempDataDictionary的用法示例。


在下文中一共展示了TempDataDictionary.TryGetValue方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: CheckIfKeyIsPresentInTempData

        /// <summary>
        /// Checks if the specified key is present in the MVC TempData dictionary.
        /// </summary>
        /// <param name="key">The key to search for.</param>
        /// <param name="tempData">The dictionary to search in.</param>
        /// <returns>True if the specified value is present. Otherwise, false.</returns>
        private static bool CheckIfKeyIsPresentInTempData( string key, TempDataDictionary tempData )
        {
            object tempDataValue;
            tempData.TryGetValue( key, out tempDataValue );

            if( tempDataValue == null ) return false;
            if( (bool)tempDataValue == false ) return false;

            return true;
        }
开发者ID:DoNormal,项目名称:Costanza,代码行数:16,代码来源:MessageExtensionsForHtmlHelper.cs

示例2: TempData_TryGetValue_MarksKeyForDeletion

        public void TempData_TryGetValue_MarksKeyForDeletion()
        {
            var tempData = new TempDataDictionary(GetHttpContextAccessor(), new NullTempDataProvider());
            object value;
            tempData["Foo"] = "Foo";

            // Act
            tempData.TryGetValue("Foo", out value);
            tempData.Save();

            // Assert
            Assert.False(tempData.ContainsKey("Foo"));
        }
开发者ID:4myBenefits,项目名称:Mvc,代码行数:13,代码来源:TempDataDictionaryTest.cs

示例3: GetList

 private static List<string> GetList(TempDataDictionary td, string key)
 {
     object obj;
     var b = td.TryGetValue(key, out obj);
     List<string> messages = null;
     if (b)
     {
         messages = obj as List<string>;
     }
     if (messages == null)
     {
         messages = new List<string>();
         td[key] = messages;
     }
     return messages;
 }
开发者ID:RavneetK,项目名称:second-test,代码行数:16,代码来源:StatusSummary.cs

示例4: TempData_RemovalOfKeysAreCaseInsensitive

        public void TempData_RemovalOfKeysAreCaseInsensitive()
        {
            var tempData = new TempDataDictionary(GetHttpContextAccessor(), new NullTempDataProvider());
            object fooValue;
            tempData["Foo"] = "Foo";
            tempData["Bar"] = "Bar";

            // Act
            tempData.TryGetValue("foo", out fooValue);
            var barValue = tempData["bar"];
            tempData.Save();

            // Assert
            Assert.False(tempData.ContainsKey("Foo"));
            Assert.False(tempData.ContainsKey("Boo"));
        }
开发者ID:huoxudong125,项目名称:Mvc,代码行数:16,代码来源:TempDataDictionaryTest.cs

示例5: TryGetValueMarksKeyForDeletion

        public void TryGetValueMarksKeyForDeletion() {
            NullTempDataProvider provider = new NullTempDataProvider();
            TempDataDictionary tempData = new TempDataDictionary();
            Mock<ControllerContext> controllerContext = new Mock<ControllerContext>();
            object value;
            tempData["Foo"] = "Foo";

            // Act
            tempData.TryGetValue("Foo", out value);
            tempData.Save(controllerContext.Object, provider);

            // Assert
            Assert.IsFalse(tempData.ContainsKey("Foo"), "tempData should not contain 'Foo'");
        }
开发者ID:consumentor,项目名称:Server,代码行数:14,代码来源:TempDataDictionaryTest.cs

示例6: RemovalOfKeysAreCaseInsensitive

        public void RemovalOfKeysAreCaseInsensitive() {
            NullTempDataProvider provider = new NullTempDataProvider();
            TempDataDictionary tempData = new TempDataDictionary();
            Mock<ControllerContext> controllerContext = new Mock<ControllerContext>();
            object fooValue;
            tempData["Foo"] = "Foo";
            tempData["Bar"] = "Bar";

            // Act
            tempData.TryGetValue("foo", out fooValue);
            object barValue = tempData["bar"];
            tempData.Save(controllerContext.Object, provider);

            // Assert
            Assert.IsFalse(tempData.ContainsKey("Foo"), "tempData should not contain 'Foo'");
            Assert.IsFalse(tempData.ContainsKey("Boo"), "tempData should not contain 'Bar'");
        }
开发者ID:consumentor,项目名称:Server,代码行数:17,代码来源:TempDataDictionaryTest.cs


注:本文中的TempDataDictionary.TryGetValue方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。