本文整理汇总了C#中DynamicDictionary类的典型用法代码示例。如果您正苦于以下问题:C# DynamicDictionary类的具体用法?C# DynamicDictionary怎么用?C# DynamicDictionary使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
DynamicDictionary类属于命名空间,在下文中一共展示了DynamicDictionary类的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: Can_read_non_existing_value_from_dictionary_via_dynamic_object
public void Can_read_non_existing_value_from_dictionary_via_dynamic_object()
{
var dictionary = new Dictionary<string, object>();
dynamic adapter = new DynamicDictionary(dictionary);
Assert.IsNull(adapter.Name);
}
示例3: MainModule
public MainModule()
{
Get["/"] = x => View["index.html"];
Get["/login"] = x =>
{
dynamic model = new DynamicDictionary();
model.Errored = this.Request.Query.error.HasValue;
return View["login", model];
};
Post["/login"] = x =>
{
var userGuid = UserDatabase.ValidateUser((string)this.Request.Form.Username, (string)this.Request.Form.Password);
if (userGuid == null)
{
return this.Context.GetRedirect("~/login?error=true&username=" + (string)this.Request.Form.Username);
}
DateTime? expiry = null;
if (this.Request.Form.RememberMe.HasValue)
{
expiry = DateTime.Now.AddDays(7);
}
return this.LoginAndRedirect(userGuid.Value, expiry);
};
Get["/logout"] = x =>
{
return this.LogoutAndRedirect("~/");
};
}
示例4: TmMqMessage
public TmMqMessage( ITmMqMessage copy )
{
#region param checks
if( copy == null )
{
throw new ArgumentNullException( "copy" );
}
#endregion
MessageId = copy.MessageId;
Properties = new DynamicDictionary( copy.Properties );
Errors = new List<TmMqMessageError>( copy.Errors );
TimeStamp = copy.TimeStamp;
DeliveredAt = copy.DeliveredAt;
CorrelationId = copy.CorrelationId;
RetryCount = copy.RetryCount;
DeliveryCount = copy.DeliveryCount;
Type = copy.Type;
OriginalQueue = copy.OriginalQueue;
ReplyTo = copy.ReplyTo;
Text = copy.Text;
ExpireAt = copy.ExpireAt;
HoldUntil = copy.HoldUntil;
}
示例5: Invoke
/// <summary>
/// Invokes the specified <paramref name="route"/> with the provided <paramref name="parameters"/>.
/// </summary>
/// <param name="route">The route that should be invoked.</param>
/// <param name="cancellationToken">Cancellation token</param>
/// <param name="parameters">The parameters that the route should be invoked with.</param>
/// <param name="context">The context of the route that is being invoked.</param>
/// <returns>A <see cref="Response"/> instance that represents the result of the invoked route.</returns>
public async Task<Response> Invoke(Route route, CancellationToken cancellationToken, DynamicDictionary parameters, NancyContext context)
{
object result;
try
{
result = await route.Invoke(parameters, cancellationToken).ConfigureAwait(false);
}
catch(RouteExecutionEarlyExitException earlyExitException)
{
context.WriteTraceLog(
sb => sb.AppendFormat(
"[DefaultRouteInvoker] Caught RouteExecutionEarlyExitException - reason {0}",
earlyExitException.Reason));
return earlyExitException.Response;
}
if (!(result is ValueType) && result == null)
{
context.WriteTraceLog(
sb => sb.AppendLine("[DefaultRouteInvoker] Invocation of route returned null"));
result = new Response();
}
return this.negotiator.NegotiateResponse(result, context);
}
示例6: Accessing_A_Defined_Property_Should_Return_The_Defined_Value
public void Accessing_A_Defined_Property_Should_Return_The_Defined_Value()
{
dynamic obj = new DynamicDictionary();
obj.FirstName = "Clark";
Assert.That( obj.FirstName == "Clark" );
}
示例7: ShouldBeAbleToSetAndRetrievePropertyViaIndexer
public void ShouldBeAbleToSetAndRetrievePropertyViaIndexer()
{
var dictionary = new DynamicDictionary();
dictionary["key"] = "value";
Assert.AreEqual("value", dictionary["key"]);
}
示例8: Can_read_from_dictionary_via_dynamic_object
public void Can_read_from_dictionary_via_dynamic_object()
{
var dictionary = new Dictionary<string, object>();
dynamic adapter = new DynamicDictionary(dictionary);
dictionary["Name"] = "stefan mucha";
Assert.AreEqual("stefan mucha", adapter.Name);
}
示例9: Can_add_to_dictionary_via_dynamic_object
public void Can_add_to_dictionary_via_dynamic_object()
{
var dictionary = new Dictionary<string, object>();
dynamic adapter = new DynamicDictionary(dictionary);
adapter.Name = "stefan mucha";
Assert.AreEqual("stefan mucha", dictionary["Name"]);
}
示例10: Accessing_A_Not_Existent_Property_Should_Return_Null
public void Accessing_A_Not_Existent_Property_Should_Return_Null()
{
dynamic obj = new DynamicDictionary();
var firstName = obj.FirstName;
Assert.Null( firstName );
}
示例11: A_Defined_Anonymous_Object_Should_Be_Accessible_Dynamically
public void A_Defined_Anonymous_Object_Should_Be_Accessible_Dynamically()
{
dynamic obj = new DynamicDictionary();
obj.Customer = new { FirstName = "Clark", LastName = "Kent" };
Assert.That( obj.Customer.FirstName == "Clark" );
}
示例12: The_DynamicDictionary_Should_Be_Castable_To_An_IDictionary_Of_String_Object
public void The_DynamicDictionary_Should_Be_Castable_To_An_IDictionary_Of_String_Object()
{
dynamic obj = new DynamicDictionary();
var dictionary = (IDictionary<string, object>)obj;
Assert.NotNull( dictionary );
}
示例13: TestContainsKey
public void TestContainsKey()
{
var d = new DynamicDictionary();
d.Add("key", "value");
Assert.IsTrue(d.ContainsKey("key"), "Did not contain key: \"key\"");
}
示例14: TestAdd
public void TestAdd()
{
var d = new DynamicDictionary();
d.Add("key", "value");
Assert.AreEqual("value", d["key"]);
}
示例15: ResolveResult
public ResolveResult(Route route, DynamicDictionary parameters, Func<NancyContext, Response> before, Action<NancyContext> after, Func<NancyContext, Exception, Response> onError)
{
this.Route = route;
this.Parameters = parameters;
this.Before = before;
this.After = after;
this.OnError = onError;
}