本文整理汇总了C#中DynamicDictionary.Add方法的典型用法代码示例。如果您正苦于以下问题:C# DynamicDictionary.Add方法的具体用法?C# DynamicDictionary.Add怎么用?C# DynamicDictionary.Add使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类DynamicDictionary
的用法示例。
在下文中一共展示了DynamicDictionary.Add方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: HomeModule
public HomeModule(ITransient transient, IRequestScoped requestScoped)
: base("/home")
{
_transient = transient;
_requestScoped = requestScoped;
Debug.Assert(_requestScoped == _transient.RequestScoped);
Get["/"] = _ =>
{
var viewBag = new DynamicDictionary();
viewBag.Add("Transient", _transient);
viewBag.Add("RequestScoped", _requestScoped);
return View["home/index", viewBag];
};
Get["/index", runAsync: true] = async (_, token) =>
{
await Task.Delay(1000);
return "123";
};
Get["/list", runAsync: true] = async (_, token) =>
{
await Task.Delay(1);
return 500;
};
Get["/edit", runAsync: true] = async (_, token) =>
{
await Task.Delay(1);
return 404;
};
}
示例2: TestContainsKey
public void TestContainsKey()
{
var d = new DynamicDictionary();
d.Add("key", "value");
Assert.IsTrue(d.ContainsKey("key"), "Did not contain key: \"key\"");
}
示例3: TestAdd
public void TestAdd()
{
var d = new DynamicDictionary();
d.Add("key", "value");
Assert.AreEqual("value", d["key"]);
}
示例4: Test_get_cards_by_filter
public void Test_get_cards_by_filter ()
{
DynamicDictionary query = new DynamicDictionary();
query.Add ("name", "Ankh of Mishra");
Card[] cards = repository.GetCards (query).Result;
Assert.Greater (cards.Length,1);
}
示例5: Should_add_value_when_invoking_string_dynamic_overload_of_add_method
public void Should_add_value_when_invoking_string_dynamic_overload_of_add_method()
{
// Given
var input = new DynamicDictionary();
// When
input.Add("test", 10);
var value = (int)input["test"];
// Then
value.ShouldEqual(10);
}
示例6: Should_add_value_when_invoking_keyvaluepair_overload_of_add_method
public void Should_add_value_when_invoking_keyvaluepair_overload_of_add_method()
{
// Given
var input = new DynamicDictionary();
// When
input.Add(new KeyValuePair<string, dynamic>("test", 10));
var value = (int)input["test"];
// Then
value.ShouldEqual(10);
}
示例7: Deserialize
public object Deserialize( BsonDeserializationContext context, BsonDeserializationArgs args )
{
var bsonReader = context.Reader;
BsonType bsonType = bsonReader.CurrentBsonType;
object result;
if( bsonType == BsonType.Null )
{
bsonReader.ReadNull();
result = null;
}
else
{
if( bsonType == BsonType.Document )
{
var dictionary = new DynamicDictionary();
bsonReader.ReadStartDocument();
IDiscriminatorConvention valueDiscriminatorConvention = BsonSerializer.LookupDiscriminatorConvention( typeof( object ) );
while( bsonReader.ReadBsonType() != BsonType.EndOfDocument )
{
string key = bsonReader.ReadName();
Type valueType = valueDiscriminatorConvention.GetActualType( bsonReader, typeof( object ) );
IBsonSerializer valueSerializer = BsonSerializer.LookupSerializer( valueType );
object value = valueSerializer.Deserialize( context );
if( key != "_t" )
{
dictionary.Add( key.Replace( '\x03', '.' ), value );
}
}
bsonReader.ReadEndDocument();
result = dictionary;
}
else
{
string message = string.Format( "Can't deserialize a {0} from BsonType {1}.", context.Reader.CurrentBsonType, bsonType );
throw new BsonException( message );
}
}
return result;
}
示例8: TestAddKeyValuePair
public void TestAddKeyValuePair()
{
var d = new DynamicDictionary();
d.Add(new KeyValuePair<string, object>("foo", "bar"));
Assert.AreEqual("bar", d["foo"]);
}
示例9: TestGetEnumerator
public void TestGetEnumerator()
{
var d = new DynamicDictionary();
d.Add("key", "value");
IEnumerator enumerator = d.GetEnumerator();
int count = 0;
while (enumerator.MoveNext())
{
var pair = (KeyValuePair<string, object>) enumerator.Current;
Assert.AreEqual("key", pair.Key);
Assert.AreEqual("value", pair.Value);
count += 1;
}
Assert.AreEqual(1, count, "Enumerator did not move through the right number of items.");
}
示例10: TestRemoveKeyValuePair
public void TestRemoveKeyValuePair()
{
var d = new DynamicDictionary();
d.Add("key", "value");
Assert.IsTrue(d.Remove(new KeyValuePair<string, object>("key", "value")));
Assert.AreEqual(0, d.Count);
}
示例11: TestCount
public void TestCount()
{
var d = new DynamicDictionary();
Assert.AreEqual(0, d.Count);
d.Add("key", "value");
Assert.AreEqual(1, d.Count);
d.Remove("key");
Assert.AreEqual(0, d.Count);
}
示例12: TestCopyToKeyValuePair
public void TestCopyToKeyValuePair()
{
var d = new DynamicDictionary();
d.Add("foo", "bar");
var array = new KeyValuePair<string, object>[d.Count];
d.CopyTo(array, 0);
KeyValuePair<string, object> pair = array[0];
Assert.AreEqual("foo", pair.Key);
Assert.AreEqual("bar", pair.Value);
}
示例13: ViewReportResults
private dynamic ViewReportResults(dynamic args)
{
var requestId = new Guid(args.id);
var results = reportResultService.GetResultsPage(requestId, Context.RequestedPage());
var columns = results.FieldColumns.Select(x => new { name = String.Format(FieldNameFormat, x.FieldName, x.UnitName), id = x.FieldId }).ToList();
columns.Insert(0, new { name = "Date Recorded", id = "DateRecorded" });
columns.Insert(1, new { name = "Site Name", id = "SiteName" });
var pagedResult = new
{
ReportName = results.ReportName,
Count = results.Count,
Pages = results.Pages,
Columns = columns,
Rows = results.Rows.Select(x =>
{
var row = new DynamicDictionary();
row.Add("DateRecorded", x.RowDateTime.ToString(RowDateFormat));
row.Add("SiteName", x.SiteName);
foreach (var field in x.Fields)
{
row.Add(field.FieldId, field.Value);
}
return row;
})
};
return pagedResult;
}
示例14: Should_remove_natural_key
public void Should_remove_natural_key()
{
// Given
var input = new DynamicDictionary();
input.Add("a-b-c", "hello");
//when
input.Remove("a-b-c");
//then
input.ContainsKey("abc").ShouldBeFalse();
}
示例15: TestTryGetValueKeyExists
public void TestTryGetValueKeyExists()
{
var d = new DynamicDictionary();
d.Add("key", "value");
object value;
Assert.IsTrue(
d.TryGetValue("key", out value),
"Expected true to trying to get a value for an existing key.");
Assert.AreEqual("value", value);
}