当前位置: 首页>>代码示例>>C#>>正文


C# NameValueCollection.HasKeys方法代码示例

本文整理汇总了C#中System.Collections.Specialized.NameValueCollection.HasKeys方法的典型用法代码示例。如果您正苦于以下问题:C# NameValueCollection.HasKeys方法的具体用法?C# NameValueCollection.HasKeys怎么用?C# NameValueCollection.HasKeys使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在System.Collections.Specialized.NameValueCollection的用法示例。


在下文中一共展示了NameValueCollection.HasKeys方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: HasKeys

		public void HasKeys ()
		{
			NameValueCollection c = new NameValueCollection (5, CaseInsensitiveHashCodeProvider.DefaultInvariant, CaseInsensitiveComparer.DefaultInvariant);
			Assert.IsTrue (!c.HasKeys (), "#1");
			c.Add ("foo1", "bar1");
			Assert.IsTrue (c.HasKeys (), "#2");
		}
开发者ID:nlhepler,项目名称:mono,代码行数:7,代码来源:NameValueCollectionTest.cs

示例2: ToQueryString

        public static string ToQueryString(NameValueCollection collection, bool startWithQuestionMark = true)
        {
            if (collection == null || !collection.HasKeys())
                return String.Empty;

            var sb = new StringBuilder();
            if (startWithQuestionMark)
                sb.Append("?");

            var j = 0;
            var keys = collection.Keys;
            foreach (string key in keys)
            {
                var i = 0;
                var values = collection.GetValues(key);
                foreach (var value in values)
                {
                    sb.Append(key)
                        .Append("=")
                        .Append(value);

                    if (++i < values.Length)
                        sb.Append("&");
                }
                if (++j < keys.Count)
                    sb.Append("&");
            }
            return sb.ToString();
        }
开发者ID:rfavillejr,项目名称:Thinktecture.IdentityServer.v2,代码行数:29,代码来源:SFHelper.cs

示例3: GetCleanedNameValueCollection

        protected static NameValueCollection GetCleanedNameValueCollection(NameValueCollection requestQueryString)
        {
            var nvc = new NameValueCollection(requestQueryString);

            if (nvc.HasKeys())
            {
                nvc.Remove(null);
            }

            return nvc;
        }
开发者ID:maksymilian-majer,项目名称:DevDefined.OAuth,代码行数:11,代码来源:OAuthContextBuilderHelpers.cs

示例4: SetUtmValuesCookie

        public void SetUtmValuesCookie()
        {
            var collection = HttpContext.Current.Request.QueryString;
            var validCollection = new NameValueCollection();
            var current = HttpContext.Current.Request.Cookies.Get("sourceData");
            if (current == null)
            {
                current = new HttpCookie("sourceData");

            }
            foreach (string key in collection.AllKeys)
            {
                if (key != null)
                {
                    if (ValidValues.ContainsKey(key))
                    {
                        validCollection.Add(key, collection[key]);

                    }
                }
            }

            //Check if the valid collection has anything to set, otherwise dont set cookie
            if (validCollection.HasKeys())
            {
                bool hasChanged = false;
                foreach (var key in validCollection.AllKeys)
                {
                    var value = collection[key];
                    if (current.Values.AllKeys.Contains(key))
                    {
                        if (current.Values[key] != collection[key])
                        {
                            current.Values[key] = collection[key];
                            hasChanged = true;
                        }

                    }
                    else
                    {
                        current.Values.Add(key, value);
                        hasChanged = true;
                    }
                }

                if (hasChanged)
                {
                    HttpContext.Current.Response.Cookies.Add(current);
                }
            }

        }
开发者ID:anandraj204,项目名称:First,代码行数:52,代码来源:SourceContext.cs

示例5: Initialize

 public override void Initialize(string name, NameValueCollection config)
 {
     if (config == null || !config.HasKeys())
         throw new ArgumentNullException("config");
     name = "UnlockedStateProvider";
     base.Initialize(name, config);
     if (!Configuration.ConfiguredAsStandardProvider)
     {
         lock (Configuration.ConfigurationCreationLock)
         {
             Configuration.ConfigureAsSdandardProvider(config);
         }
     }
 }
