本文整理汇总了C#中IDictionary类的典型用法代码示例。如果您正苦于以下问题:C# IDictionary类的具体用法?C# IDictionary怎么用?C# IDictionary使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
IDictionary类属于命名空间,在下文中一共展示了IDictionary类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: GetTestableChat
public static TestableChat GetTestableChat(string connectionId, StateChangeTracker clientState, ChatUser user, IDictionary<string, Cookie> cookies)
{
// setup things needed for chat
var repository = new InMemoryRepository();
var resourceProcessor = new Mock<IResourceProcessor>();
var chatService = new Mock<IChatService>();
var connection = new Mock<IConnection>();
var settings = new Mock<IApplicationSettings>();
var mockPipeline = new Mock<IHubPipelineInvoker>();
// add user to repository
repository.Add(user);
// create testable chat
var chat = new TestableChat(settings, resourceProcessor, chatService, repository, connection);
var mockedConnectionObject = chat.MockedConnection.Object;
chat.Clients = new HubConnectionContext(mockPipeline.Object, mockedConnectionObject, "Chat", connectionId, clientState);
var prinicipal = new Mock<IPrincipal>();
var request = new Mock<IRequest>();
request.Setup(m => m.Cookies).Returns(cookies);
request.Setup(m => m.User).Returns(prinicipal.Object);
// setup context
chat.Context = new HubCallerContext(request.Object, connectionId);
return chat;
}
示例2: Invoke
public Task Invoke(IDictionary<string, object> environment)
{
if (!environment.Get<string>(OwinConstants.RequestMethodKey).EqualsIgnoreCase("GET"))
{
return _inner(environment);
}
var originalOutput = environment.Get<Stream>(OwinConstants.ResponseBodyKey);
var recordedStream = new MemoryStream();
environment.Set(OwinConstants.ResponseBodyKey, recordedStream);
return _inner(environment).ContinueWith(t => {
recordedStream.Position = 0;
environment[OwinConstants.ResponseBodyKey] = originalOutput;
var response = new OwinHttpResponse(environment);
if (IsGetHtmlRequest(environment) && response.StatusCode < 500)
{
injectContent(environment, recordedStream, response);
}
else
{
response.StreamContents(recordedStream);
}
});
}
示例3: CallAction
private static void CallAction(Key key, IDictionary<Key, Action> delegates)
{
if (delegates.ContainsKey(key) && delegates[key] != null)
{
delegates[key]();
}
}
示例4: ClientPermissionsActionResult
public ClientPermissionsActionResult(IViewService viewSvc, IDictionary<string, object> env, ClientPermissionsViewModel model)
: base(async () => await viewSvc.ClientPermissions(model))
{
if (viewSvc == null) throw new ArgumentNullException("viewSvc");
if (env == null) throw new ArgumentNullException("env");
if (model == null) throw new ArgumentNullException("model");
}
示例5: GetInt32
public static int GetInt32(string property, IDictionary<string, string> properties, int defaultValue)
{
string toParse;
properties.TryGetValue(property, out toParse);
int result;
return int.TryParse(toParse, out result) ? result : defaultValue;
}
示例6: BuildCacheStatic
public static ICache BuildCacheStatic(string regionName, IDictionary<string,string> properties)
{
if (regionName != null && caches[regionName] != null)
{
return caches[regionName] as ICache;
}
if (regionName == null)
{
regionName = "";
}
if (properties == null)
{
properties = new Dictionary<string,string>();
}
if (log.IsDebugEnabled)
{
StringBuilder sb = new StringBuilder();
foreach (KeyValuePair<string, string> de in properties)
{
sb.Append("name=");
sb.Append(de.Key);
sb.Append("&value=");
sb.Append(de.Value);
sb.Append(";");
}
log.Debug("building cache with region: " + regionName + ", properties: " + sb.ToString());
}
FooCache cache = new FooCache(regionName, properties);
caches.Add(regionName, cache);
return cache;
}
示例7: Invoke
public async Task Invoke(IDictionary<string, object> environment)
{
int maxRedirects = _maxRedirects;
while (maxRedirects >= 0)
{
await _next(environment);
var response = new OwinResponse(environment);
if (response.StatusCode == 302 || response.StatusCode == 301)
{
string url = BuildRedirectUrl(response);
// Clear the env so we can make a new request
environment.Clear();
// Populate the env with new request data
RequestBuilder.BuildGet(environment, url);
}
else
{
break;
}
maxRedirects--;
}
}
示例8: FormatRichTextPersistedDataForEditor
/// <summary>
/// This formats the persisted string to something useful for the rte so that the macro renders properly since we
/// persist all macro formats like {?UMBRACO_MACRO macroAlias=\"myMacro\" /}
/// </summary>
/// <param name="persistedContent"></param>
/// <param name="htmlAttributes">The html attributes to be added to the div</param>
/// <returns></returns>
/// <remarks>
/// This converts the persisted macro format to this:
///
/// {div class='umb-macro-holder'}
/// <!-- <?UMBRACO_MACRO macroAlias=\"myMacro\" /> -->
/// {ins}Macro alias: {strong}My Macro{/strong}{/ins}
/// {/div}
///
/// </remarks>
internal static string FormatRichTextPersistedDataForEditor(string persistedContent, IDictionary<string ,string> htmlAttributes)
{
return MacroPersistedFormat.Replace(persistedContent, match =>
{
if (match.Groups.Count >= 3)
{
//<div class="umb-macro-holder myMacro mceNonEditable">
var alias = match.Groups[2].Value;
var sb = new StringBuilder("<div class=\"umb-macro-holder ");
sb.Append(alias);
sb.Append(" mceNonEditable\"");
foreach (var htmlAttribute in htmlAttributes)
{
sb.Append(" ");
sb.Append(htmlAttribute.Key);
sb.Append("=\"");
sb.Append(htmlAttribute.Value);
sb.Append("\"");
}
sb.AppendLine(">");
sb.Append("<!-- ");
sb.Append(match.Groups[1].Value.Trim());
sb.Append(" />");
sb.AppendLine(" -->");
sb.Append("<ins>");
sb.Append("Macro alias: ");
sb.Append("<strong>");
sb.Append(alias);
sb.Append("</strong></ins></div>");
return sb.ToString();
}
//replace with nothing if we couldn't find the syntax for whatever reason
return "";
});
}
示例9: ParseAsync
/// <summary>
/// Tries to find a secret on the environment that can be used for authentication
/// </summary>
/// <param name="environment">The environment.</param>
/// <returns>
/// A parsed secret
/// </returns>
public async Task<ParsedSecret> ParseAsync(IDictionary<string, object> environment)
{
Logger.Debug("Start parsing for secret in post body");
var context = new OwinContext(environment);
var body = await context.ReadRequestFormAsync();
if (body != null)
{
var id = body.Get("client_id");
var secret = body.Get("client_secret");
if (id.IsPresent() && secret.IsPresent())
{
var parsedSecret = new ParsedSecret
{
Id = id,
Credential = secret,
Type = Constants.ParsedSecretTypes.SharedSecret
};
return parsedSecret;
}
}
Logger.Debug("No secet in post body found");
return null;
}
示例10: Rectangle
public Rectangle(IDictionary<ParamKeys, object> parameter)
: base(parameter)
{
_edge1 = (double) parameter[ParamKeys.Edge1];
_edge2 = (double) parameter[ParamKeys.Edge2];
ShapeName = "Rectangle";
}
示例11: SendEvent
public async Task<HttpResponseMessage> SendEvent(string eventType, IDictionary<string, string> options)
{
HttpRequestMessage request = new HttpRequestMessage(HttpMethod.Post, endpointUrl);
request.Content = GetRequestContent(eventType, options);
var response = await HttpClient.SendAsync(request).ConfigureAwait(false);
return response;
}
示例12: DELETE
public static string DELETE(string uri, IDictionary<string, string> args)
{
try {
WebClient client = new WebClient();
client.Encoding = Encoding.UTF8;
client.Headers["Connection"] = "Keep-Alive";
StringBuilder formattedParams = new StringBuilder();
IDictionary<string, string> parameters = new Dictionary<string, string>();
foreach (var arg in args)
{
parameters.Add(arg.Key, arg.Value);
formattedParams.AppendFormat("{0}={{{1}}}", arg.Key, arg.Key);
}
//Formatted URI
Uri baseUri = new Uri(uri);
client.UploadStringCompleted += new UploadStringCompletedEventHandler(client_UploadStringCompletedDelete);
client.UploadStringAsync(baseUri, "DELETE", string.Empty);
allDone.Reset();
allDone.WaitOne();
return requestResult;
}
catch (WebException ex) {
return ReadResponse(ex.Response.GetResponseStream());
}
}
示例13: GetInt64
public static long GetInt64(string property, IDictionary<string, string> properties, long defaultValue)
{
string toParse;
properties.TryGetValue(property, out toParse);
long result;
return long.TryParse(toParse, out result) ? result : defaultValue;
}
示例14: GetValue
public IItem GetValue(IDictionary<string, IItem> variables) {
var stack = new Stack<object>();
int i = 0;
try {
for (; i < tokens.Count; i++) {
var token = tokens[i];
double d;
if (TryParse(token, out d)) {
stack.Push(d);
} else if (token.StartsWith("\"")) {
stack.Push(GetVariableValue(variables, token.Substring(1, token.Length - 2).Replace("\\\"", "\"")));
} else if (token.StartsWith("'")) {
stack.Push(token.Substring(1, token.Length - 2).Replace("\\'", "'"));
} else {
Apply(token, stack, variables);
}
}
} catch (Exception x) {
throw new Exception(string.Format(
"Calculation of '{1}'{0}failed at token #{2}: {3} {0}current stack is: {0}{4}", Environment.NewLine,
Formula, i, TokenWithContext(tokens, i, 3),
string.Join(Environment.NewLine, stack.Select(AsString))),
x);
}
if (stack.Count != 1)
throw new Exception(
string.Format("Invalid final evaluation stack size {0} (should be 1) in formula '{1}'",
stack.Count, Formula));
var result = stack.Pop();
if (result is string) return new StringValue((string)result);
if (result is int) return new IntValue((int)result);
if (result is double) return new DoubleValue((double)result);
if (result is bool) return new BoolValue((bool)result);
return null;
}
示例15: ToSqlString
public override SqlString ToSqlString(ICriteria criteria, ICriteriaQuery criteriaQuery, IDictionary<string, IFilter> enabledFilters)
{
var sqlBuilder = new SqlStringBuilder();
SqlString[] columnNames = null;
if (_propertyName != "*")
{
columnNames = CriterionUtil.GetColumnNames(_propertyName, _projection, criteriaQuery, criteria, enabledFilters);
if (columnNames.Length != 1)
{
throw new HibernateException("Contains may only be used with single-column properties");
}
} else
{
columnNames = new SqlString[]
{
new SqlString("*")
};
}
sqlBuilder.Add("contains(")
.Add(columnNames[0])
.Add(",");
sqlBuilder.Add(criteriaQuery.NewQueryParameter(GetParameterTypedValue(criteria, criteriaQuery)).Single());
sqlBuilder.Add(")");
return sqlBuilder.ToSqlString();
}