本文整理汇总了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;
}
示例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"));
}
示例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;
}
示例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"));
}
示例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'");
}
示例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'");
}