开发者ID:njfife,项目名称:playground,代码行数:14,代码来源:UnlockedRedisSessionStateProvider.cs

示例6: IPNMessage

 /// <summary>
 /// IPNMessage constructor
 /// </summary>
 /// <param name="nvc"></param>
 public IPNMessage(NameValueCollection nvc)
 {
     try
     {
         if (nvc.HasKeys())
         {
             foreach (string key in nvc.Keys)
             {
                 nvcMap.Add(key, nvc[key]);
             }
             ipnRequest = ConstructQueryString(nvc);
             ipnRequest += "&cmd=_notify-validate";
         }
     }
     catch (System.Exception ex)
     {
         logger.Debug(this.GetType().Name + " : " + ex.Message);
     }
 }
开发者ID:Cjrbro1280,项目名称:sdk-core-dotnet,代码行数:23,代码来源:IPNMessage.cs

示例7: CreateUri

        /// <summary>
        /// Create Uri
        /// </summary>
        /// <param name="baseUri">base uri</param>
        /// <param name="pathInfos">path infos</param>
        /// <param name="queryStrings">query strings</param>
        /// <param name="fragment">fragment string</param>
        /// <returns>request uri</returns>
        public static Uri CreateUri(
            Uri baseUri,
            IEnumerable<string> pathInfos,
            NameValueCollection queryStrings,
            string fragment)
        {
            UriBuilder uriBuilder;

            // build pathInfo
            if (pathInfos != null && pathInfos.Any())
            {
                uriBuilder = new UriBuilder(new Uri(baseUri, new Uri(ToPathInfo(pathInfos), UriKind.Relative)));
            }
            else
            {
                uriBuilder = new UriBuilder(baseUri);
            }

            // build queryString
            if (queryStrings != null && queryStrings.HasKeys())
            {
                var query = HttpUtility.ParseQueryString(baseUri.Query);
                foreach (string key in queryStrings)
                {
                    query[key] = queryStrings[key];
                }

                uriBuilder.Query = ToQueryString(query);
            }

            // append fragment
            if (!string.IsNullOrWhiteSpace(fragment))
            {
                uriBuilder.Fragment = HttpUtility.UrlEncode(fragment);
            }

            return uriBuilder.Uri;
        }
开发者ID:kenyamat,项目名称:Tatami-dotnet,代码行数:46,代码来源:HttpRequestService.cs

示例8: FindBestMatchingTemplate

        private UriTemplate FindBestMatchingTemplate(UriTemplateTable templates, object resourceKey, string uriName, NameValueCollection keyValues)
        {
            resourceKey = this.EnsureIsNotType(resourceKey);

            var matchingTemplates =
                from template in templates.KeyValuePairs
                let descriptor = (UrlDescriptor)template.Value
                where CompatibleKeys(resourceKey, descriptor.ResourceKey)
                where UriNameMatches(uriName, descriptor.UriName)
                let templateParameters =
                    template.Key.PathSegmentVariableNames.Concat(template.Key.QueryValueVariableNames).ToList()
                let hasKeys = keyValues != null && keyValues.HasKeys()
                where (templateParameters.Count == 0) ||
                      (templateParameters.Count > 0
                       && hasKeys
                       && templateParameters.All(x => keyValues.AllKeys.Contains(x, StringComparison.OrdinalIgnoreCase)))
                orderby templateParameters.Count descending
                select template.Key;

            return matchingTemplates.FirstOrDefault();
        }
开发者ID:endjin,项目名称:openrasta-stable,代码行数:21,代码来源:TemplatedUriResolver.cs

示例9: CreatePathWithQueryStrings

		private string CreatePathWithQueryStrings(string path, IConnectionConfigurationValues global, IRequestParameters request = null)
		{

			//Make sure we append global query string as well the request specific query string parameters
			var copy = new NameValueCollection(global.QueryStringParameters);
			var formatter = new UrlFormatProvider(this.ConnectionSettings);
			if (request != null)
				copy.Add(request.QueryString.ToNameValueCollection(formatter));
			if (!copy.HasKeys()) return path;

			var queryString = copy.ToQueryString();
			var tempUri = new Uri("http://localhost:9200/" + path).Purify();
			if (tempUri.Query.IsNullOrEmpty())
				path += queryString;
			else 
				path += "&" + queryString.Substring(1, queryString.Length - 1);
			return path;
		}
