本文整理汇总了C#中IDictionary.ContainsKey方法的典型用法代码示例。如果您正苦于以下问题:C# IDictionary.ContainsKey方法的具体用法?C# IDictionary.ContainsKey怎么用?C# IDictionary.ContainsKey使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类IDictionary
的用法示例。
在下文中一共展示了IDictionary.ContainsKey方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: GetMarkup
/// <summary>
/// Gets the markup for the tag based upon the passed in parameters.
/// </summary>
/// <param name="currentPage">The current page.</param>
/// <param name="parameters">The parameters.</param>
/// <returns></returns>
public override string GetMarkup(IContent currentPage, IDictionary<string, string> parameters)
{
var email = parameters["email"];
var text = email;
if (parameters.ContainsKey("subject"))
email += ((email.IndexOf("?", StringComparison.InvariantCulture) == -1) ? "?" : "&") + "subject=" + parameters["subject"];
if (parameters.ContainsKey("body"))
email += ((email.IndexOf("?", StringComparison.InvariantCulture) == -1) ? "?" : "&") + "body=" + parameters["body"];
var sb = new StringBuilder();
sb.AppendFormat("<a href=\"mailto:{0}\"", email); // TODO: HTML encode
if (parameters.ContainsKey("title"))
sb.AppendFormat(" title=\"{0}\"", parameters["title"]);
if (parameters.ContainsKey("class"))
sb.AppendFormat(" class=\"{0}\"", parameters["class"]);
sb.Append(">");
sb.Append(parameters.ContainsKey("text")
? parameters["text"]
: text);
sb.Append("</a>");
return sb.ToString();
}
示例2: GetWordsCountDictionaryTest
public void GetWordsCountDictionaryTest()
{
string teststring = @"this is a test 123 34string $%%^%^ to Test String parsing.";
_wordsCountDictionary = _sentenceParserHelper.GetWordsCountDictionary(teststring);
Assert.AreEqual(7, _wordsCountDictionary.Count);
Assert.IsTrue( _wordsCountDictionary.ContainsKey("string"));
Assert.IsTrue(_wordsCountDictionary.ContainsKey("test"));
Assert.IsTrue(_wordsCountDictionary.ContainsKey("this"));
Assert.IsTrue(_wordsCountDictionary.ContainsKey("is"));
Assert.IsTrue(_wordsCountDictionary.ContainsKey("a"));
Assert.IsTrue(_wordsCountDictionary.ContainsKey("to"));
Assert.IsTrue(_wordsCountDictionary.ContainsKey("parsing"));
Assert.IsFalse(_wordsCountDictionary.ContainsKey("123"));
Assert.IsFalse(_wordsCountDictionary.ContainsKey("34string"));
Assert.IsFalse(_wordsCountDictionary.ContainsKey("$%%^%^"));
Assert.AreEqual(2, _wordsCountDictionary["string"]);
Assert.AreEqual(2, _wordsCountDictionary["test"]);
Assert.AreEqual(1, _wordsCountDictionary["this"]);
Assert.AreEqual(1, _wordsCountDictionary["is"]);
Assert.AreEqual(1, _wordsCountDictionary["a"]);
Assert.AreEqual(1, _wordsCountDictionary["to"]);
Assert.AreEqual(1, _wordsCountDictionary["parsing"]);
}
示例3: NewConnectionProvider
public static IConnectionProvider NewConnectionProvider(IDictionary<string, string> settings)
{
IConnectionProvider connections;
string providerClass;
if (settings.TryGetValue(Environment.ConnectionProvider, out providerClass))
{
try
{
log.Info("Initializing connection provider: " + providerClass);
connections =
(IConnectionProvider)
Environment.BytecodeProvider.ObjectsFactory.CreateInstance(ReflectHelper.ClassForName(providerClass));
}
catch (Exception e)
{
log.Fatal("Could not instantiate connection provider", e);
throw new HibernateException("Could not instantiate connection provider: " + providerClass, e);
}
}
else if (settings.ContainsKey(Environment.ConnectionString) || settings.ContainsKey(Environment.ConnectionStringName))
{
connections = new DriverConnectionProvider();
}
else
{
log.Info("No connection provider specified, UserSuppliedConnectionProvider will be used.");
connections = new UserSuppliedConnectionProvider();
}
connections.Configure(settings);
return connections;
}
示例4: ConvertReply
public static BaseReply ConvertReply(IDictionary<string, string> dicParams, Reply reply)
{
if (!dicParams.ContainsKey("ToUserName")) throw new Exception("没有获取到ToUserName");
if (!dicParams.ContainsKey("FromUserName")) throw new Exception("没有获取到FromUserName");
if (reply == null)
{
return null;
}
BaseReply returnReply;
switch (reply.Message.Type)
{
case (int)EnumReplyType.TextReply:
returnReply = new TextReply { Content = reply.Message.Content };
break;
case (int)EnumReplyType.ArticleReply:
returnReply = new ArticleReply
{
Articles = JsonConvert.DeserializeObject<List<ArticleReplyItem>>(reply.Message.Content)
};
break;
default:
return null;
}
returnReply.FromUserName = dicParams["ToUserName"];
returnReply.ToUserName = dicParams["FromUserName"];
return returnReply;
}
示例5: ReorganizeAdStacks
public void ReorganizeAdStacks(IDictionary<DateTime, IDictionary<Guid, IDictionary<Ad, IDictionary<int, long>>>> adDispatchPlans, DateTime currentTime)
{
var time = new DateTime(currentTime.Year, currentTime.Month, currentTime.Day, currentTime.Hour, currentTime.Minute, 0);
if (adDispatchPlans != null && adDispatchPlans.ContainsKey(time.AddMinutes(-1)) && adDispatchPlans.ContainsKey(time.AddMinutes(1)))
{
//上一分钟
var lastMeidaAdPlans = adDispatchPlans[time.AddMinutes(-1)];
//下一分钟
var nextMediaAdPlans = adDispatchPlans[time.AddMinutes(1)];
//轮询处理每个媒体的广告
foreach (var lastAdMediaAdPlan in lastMeidaAdPlans.AsParallel())
{
var mediaId = lastAdMediaAdPlan.Key;
if (!nextMediaAdPlans.ContainsKey(mediaId))
{
nextMediaAdPlans[mediaId] = new ConcurrentDictionary<Ad, IDictionary<int, long>>();
}
//轮询处理该媒体内每个广告
foreach (var lastAdPlan in lastAdMediaAdPlan.Value)
{
int i = 0;
while (lastAdPlan.Value.ContainsKey(i))
{
if (!nextMediaAdPlans[mediaId].ContainsKey(lastAdPlan.Key))
{
nextMediaAdPlans[mediaId][lastAdPlan.Key] = new ConcurrentDictionary<int, long>();
}
//TODO:对于贴片位置定向的情况需要进行处理
nextMediaAdPlans[mediaId][lastAdPlan.Key][i + 1] = lastAdPlan.Value[i];
i++;
}
}
}
}
}
示例6: OnNavigatedToAsync
public override async Task OnNavigatedToAsync(object parameter, NavigationMode mode, IDictionary<string, object> state)
{
if (state.ContainsKey(nameof(this.FeaturedShows)))
{
this.FeaturedShows = state[nameof(this.FeaturedShows)] as ObservableCollection<Show>;
}
if (state.ContainsKey(nameof(this.NewReleaseShows)))
{
this.NewReleaseShows = state[nameof(this.NewReleaseShows)] as ObservableCollection<Show>;
}
state.Clear();
if (this._dataAcquired)
{
await Task.Yield();
return;
}
this.RetrieveFeaturedShows();
this.RetrieveOtherShows();
this._dataAcquired = true;
}
示例7: LoadPage
protected override void LoadPage(object target, string source, IDictionary<string, object> sourceData, IDictionary<string, object> uiProperties, bool navigateForward)
{
this.Application.NavigatingForward = navigateForward;
if (navigateForward)
{
if (breadcrumbs.Count == 0) {
breadcrumbs.Add(Config.Instance.InitialBreadcrumbName);
}
else if ((uiProperties != null) && (uiProperties.ContainsKey("Item")))
{
Item itm = (Item)uiProperties["Item"];
breadcrumbs.Add(itm.Name);
}
else if ((uiProperties != null) && (uiProperties.ContainsKey("Folder"))) {
FolderModel folder = (FolderModel)uiProperties["Folder"];
breadcrumbs.Add(folder.Name);
}
else
breadcrumbs.Add("");
}
else if (breadcrumbs.Count > 0)
breadcrumbs.RemoveAt(breadcrumbs.Count - 1);
base.LoadPage(target, source, sourceData, uiProperties, navigateForward);
}
示例8: ImgurAlbum
public ImgurAlbum(IDictionary<string, object> data)
{
var layoutRaw = (string)data["layout"];
var privacyRaw = (string)data["privacy"];
var timeAddedRaw = Convert.ToInt64(data["datetime"]);
var deleteHash = data.ContainsKey("deletehash") ? (string)data["deletehash"] : null;
var order = data.ContainsKey("order") ? Convert.ToInt32(data["order"]) : 0;
var imageArrayRaw = (IList<object>)data["images"];
var imageArray = imageArrayRaw.Select(image => new ImgurImage((IDictionary<string, object>)image)).ToList();
ID = (string) data["id"];
Title = (string) data["title"];
Description = (string) data["description"];
TimeAdded = ConvertDateTime(timeAddedRaw);
Cover = (string) data["cover"];
CoverWidth = Convert.ToInt32(data["cover_width"]);
CoverHeight = Convert.ToInt32(data["cover_height"]);
AccountID = data["account_url"] == null ? null : (string) data["account_url"];
Privacy = ConvertPrivacy(privacyRaw);
Layout = ConvertLayout(layoutRaw);
Views = Convert.ToInt32(data["views"]);
Link = new Uri((string) data["link"]);
Favorite = (bool) data["favorite"];
Nsfw = data["nsfw"] != null && (bool) data["nsfw"];
Section = data["section"] == null ? null : (string) data["section"];
Order = order;
DeleteHash = deleteHash;
ImagesCount = Convert.ToInt32(data["images_count"]);
Images = imageArray;
}
示例9: InitAppConfig
private void InitAppConfig()
{
Settings = new Dictionary<string, object>();
foreach (var key in ConfigurationManager.AppSettings.AllKeys)
{
Settings.Add(key, ConfigurationManager.AppSettings[key]);
}
if (Settings.ContainsKey("SmtpServer"))
SMTPServerUrl = Settings["SmtpServer"].ToString();
if (Settings.ContainsKey("MozuAuthUrl"))
BaseUrl = Settings["MozuAuthUrl"].ToString();
if (Settings.ContainsKey("MozuPCIUrl"))
BasePCIUrl = Settings["MozuPCIUrl"].ToString();
if (Settings.ContainsKey("AppName"))
AppName = Settings["AppName"].ToString();
SetProperties();
}
示例10: Button
public static IHtmlString Button(this HtmlHelper htmlHelper, string buttonText, string permissions, IDictionary<string, string> attributeDic)
{
var user = SecurityContextHolder.Get();
if (!string.IsNullOrWhiteSpace(permissions))
{
string[] permissionArray = permissions.Split(',');
var q = user.UrlPermissions.Where(p => permissionArray.Contains(p)).ToList();
if (q == null || q.Count() == 0)
{
return MvcHtmlString.Empty;
}
}
var button = new TagBuilder("button");
button.SetInnerText(buttonText);
if (attributeDic.ContainsKey("needconfirm") && bool.Parse(attributeDic["needconfirm"]))
{
if (attributeDic.ContainsKey("onclick"))
{
attributeDic["onclick"] = "if( confirm('" + string.Format(Resources.Global.Button_ConfirmOperation, buttonText) + "')){" + attributeDic["onclick"] + "}";
}
else
{
attributeDic.Add("onclick", "return confirm('" + string.Format(Resources.Global.Button_ConfirmOperation, buttonText) + "');");
}
}
button.MergeAttributes(attributeDic);
return new HtmlString(" " + button.ToString());
}
示例11: Match
public bool Match(HttpRequestMessage request, IHttpRoute route, string parameterName,
IDictionary<string, object> values, HttpRouteDirection routeDirection)
{
if (values == null)
{
return true;
}
if (!values.ContainsKey(parameterName) || !values.ContainsKey(Id))
{
return true;
}
string action = values[parameterName].ToString().ToLower();
if (string.IsNullOrEmpty(action))
{
values[parameterName] = request.Method.ToString();
}
else if (string.IsNullOrEmpty(values[Id].ToString()))
{
bool isAction = _array.All(item => action.StartsWith(item.ToLower()));
if (isAction)
{
return true;
}
//values[Id] = values[parameterName];
//values[parameterName] = request.Method.ToString();
}
return true;
}
示例12: FromJsonProtoTemplate
public static IConfigurationFlag FromJsonProtoTemplate(IDictionary<string, dynamic> protoTemplate)
{
string key = protoTemplate["key"];
ConfigurationFlagTypes type;
if (!Enum.TryParse<ConfigurationFlagTypes>(protoTemplate["type"], out type))
throw new ArgumentException("type can be one of BOOLEAN_FLAG, INTEGER_FLAG, SELECT_FLAG. Fix your emulator plugin.");
string description = protoTemplate["description"];
string defaultValue = protoTemplate["default"].ToString();
int max = 0;
int min = 0;
IList<IConfigurationFlagSelectValue> selectTypes = null;
if (protoTemplate.ContainsKey("max"))
{
max = (int)protoTemplate["max"];
}
if (protoTemplate.ContainsKey("min"))
{
min = (int)protoTemplate["min"];
}
if (protoTemplate.ContainsKey("values"))
{
selectTypes = ((IList<ConfigurationFlagSelectValue>)protoTemplate["values"].ToObject(typeof(IList<ConfigurationFlagSelectValue>)))
.Select(x => (IConfigurationFlagSelectValue)x).ToList();
}
return new ConfigurationFlag(key, type, defaultValue, description, max, min, selectTypes);
}
示例13: InitPageParameter
protected override void InitPageParameter(IDictionary<string, string> actionParameter)
{
if (actionParameter.ContainsKey("StartDate"))
{
this.tbStartDate.Text = actionParameter["StartDate"];
}
if (actionParameter.ContainsKey("EndDate"))
{
this.tbEndDate.Text = actionParameter["EndDate"];
}
if (actionParameter.ContainsKey("PartyCode"))
{
this.tbPartyCode.Text = actionParameter["PartyCode"];
}
if (actionParameter.ContainsKey("ReceiptNo"))
{
this.tbReceiptNo.Text = actionParameter["ReceiptNo"];
}
if (actionParameter.ContainsKey("ItemCode"))
{
this.tbItemCode.Text = actionParameter["ItemCode"];
}
if (actionParameter.ContainsKey("ExternalReceiptNo"))
{
this.tbExtReceiptNo.Text = actionParameter["ExternalReceiptNo"];
}
}
示例14: AddCommonProperties
/// <summary>
/// Helper private method to add additional common properties to all telemetry events via ref param
/// </summary>
/// <param name="properties">original properties to add to</param>
private static void AddCommonProperties(ref IDictionary<string, string> properties)
{
// add common properties as long as they don't already exist in the original properties passed in
if (!properties.ContainsKey("Custom_AppVersion"))
{
properties.Add("Custom_AppVersion", EnvironmentSettings.GetAppVersion());
}
if (!properties.ContainsKey("Custom_OSVersion"))
{
properties.Add("Custom_OSVersion", EnvironmentSettings.GetOSVersion());
}
#if MS_INTERNAL_ONLY // Do not send this app insights telemetry data for external customers. Microsoft only.
if (!properties.ContainsKey("userAlias"))
{
properties.Add("userAlias", App.Controller.XmlSettings.MicrosoftAlias);
}
if (!properties.ContainsKey("Custom_DeviceName"))
{
properties.Add("Custom_DeviceName", EnvironmentSettings.GetDeviceName());
}
if (!properties.ContainsKey("Custom_IPAddress"))
{
properties.Add("Custom_IPAddress", EnvironmentSettings.GetIPAddress());
}
#endif
}
示例15: UpgradeHandshaker
public UpgradeHandshaker(IDictionary<string, object> handshakeEnvironment)
{
InternalSocket = (SecureSocket)handshakeEnvironment["secureSocket"];
_end = (ConnectionEnd)handshakeEnvironment["end"];
_responseReceivedRaised = new ManualResetEvent(false);
_handshakeResult = new Dictionary<string, object>();
if (_end == ConnectionEnd.Client)
{
if (handshakeEnvironment.ContainsKey(":host") || (handshakeEnvironment[":host"] is string)
|| handshakeEnvironment.ContainsKey(":version") || (handshakeEnvironment[":version"] is string))
{
_headers = new Dictionary<string, object>
{
{":path", handshakeEnvironment[":path"]},
{":host", handshakeEnvironment[":host"]},
{":version", handshakeEnvironment[":version"]},
{":max_concurrent_streams", 100},
{":initial_window_size", 2000000},
};
}
else
{
throw new InvalidConstraintException("Incorrect header for upgrade handshake");
}
}
}