本文整理汇总了C#中NameValueCollection.Remove方法的典型用法代码示例。如果您正苦于以下问题:C# NameValueCollection.Remove方法的具体用法?C# NameValueCollection.Remove怎么用?C# NameValueCollection.Remove使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类NameValueCollection
的用法示例。
在下文中一共展示了NameValueCollection.Remove方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: btnAnChitiet_Click
//protected void btnLuuGiaytonopkem_Click(object sender, EventArgs e)
//{
// String sDangkyChungnhan = btnLuuGiaytonopkem.CommandArgument;
// if(sDangkyChungnhan != null)
// {
// Int16 iDangkyChungnhan = Int16.Parse(sDangkyChungnhan);
// List<HosokemtheoTochucchungnhanEntity> lstHosonopkem = HosokemtheoTochucchungnhanBRL.GetByFK_iDangkyChungnhanVietGapID(iDangkyChungnhan);
// HosokemtheoTochucchungnhanEntity oHosonopkem = null;
// foreach (ListItem chk in cblGiaytonopkem.Items)
// {
// oHosonopkem = null;
// oHosonopkem = lstHosonopkem.Find(
// delegate(HosokemtheoTochucchungnhanEntity oHosonopkemFound)
// {
// return oHosonopkemFound.FK_iGiaytoID.ToString().Equals(chk.Value);
// }
// );
// if (oHosonopkem == null)
// {
// if (chk.Selected)
// {
// HosokemtheoTochucchungnhanEntity oHosonopkemNew = new HosokemtheoTochucchungnhanEntity();
// oHosonopkemNew.FK_iGiaytoID = int.Parse(chk.Value);
// oHosonopkemNew.FK_iDangkyChungnhanVietGapID = iDangkyChungnhan;
// HosokemtheoTochucchungnhanBRL.Add(oHosonopkemNew);
// }
// }
// else
// {
// if (!chk.Selected)
// {
// HosokemtheoTochucchungnhanBRL.Remove(oHosonopkem.PK_iHosokemtheoID);
// }
// lstHosonopkem.Remove(oHosonopkem); //Loại bỏ phần tử đã tìm thấy để tối ưu
// }
// }
// lstHosonopkem = null;
// lblThongbao.Text = "Lưu thành công!";
// }
//}
//protected void btnHuygiaytonopkem_Click(object sender, EventArgs e)
//{
// panGiayto.Visible = false;
//}
protected void btnAnChitiet_Click(object sender, EventArgs e)
{
pnThongTin.Visible = false;
NameValueCollection filtered = new NameValueCollection(Request.QueryString);
filtered.Remove("iTochucchungnhanID");
filtered.Remove("PK_iDangkyChungnhanVietGapID");
}
示例2: Initialize
/// <summary>
/// Initialize the session state provider
/// </summary>
public override void Initialize(string name, NameValueCollection config)
{
if (config == null)
throw new ArgumentNullException("config");
if (name == null || name.Length == 0)
name = "SqlSessionStateProvider";
if (String.IsNullOrEmpty(config["description"]))
{
config.Remove("description");
config.Add("description", "Sql session state provider");
}
// Initialize the abstract base class.
base.Initialize(name, config);
// Set the application name
this.applicationName = System.Web.Hosting.HostingEnvironment.ApplicationVirtualPath;
// Get the session state configuration
Configuration cfg = WebConfigurationManager.OpenWebConfiguration(this.applicationName);
sessionStateConfiguration = (SessionStateSection)cfg.GetSection("system.web/sessionState");
} // End of the Initialize method
示例3: Initialize
public override void Initialize(string name,
NameValueCollection config)
{
// Verify that config isn't null
if (config == null)
throw new ArgumentNullException("config");
// Assign the provider a default name if it doesn't have one
if (String.IsNullOrEmpty(name))
name = "TextFileWebEventProvider";
// Add a default "description" attribute to config if the
// attribute doesn't exist or is empty
if (string.IsNullOrEmpty(config["description"]))
{
config.Remove("description");
config.Add("description", "Text file Web event provider");
}
// Call the base class's Initialize method
base.Initialize(name, config);
// Initialize _LogFileName and make sure the path
// is app-relative
string path = config["logFileName"];
if (String.IsNullOrEmpty(path))
throw new ProviderException
("Missing logFileName attribute");
if (!VirtualPathUtility.IsAppRelative(path))
throw new ArgumentException
("logFileName must be app-relative");
string fullyQualifiedPath = VirtualPathUtility.Combine
(VirtualPathUtility.AppendTrailingSlash
(HttpRuntime.AppDomainAppVirtualPath), path);
_LogFileName = HostingEnvironment.MapPath(fullyQualifiedPath);
config.Remove("logFileName");
// Make sure we have permission to write to the log file
// throw an exception if we don't
FileIOPermission permission =
new FileIOPermission(FileIOPermissionAccess.Write |
FileIOPermissionAccess.Append, _LogFileName);
permission.Demand();
// Throw an exception if unrecognized attributes remain
if (config.Count > 0)
{
string attr = config.GetKey(0);
if (!String.IsNullOrEmpty(attr))
throw new ProviderException
("Unrecognized attribute: " + attr);
}
}
示例4: Remove_NullName
public void Remove_NullName()
{
NameValueCollection nameValueCollection = new NameValueCollection();
nameValueCollection.Add(null, "value");
nameValueCollection.Remove(null);
Assert.Equal(0, nameValueCollection.Count);
Assert.Null(nameValueCollection[null]);
}
示例5: Remove_MultipleValues_SameName
public void Remove_MultipleValues_SameName()
{
NameValueCollection nameValueCollection = new NameValueCollection();
string name = "name";
nameValueCollection.Add(name, "value1");
nameValueCollection.Add(name, "value2");
nameValueCollection.Add(name, "value3");
nameValueCollection.Remove(name);
Assert.Null(nameValueCollection[name]);
}
示例6: Ctor_NameValueCollection
public void Ctor_NameValueCollection(NameValueCollection nameValueCollection1)
{
NameValueCollection nameValueCollection2 = new NameValueCollection(nameValueCollection1);
Assert.Equal(nameValueCollection1.Count, nameValueCollection2.Count);
Assert.Equal(nameValueCollection1.Keys, nameValueCollection2.Keys);
Assert.Equal(nameValueCollection1.AllKeys, nameValueCollection2.AllKeys);
Assert.False(((ICollection)nameValueCollection2).IsSynchronized);
// Modify nameValueCollection1 does not affect nameValueCollection2
string previous = nameValueCollection1["Name_1"];
nameValueCollection1["Name_1"] = "newvalue";
Assert.Equal(previous, nameValueCollection2["Name_1"]);
nameValueCollection1.Remove("Name_1");
Assert.Equal(previous, nameValueCollection2["Name_1"]);
}
示例7: Initialize
// BlogsaRoleProvider methods
public override void Initialize(string name, NameValueCollection config)
{
if (config == null)
throw new ArgumentNullException("config");
if (String.IsNullOrEmpty(name))
name = "SITRoleProvider";
if (string.IsNullOrEmpty(config["description"]))
{
config.Remove("description");
config.Add("description", "SIT Role Provider");
}
base.Initialize(name, config);
//FileIOPermission permission =
// new FileIOPermission(FileIOPermissionAccess.Read,
// _XmlFileName);
//permission.Demand();
if (config.Count > 0)
{
string attr = config.GetKey(0);
if (!String.IsNullOrEmpty(attr))
throw new ProviderException
("Unrecognized attribute: " + attr);
}
}
示例8: runTest
public virtual bool runTest()
{
Console.WriteLine(s_strTFPath + " " + s_strTFName + " , for " + s_strClassMethod + " , Source ver: " + s_strDtTmVer);
int iCountErrors = 0;
int iCountTestcases = 0;
IntlStrings intl;
String strLoc = "Loc_000oo";
NameValueCollection nvc;
string [] values =
{
"",
" ",
"a",
"aA",
"text",
" SPaces",
"1",
"$%^#",
"2222222222222222222222222",
System.DateTime.Today.ToString(),
Int32.MaxValue.ToString()
};
string [] keys =
{
"zero",
"oNe",
" ",
"",
"aa",
"1",
System.DateTime.Today.ToString(),
"$%^#",
Int32.MaxValue.ToString(),
" spaces",
"2222222222222222222222222"
};
int cnt = 0;
string [] ks;
try
{
intl = new IntlStrings();
Console.WriteLine("--- create collection ---");
strLoc = "Loc_001oo";
iCountTestcases++;
nvc = new NameValueCollection();
Console.WriteLine("1. Remove() on empty collection");
iCountTestcases++;
cnt = nvc.Count;
Console.WriteLine(" - Remove(null)");
nvc.Remove(null);
if (nvc.Count != cnt)
{
iCountErrors++;
Console.WriteLine("Err_0001a, changed collection after Remove(null)");
}
iCountTestcases++;
cnt = nvc.Count;
Console.WriteLine(" - Remove(some_string)");
nvc.Remove("some_string");
if (nvc.Count != cnt)
{
iCountErrors++;
Console.WriteLine("Err_0001b, changed collection after Remove(some_string)");
}
Console.WriteLine("2. add simple strings, remove them via Remove(string)");
strLoc = "Loc_002oo";
iCountTestcases++;
cnt = nvc.Count;
int len = values.Length;
for (int i = 0; i < len; i++)
{
nvc.Add(keys[i], values[i]);
}
if (nvc.Count != len)
{
iCountErrors++;
Console.WriteLine("Err_0002a, count is {0} instead of {1}", nvc.Count, values.Length);
}
for (int i = 0; i < len; i++)
{
cnt = nvc.Count;
iCountTestcases++;
nvc.Remove(keys[i]);
if (nvc.Count != cnt - 1)
{
iCountErrors++;
Console.WriteLine("Err_0002_{0}b, returned: failed to remove item", i);
}
ks = nvc.AllKeys;
iCountTestcases++;
if ( Array.IndexOf(ks, keys[i]) > -1 )
{
iCountErrors++;
Console.WriteLine("Err_0002_{0}c, removed wrong item", i);
}
}
Console.WriteLine("3. add intl strings and Remove()");
strLoc = "Loc_003oo";
iCountTestcases++;
string [] intlValues = new string [len * 2];
//.........这里部分代码省略.........
示例9: Initialize
public override void Initialize(String name, NameValueCollection config)
{
// if the parameter name is empty, use the default name
if (name == null || name.Trim() == String.Empty)
{
name = _name;
}
// if no configuration attributes found, throw an exception
if (config == null)
{
throw new ArgumentNullException("config", "There are no configuration attributes in web.config!");
}
// if no 'description' attribute in the configuration, use the default
String cfg_description = config["description"];
if (cfg_description == null || cfg_description.Trim() == "")
{
config.Remove("description");
config.Add("description", _description);
}
// if there is no 'connectionStringName' in the configuration, throw an exception
// otherwise extract the connection string from the web.config
// and test it, if it is not working throw an exception
String cfg_connectionStringName = config["connectionStringName"];
if (cfg_connectionStringName == null || cfg_connectionStringName.Trim() == "")
{
throw new ProviderException("Provider configuration attribute 'connectionStringName' in web.config is missing or blank!");
}
else
{
// get the entry refrenced by the 'connectionStringName'
ConnectionStringSettings connObj = ConfigurationManager.ConnectionStrings[cfg_connectionStringName];
// if you can't find the entry defined by the 'connectionStringName' or it is empty, throw an exception
if (connObj != null && connObj.ConnectionString != null && connObj.ConnectionString.Trim() != "")
{
try
{
// try testing the connection
using (SqlConnection conn = new SqlConnection(connObj.ConnectionString))
{
conn.Open();
_connectionStringName = connObj.ConnectionString;
}
}
catch (Exception e)
{
// if anything wrong happened, throw an exception showing what happened
ProviderException pException = new ProviderException(
String.Format("Connection string '{0}' in web.config is not usable!", cfg_connectionStringName), e);
throw pException;
}
}
else
{
throw new ProviderException(String.Format("Connection string '{0}' in web.config is missing or blank!",
cfg_connectionStringName));
}
}
// if there is no 'commandTimeout' attribute in the configuration, use the default
// otherwise try to get it, if errors ocurred, throw an exception
String cfg_commandTimeout = config["commandTimeout"];
if (cfg_commandTimeout == null || cfg_commandTimeout.Trim() == String.Empty)
{
}
else
{
Int32 _ct;
if (Int32.TryParse(cfg_commandTimeout, out _ct) && _ct >= 0)
{
_commandTimeout = _ct;
}
else
{
throw new ProviderException("Provider property 'commandTimeout' in web.config is not valid!");
}
}
// initialize the SqlProfileProvider with the current parameters
base.Initialize(name, config);
// throw an exception if unrecognized attributes remain
if (config.Count > 0)
{
String strAttributes = "";
for (int i = 0; i < config.Count; i++)
{
strAttributes += config.GetKey(i);
if (i < config.Count - 1)
{
strAttributes += ", ";
}
//.........这里部分代码省略.........
示例10: SetQueryString
/// <summary>
/// QuseryString處理
/// </summary>
/// <param name="dic">預設參數</param>
/// <param name="dicAdd">新增參數</param>
/// <param name="strRemove">移除參數</param>
/// <returns>組成QuseryString</returns>
public static string SetQueryString(bool isClear, Dictionary<string, string> dic, Dictionary<string, string> dicAdd, string[] strRemove)
{
StringBuilder sbQueryString = new StringBuilder();
NameValueCollection nvc = new NameValueCollection();
//如不清除原本的參數,並取得目前的QueryString轉為NameValueCollection物件
if (!isClear & HttpContext.Current.Request.QueryString.Count > 0)
{
nvc.Add(HttpContext.Current.Request.QueryString);
}
//加入預設參數
foreach (KeyValuePair<string, string> kvp in dic)
{
nvc.Add(kvp.Key, kvp.Value);
}
//新增參數
if (dicAdd != null)
{
foreach (KeyValuePair<string, string> kvp in dicAdd)
{
nvc.Add(kvp.Key, kvp.Value);
}
}
//移除參數
if (strRemove != null)
{
foreach (string strKey in strRemove)
{
nvc.Remove(strKey);
}
}
//轉回組成QueryString
foreach (string strKey in nvc.AllKeys)
{
string[] strValues = nvc.GetValues(strKey);
foreach (string strValue in strValues)
{
sbQueryString.Append(("&" + strKey + "=") + HttpUtility.UrlEncode(strValue));
}
}
//第一個字元處理
if (sbQueryString.Length > 0)
{
sbQueryString.Remove(0, 1);
sbQueryString.Insert(0, "?");
}
return sbQueryString.ToString();
}
示例11: runTest
//.........这里部分代码省略.........
iCountErrors++;
Console.WriteLine("Err_0004_{0}_b, didn't replace value", i);
}
}
iCountTestcases++;
if (nvc.AllKeys.Length != 1)
{
iCountErrors++;
Console.WriteLine("Err_0004c, should contain only 1 key");
}
iCountTestcases++;
if (Array.IndexOf(nvc.AllKeys, k) < 0)
{
iCountErrors++;
Console.WriteLine("Err_0004b, collection doesn't contain key of new item");
}
string [] vals = nvc.GetValues(k);
if (vals.Length != 1)
{
iCountErrors++;
Console.WriteLine("Err_0004d, number of values at given key is {0} instead of {1}", vals.Length, 1);
}
iCountTestcases++;
if (Array.IndexOf(vals, "Value"+(len-1).ToString()) < 0 )
{
iCountErrors++;
Console.WriteLine("Err_0004e, value is not {0}", "Value"+(len-1));
}
Console.WriteLine("5. Set (string, null) ");
strLoc = "Loc_005oo";
iCountTestcases++;
k = "kk";
Console.WriteLine(" - no item with such key initially");
nvc.Remove(k);
cnt = nvc.Count;
Console.WriteLine(" initial number of items: " + cnt);
nvc.Set(k, null);
iCountTestcases++;
if (nvc.Count != cnt+1)
{
iCountErrors++;
Console.WriteLine("Err_0005a, count is {0} instead of {1}", nvc.Count, cnt+1);
}
iCountTestcases++;
if (Array.IndexOf(nvc.AllKeys, k) < 0)
{
iCountErrors++;
Console.WriteLine("Err_0005b, collection doesn't contain key of new item");
}
iCountTestcases++;
if (nvc[k] != null)
{
iCountErrors++;
Console.WriteLine("Err_0005c, returned non-null on place of null");
}
Console.WriteLine(" - item with such key is initially present");
nvc.Remove(k);
nvc.Add(k, "kItem");
cnt = nvc.Count;
Console.WriteLine(" initial number of items: " + cnt);
nvc.Set(k, null);
iCountTestcases++;
if (nvc.Count != cnt)
{
iCountErrors++;
Console.WriteLine("Err_0005d, count has changed: {0} instead of {1}", nvc.Count, cnt);
示例12: Initialize
public override void Initialize(string name, NameValueCollection config)
{
// Verify that config isn't null
if (config == null)
throw new ArgumentNullException("config");
// Assign the provider a default name if it doesn't have one
if (String.IsNullOrEmpty(name))
name = "SubSonicSiteMapProvider";
// Add a default "description" attribute to config if the
// attribute doesn�t exist or is empty
if (string.IsNullOrEmpty(config["description"]))
{
config.Remove("description");
config.Add("description", "SubSonic site map provider");
}
// Call the base class's Initialize method
base.Initialize(name, config);
}
示例13: Initialize
public override void Initialize(string name, NameValueCollection config)
{
// Verify that config isn't null
if (config == null)
throw new ArgumentNullException("config");
// Assign the provider a default name if it doesn't have one
if (String.IsNullOrEmpty(name))
name = "SqlSiteMapProvider";
// Add a default "description" attribute to config if the
// attribute doesn?t exist or is empty
if (string.IsNullOrEmpty(config["description"]))
{
config.Remove("description");
config.Add("description", "SQL site map provider");
}
// Call the base class's Initialize method
base.Initialize(name, config);
// Initialize _connect
string connect = config["connectionStringName"];
if (String.IsNullOrEmpty(connect))
throw new ProviderException(_errmsg5);
config.Remove("connectionStringName");
if (WebConfigurationManager.ConnectionStrings[connect] == null)
throw new ProviderException(_errmsg6);
_connect = WebConfigurationManager.ConnectionStrings[connect].ConnectionString;
if (String.IsNullOrEmpty(_connect))
throw new ProviderException(_errmsg7);
// Initialize SQL cache dependency info
string dependency = config["sqlCacheDependency"];
if (!String.IsNullOrEmpty(dependency))
{
if (String.Equals(dependency, "CommandNotification", StringComparison.InvariantCultureIgnoreCase))
{
SqlDependency.Start(_connect);
_2005dependency = true;
}
else
{
// If not "CommandNotification", then extract database and table names
string[] info = dependency.Split(new char[] { ':' });
if (info.Length != 2)
throw new ProviderException(_errmsg8);
_database = info[0];
_table = info[1];
}
config.Remove("sqlCacheDependency");
}
// SiteMapProvider processes the securityTrimmingEnabled
// attribute but fails to remove it. Remove it now so we can
// check for unrecognized configuration attributes.
if (config["securityTrimmingEnabled"] != null)
config.Remove("securityTrimmingEnabled");
// Throw an exception if unrecognized attributes remain
if (config.Count > 0)
{
string attr = config.GetKey(0);
if (!String.IsNullOrEmpty(attr))
throw new ProviderException("Unrecognized attribute: " + attr);
}
}
示例14: Initialize
//
// System.Configuration.Provider.ProviderBase.Initialize Method
//
public override void Initialize(string name, NameValueCollection config)
{
//
// Initialize values from web.config.
//
if (config == null)
throw new ArgumentNullException("config");
if (name == null || name.Length == 0)
name = "CustomRoleProvider";
if (String.IsNullOrEmpty(config["description"]))
{
config.Remove("description");
config.Add("description", "Custom Role provider");
}
// Initialize the abstract base class.
base.Initialize(name, config);
if (config["applicationName"] == null || config["applicationName"].Trim() == "")
{
pApplicationName = System.Web.Hosting.HostingEnvironment.ApplicationVirtualPath;
}
else
{
pApplicationName = config["applicationName"];
}
if (config["writeExceptionsToEventLog"] != null)
{
if (config["writeExceptionsToEventLog"].ToUpper() == "TRUE")
{
pWriteExceptionsToEventLog = true;
}
}
//
// Initialize Connection.
//
/*
SqlConnection pConnectionStringSettings = new SqlConnection();
pConnectionStringSettings.ConnectionString = ConfigurationManager.ConnectionStrings["ManPro_Memeberships_Roles"].ConnectionString.ToString();
if (pConnectionStringSettings == null || pConnectionStringSettings.ConnectionString.Trim() == "")
{
throw new ProviderException("Connection string cannot be blank.");
}
connectionString = pConnectionStringSettings.ConnectionString;
*/
connectionString = ConfigurationManager.ConnectionStrings["GRASP_MemberShip"].ConnectionString;
}
示例15: VerifyCtor_IEqualityComparer
public void VerifyCtor_IEqualityComparer(NameValueCollection nameValueCollection, IEqualityComparer equalityComparer, int newCount)
{
Assert.Equal(0, nameValueCollection.Count);
Assert.Equal(0, nameValueCollection.Keys.Count);
Assert.Equal(0, nameValueCollection.AllKeys.Length);
Assert.False(((ICollection)nameValueCollection).IsSynchronized);
string[] values = new string[newCount];
for (int i = 0; i < newCount; i++)
{
string value = "Value_" + i;
nameValueCollection.Add("Name_" + i, value);
values[i] = value;
}
if (equalityComparer?.GetType() == typeof(IdiotComparer))
{
Assert.Equal(1, nameValueCollection.Count);
string expectedValues = string.Join(",", values);
Assert.Equal(expectedValues, nameValueCollection["Name_1"]);
Assert.Equal(expectedValues, nameValueCollection["any-name"]);
nameValueCollection.Remove("any-name");
Assert.Equal(0, nameValueCollection.Count);
}
else
{
Assert.Equal(newCount, nameValueCollection.Count);
nameValueCollection.Remove("any-name");
Assert.Equal(newCount, nameValueCollection.Count);
}
}