开发者ID:jeroenheijmans,项目名称:elasticsearch-net,代码行数:18,代码来源:RequestData.cs

示例10: CombobulateArgumentRequest

        /// <summary>
        /// Function that puts the authentication parameters from the request url in the request authentication header and parses the arguments as parameters for the controller
        /// </summary>
        /// <param name="request"></param>
        /// <returns></returns>
        public HttpRequestMessage CombobulateArgumentRequest(HttpRequestMessage request)
        {
            NameValueCollection requestParams = request.RequestUri.ParseQueryString();

            // Derive Authorization header from parameter
            if (request.Headers.Authorization == null)
            {
                string test = requestParams["arg0"];
                string test2 = requestParams["arg1"];
                string authHeader = String.Format("ApiUser={0}, SharedSecret={1}", requestParams["arg0"], requestParams["arg1"]);
                request.Headers.Authorization = new AuthenticationHeaderValue("LSR-DIGEST", authHeader);
            }

            // Build new uri without method and data array
            StringBuilder newPath = new StringBuilder(request.RequestUri.Scheme + "://");
            newPath.Append(request.RequestUri.Authority);
            newPath.Append(request.RequestUri.AbsolutePath);
            newPath.Append("/" + requestParams["method"] + "/");

            //// Find the data[], aka the function parameters
            NameValueCollection functionParams = new NameValueCollection();
            Regex r = new Regex(@"arg[0-9]+\[(?<parm>\w+)\]", RegexOptions.IgnoreCase);
            foreach (String s in requestParams.AllKeys)
            {
                Match m = r.Match(s);
                if (m.Success)
                    functionParams.Add(r.Match(s).Result("${parm}"), requestParams[s]);
            }

            if (functionParams.HasKeys())
            {
                newPath.Append("?");
                foreach (String s in functionParams.AllKeys)
                {
                    newPath.Append("&" + s + "=" + functionParams[s]);
                }
            }

            request.RequestUri = new Uri(newPath.ToString());

            return request;
        }
开发者ID:Pamplemousse09,项目名称:offerservice3,代码行数:47,代码来源:CommonMethods.cs

示例11: ParseRequest

        internal string ParseRequest(string url, NameValueCollection arguments, out long length)
        {
            try
            {
                var retval = url;
                if (arguments.HasKeys() && url == "/approve.html")
                    if (arguments["cid"] != null && arguments["action"] != null)
                    {
                        var client = Exts.FromBase64(arguments["cid"]);
                        if (DHCP.Clients.ContainsKey(client) && !DHCP.Clients[client].ActionDone)
                        {
                            if (arguments["action"] == "0")
                            {
                                DHCP.Clients[client].NextAction = Definitions.NextActionOptionValues.Referral;
                                DHCP.Clients[client].ActionDone = true;
                            }
                            else
                            {
                                DHCP.Clients[client].NextAction = Definitions.NextActionOptionValues.Abort;
                                DHCP.Clients[client].ActionDone = true;
                            }
                        }
                    }

                if (retval == "/approve.html")
                    retval = "/requests.html";

                if (retval == "/")
                    retval = "/index.html";

                if (!retval.EndsWith(".htm") && !retval.EndsWith(".html") && !retval.EndsWith(".js") &&
                    !retval.EndsWith(".css") && !retval.EndsWith(".png") && !retval.EndsWith(".gif") && !retval.EndsWith(".ico"))
                    throw new Exception("Unsupportet Content type!");

                var size = Filesystem.Size("http{0}".F(retval));
                length = size;

                if (size > Settings.MaxAllowedFileLength) // 10 MB
                    return null;

                return "http{0}".F(retval);
            }
            catch (Exception)
            {
                length = 0;
                return null;
            }
        }
开发者ID:LipkeGu,项目名称:bootpd,代码行数:48,代码来源:HTTP.cs

示例12: Initialize

        /// <summary>
        /// Sets up the profile providers
        /// </summary>
        /// <param name="name">
        /// </param>
        /// <param name="config">
        /// </param>
        public override void Initialize(string name, NameValueCollection config)
        {
            // verify that the configuration section was properly passed
            if (!config.HasKeys())
            {
                ExceptionReporter.ThrowArgument("ROLES", "CONFIGNOTFOUND");
            }

            // Application Name
            this._appName = config["applicationName"].ToStringDBNull(Config.ApplicationName);

            // Connection String Name
            this._connStrName = config["connectionStringName"].ToStringDBNull(Config.ConnectionStringName);

            // is the connection string set?
            if (this._connStrName.IsSet())
            {
                string connStr = ConfigurationManager.ConnectionStrings[this._connStrName].ConnectionString;
                _connectionString = connStr;
                ConnectionStringName = VZF.Data.DAL.SqlDbAccess.GetConnectionStringNameFromConnectionString(connStr);
                // set the app variable...
                if (YafContext.Current.Get<HttpApplicationStateBase>()[ConnStrAppKeyName] == null)
                {
                    YafContext.Current.Get<HttpApplicationStateBase>().Add(ConnStrAppKeyName, connStr);
                }
                else
                {
                    YafContext.Current.Get<HttpApplicationStateBase>()[ConnStrAppKeyName] = connStr;
                }
            }

            base.Initialize(name, config);

            // application name
            this._appName = config["applicationName"];

            if (string.IsNullOrEmpty(this._appName))
            {
                this._appName = "YetAnotherForum";
            }
        }
开发者ID:vzrus,项目名称:VZF,代码行数:48,代码来源:YafRoleProvider.cs

示例13: ShellParameterService

        /// <summary>
        /// Create an instance of the service using the System.Environment and
        /// AppDomain.CurrentDomain.SetupInformation.ActivationArguments
        /// </summary>
        public ShellParameterService()
        {
            this.ArgTable = new System.Collections.Specialized.NameValueCollection();
            List<string> Args = new List<string>(System.Environment.GetCommandLineArgs());
            Args.RemoveAt(0);

            string AppWebsite = "";
            string website = "http://connectomes.utah.edu/Rabbit/Volume.VikingXML";
             //   string homepage = "http://connectomes.utah.edu/";

            if (Args.Count > 0)
            {
                website = Args[0];
            }
            else
            {
                bool ShowUsage = true;
                if (AppDomain.CurrentDomain.SetupInformation.ActivationArguments != null)
                {
                    string[] ClickOnceArgs = AppDomain.CurrentDomain.SetupInformation.ActivationArguments.ActivationData;
                    if (ClickOnceArgs != null && ClickOnceArgs.Length > 0)
                    {
                        Trace.WriteLine("ActivationArguments: ");
                        foreach (string arg in ClickOnceArgs)
                            Trace.WriteLine(arg, "Viking");

                        string FirstArg = System.Web.HttpUtility.HtmlDecode(ClickOnceArgs[0]);
                        string[] HttpArgs = FirstArg.Split('?');

                        AppWebsite = HttpArgs[0]; //The website we use to launch Viking
                        Trace.WriteLine("Application Website: " + AppWebsite, "Viking");

                        if (HttpArgs.Length == 0)
                        {
                            //Sometimes the only argument passed is the application directory
                            if (!HttpArgs[0].ToLower().EndsWith(".application"))
                            {
                                website = HttpArgs[1];
                                ShowUsage = false;
                            }
                        }
                        //Parse the arguments
                        else if (HttpArgs.Length > 1)
                        {
                            ArgTable = System.Web.HttpUtility.ParseQueryString(HttpArgs[1]);

                            if (ArgTable.HasKeys())
                            {
                                //PORT WPF
                                //UI.State.StartupArguments = QueryTable;
                                string VolumeValue = ArgTable["Volume"];
                                if (VolumeValue != null)
                                {
                                    website = VolumeValue;
                                    ShowUsage = false;
                                }
                            }
                            else
                            {
                                website = HttpArgs[1];
                                ShowUsage = false;
                            }
                        }
                    }
                }

                if (ShowUsage)
                {
                    //Launch the viking home page and exit

                    System.Windows.MessageBox.Show("No volume definition file was specified.  Loading RC1 by default.  You can pass a website as the first argument to launch a different volume, or select a volume definition from the website: http://connectomes.utah.edu/", "Viking", System.Windows.MessageBoxButton.OK);
                    //System.Diagnostics.Process WebBrowser = new System.Diagnostics.Process();
                    //WebBrowser.StartInfo.FileName = homepage;
                    //WebBrowser.Start();
                }
            }

            //Make sure the website includes a file, if it does not then include Volume.VikingXML by default
            Uri WebsiteURI = new Uri(website);
            string path = WebsiteURI.GetComponents(UriComponents.Path, UriFormat.SafeUnescaped);
            if (path.Contains(".") == false)
            {
                if (website.EndsWith("/") == false)
                    website = website + "/";

                website = website + "volume.VikingXML";
                WebsiteURI = new Uri(website);
            }

            string HostPath = System.IO.Path.GetDirectoryName(website);

            //Add the host property to the properties
            ArgTable.Add("Host", website);
            ArgTable.Add("HostPath", HostPath);

            //Add the host's subpath to the properties
//.........这里部分代码省略.........
开发者ID:abordt,项目名称:Viking,代码行数:101,代码来源:ShellParametersService.cs

示例14: Test01

        public void Test01()
        {
            IntlStrings intl;
            NameValueCollection nvc;

            // simple string values
            string[] values =
            {
                "",
                " ",
                "a",
                "aA",
                "text",
                "     SPaces",
                "1",
                "$%^#",
                "2222222222222222222222222",
                System.DateTime.Today.ToString(),
                Int32.MaxValue.ToString()
            };

            // keys for simple string values
            string[] keys =
            {
                "zero",
                "oNe",
                " ",
                "",
                "aa",
                "1",
                System.DateTime.Today.ToString(),
                "$%^#",
                Int32.MaxValue.ToString(),
                "     spaces",
                "2222222222222222222222222"
            };

            int cnt = 0;            // Count

            // [] initialize IntStrings
            intl = new IntlStrings();


            // [] NameValueCollection is constructed as expected
            //-----------------------------------------------------------------

            nvc = new NameValueCollection();
            cnt = nvc.Count;
            if (cnt != 0)
            {
                Assert.False(true, string.Format("Error, count is {0} instead of {1} after default ctor", nvc.Count, 0));
            }

            //
            //  [] on empty collection
            //
            if (nvc.HasKeys())
            {
                Assert.False(true, "Error, HasKeys returned true after default ctor");
            }


            //  [] Add simple strings and HasKeys()
            //
            cnt = nvc.Count;
            for (int i = 0; i < values.Length; i++)
            {
                nvc.Add(keys[i], values[i]);
            }
            if (nvc.Count != values.Length)
            {
                Assert.False(true, string.Format("Error, count is {0} instead of {1}", nvc.Count, values.Length));
            }

            if (!nvc.HasKeys())
            {
                Assert.False(true, string.Format("Error, returned false for collection with {0} items", nvc.Count));
            }


            //
            // [] Add Intl strings and HasKeys()
            //
            int len = values.Length;
            string[] intlValues = new string[len * 2];

            // fill array with unique strings
            //
            for (int i = 0; i < len * 2; i++)
            {
                string val = intl.GetRandomString(MAX_LEN);
                while (Array.IndexOf(intlValues, val) != -1)
                    val = intl.GetRandomString(MAX_LEN);
                intlValues[i] = val;
            }

            //   Add items
            //
            cnt = nvc.Count;
            for (int i = 0; i < len; i++)
//.........这里部分代码省略.........
开发者ID:er0dr1guez,项目名称:corefx,代码行数:101,代码来源:HasKeysTests.cs

示例15: FromNamedValueCollection

            public static PostContentData[] FromNamedValueCollection(NameValueCollection nvc)
            {
                var result = new List<PostContentData>();

                try
                {
                    if (nvc != null && nvc.Count > 0 && nvc.HasKeys())
                    {
                        var keys = nvc.AllKeys.ToList();

                        foreach (var key in keys)
                        {
                            var vals = "";
                            foreach (var val in nvc.GetValues(key)) vals += val;

                            result.Add(new PostContentData(key, vals));
                        }
                    }
                }
                catch (Exception ex) { }

                return result.ToArray();
            }
开发者ID:TrakHound,项目名称:TrakHound-Community,代码行数:23,代码来源:HTTP.cs


注:本文中的System.Collections.Specialized.NameValueCollection.HasKeys方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。