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


C# IDictionary.ToArray方法代码示例

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


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

示例1: DemoAction

 public ActionResult DemoAction(IDictionary<string, Contact> contacts)
 {
     var contactArray = contacts.ToArray();
     Dictionary<string, object> parameters = new Dictionary<string, object>();
     foreach (var item in contacts)
     {
         string address = string.Format("{0}省{1}市{2}{3}",item.Value.Address.Province, item.Value.Address.City,item.Value.Address.District, item.Value.Address.Street);
         parameters.Add(string.Format("contacts[\"{0}\"].Name", item.Key),item.Value.Name);
         parameters.Add(string.Format("contacts[\"{0}\"].PhoneNo", item.Key),item.Value.PhoneNo);
         parameters.Add(string.Format("contacts[\"{0}\"].EmailAddress",item.Key), item.Value.EmailAddress);
         parameters.Add(string.Format("contacts[\"{0}\"].Address", item.Key),address);
     }
     return View("DemoAction", parameters);
 }
开发者ID:xiaohong2015,项目名称:.NET,代码行数:14,代码来源:HomeController.cs

示例2: FinalizeEntries

        private static void FinalizeEntries(Node node, IDictionary<string, IList<Entry>> waiting, System.IO.FileInfo fileInfo)
        {
            int lastCount = 0;
            int count = 0;
            do
            {
                lastCount = count;
                count = 0;
                foreach (var waitingInfo in waiting.ToArray())
                {
                    Node dir = GetDirectory(waitingInfo.Key, node);
                    if ((dir == null))
                    {
                        dir = GetDirectory(waitingInfo.Key.Substring(0, Math.Max(0, waitingInfo.Key.LastIndexOf('/'))), node);
                        if (dir != null)
                        {
                            Entry dirEntry = Entry.CreateZipDirectoryEntry(waitingInfo.Key.Substring(waitingInfo.Key.LastIndexOf('/') + 1), fileInfo.LastWriteTime);
                            dirEntry.Node = new Node();
                            dir.Nodes.Add(dirEntry);
                            dir = dirEntry.Node;
                        }
                    }
                    if (dir != null)
                    {
                        foreach (var dirEntry in waitingInfo.Value)
                        {
                            dir.Nodes.Add(dirEntry);
                        }
                        waiting.Remove(waitingInfo.Key);
                    }

                    else
                    {
                        count += waitingInfo.Value.Count;
                    }
                }
            }
            while ((count > 0) && (lastCount != count));
        }
开发者ID:BGCX261,项目名称:zipdirfs-svn-to-git,代码行数:39,代码来源:ZipFileGenerator.cs

示例3: OverrideGlobals

 public static TestBlobCache OverrideGlobals(IDictionary<string, byte[]> initialContents, IScheduler scheduler = null)
 {
     return OverrideGlobals(scheduler, initialContents.ToArray());
 }
开发者ID:ThomasLebrun,项目名称:Akavache,代码行数:4,代码来源:TestBlobCache.cs

示例4: UnSubscribe

		private void UnSubscribe(IDictionary<Security, List<IChartElement>> elements, IChartElement element)
		{
			lock (_syncRoot)
			{
				foreach (var pair in elements.ToArray())
				{
					if (!pair.Value.Remove(element))
						continue;

					if (pair.Value.Count == 0)
						elements.Remove(pair.Key);
				}
			}
		}
开发者ID:reddream,项目名称:StockSharp,代码行数:14,代码来源:TerminalStrategy.cs

示例5: SetCustomProperties

        public Task<ActionResult> SetCustomProperties(string slug, IDictionary<string, string> settings)
        {
            if (settings != null && settings.Count > 0)
            {
                // validate custom property name/values
                int i = 0;
                foreach (var setting in settings)
                {
                    if (string.IsNullOrWhiteSpace(setting.Key))
                    {
                        ModelState.AddModelError(String.Format("Settings[{0}].Key", i), "property name cannot be empty");
                    }

                    if (string.IsNullOrWhiteSpace(setting.Value))
                    {
                        ModelState.AddModelError(String.Format("Settings[{0}].Value", i), "property value cannot be empty");
                    }
                    i++;
                }

                if (ModelState.IsValid)
                {
                    var tcs = new TaskCompletionSource<ActionResult>();
                    _service.SetKuduSettings(slug, settings.ToArray())
                                   .ContinueWith(task =>
                                   {
                                       if (task.IsFaulted)
                                       {
                                           tcs.SetException(task.Exception.InnerExceptions);
                                       }
                                       else
                                       {
                                           tcs.SetResult(RedirectToAction("Index", new { slug }));
                                       }
                                   });

                    return tcs.Task;
                }
            }

            return GetSettingsViewModel(slug).Then(model =>
            {
                model.KuduSettings.SiteSettings = settings;

                return (ActionResult)View("index", model);
            });
        }
开发者ID:BrianVallelunga,项目名称:kudu,代码行数:47,代码来源:SettingsController.cs

示例6: SetCustomProperties

        public async Task<ActionResult> SetCustomProperties(string slug, IDictionary<string, string> settings)
        {
            if (settings != null && settings.Count > 0)
            {
                // validate custom property name/values
                int i = 0;
                foreach (var setting in settings)
                {
                    if (string.IsNullOrWhiteSpace(setting.Key))
                    {
                        ModelState.AddModelError(String.Format("Settings[{0}].Key", i), "property name cannot be empty");
                    }

                    if (string.IsNullOrWhiteSpace(setting.Value))
                    {
                        ModelState.AddModelError(String.Format("Settings[{0}].Value", i), "property value cannot be empty");
                    }
                    i++;
                }

                if (ModelState.IsValid)
                {
                    await _service.SetKuduSettings(slug, settings.ToArray());
                    return RedirectToAction("Index", new { slug });
                }
            }

            var model = await GetSettingsViewModel(slug);

            model.KuduSettings.SiteSettings = settings;

            return (ActionResult)View("index", model);
        }
开发者ID:40a,项目名称:kudu,代码行数:33,代码来源:SettingsController.cs

示例7: PopulateSettings

        /// <summary>
        /// Sets object properties from the dictionary matching keys to property names or aliases.
        /// </summary>
        /// <param name="entityToPopulate">Object to populate from dictionary.</param>
        /// <param name="settings">Dictionary of settings.Settings that are populated get removed from the dictionary.</param>
        /// <returns>Dictionary of settings that were not matched.</returns>
        public static void PopulateSettings(object entityToPopulate, IDictionary<string, object> settings)
        {
            if (entityToPopulate == null)
            {
                throw new ArgumentNullException("entityToPopulate");
            }

            if (settings != null && settings.Count > 0)
            {
                // Setting property value from dictionary
                foreach (var setting in settings.ToArray())
                {
                    PropertyInfo property = entityToPopulate.GetType().GetProperties()
                        .FirstOrDefault(p => setting.Key.Equals(p.Name, StringComparison.OrdinalIgnoreCase) ||
                                             p.GetCustomAttributes<SettingsAliasAttribute>()
                                                .Any(a => setting.Key.Equals(a.Alias, StringComparison.OrdinalIgnoreCase)));

                    if (property != null)
                    {
                        try
                        {
                            if (property.PropertyType == typeof(bool) && (setting.Value == null || setting.Value.ToString().IsNullOrEmpty()))
                            {
                                property.SetValue(entityToPopulate, true);
                            }
                            else if (property.PropertyType.IsEnum)
                            {
                                property.SetValue(entityToPopulate, Enum.Parse(property.PropertyType, setting.Value.ToString(), true));
                            }
                            else if (property.PropertyType.IsArray && setting.Value.GetType() == typeof(JArray))
                            {
                                var elementType = property.PropertyType.GetElementType();
                                if (elementType == typeof(string))
                                {
                                    var stringArray = ((JArray) setting.Value).Children().
                                    Select(
                                        c => c.ToString())
                                    .ToArray();
  
                                    property.SetValue(entityToPopulate, stringArray);
                                }
                                else if (elementType == typeof (int))
                                {
                                    var intValues = ((JArray)setting.Value).Children().
                                         Select(c => (int)Convert.ChangeType(c, elementType, CultureInfo.InvariantCulture))
                                         .ToArray();
                                    property.SetValue(entityToPopulate, intValues);
                                }
                            }
                            else
                            {
                                property.SetValue(entityToPopulate,
                                    Convert.ChangeType(setting.Value, property.PropertyType, CultureInfo.InvariantCulture), null);
                            }

                            settings.Remove(setting.Key);
                        }
                        catch (Exception exception)
                        {
                            throw new ArgumentException(String.Format(CultureInfo.InvariantCulture, Resources.ParameterValueIsNotValid,
                                setting.Key, property.GetType().Name), exception);
                        }
                    }
                }
            }
        }
开发者ID:xingwu1,项目名称:autorest,代码行数:72,代码来源:Settings.cs

示例8: RunQuery

        private void RunQuery(string query, IDictionary<string,object> parameters = null)
        {
            edtResults.Text = query + "\r\n\r\nRunning...";
            tabControl.Enabled = false;

            Task.Run(async () =>
            {
                var bucket = ClusterHelper.GetBucket("beer-sample");

                var queryRequest = new QueryRequest(query);

                if (parameters != null)
                {
                    queryRequest.AddNamedParameter(parameters.ToArray());
                };

                var result = await
                    bucket.QueryAsync<dynamic>(queryRequest);
                if (!result.Success)
                {
                    if (result.Errors != null && result.Errors.Count > 0)
                    {
                        return result.Errors.First().Message;
                    }
                    else if (result.Exception != null)
                    {
                        return string.Format("{0}\r\n\r\n{1}\r\n{2}", query, result.Exception.Message,
                            result.Exception.StackTrace);
                    }
                    else
                    {
                        return "Unknown Error";
                    }
                }
                else if (result.Rows != null)
                {
                    var sb = new StringBuilder();
                    sb.AppendFormat("{0}\r\n\r\n{1} rows returned\r\n\r\n", query, result.Rows.Count);

                    foreach (var row in result.Rows)
                    {
                        sb.AppendLine(row.ToString());
                    }

                    return sb.ToString();
                }
                else
                {
                    return query + "\r\n\r\n0 row returned";
                }
            })
                .ContinueWith(task =>
                {
                    BeginInvoke(new Action(() =>
                    {
                        if (task.IsFaulted)
                        {
                            edtResults.Text = string.Format("{0}\r\n\r\n{1}\r\n{2}", query, task.Exception.Message,
                                task.Exception.StackTrace);
                        }
                        else
                        {
                            edtResults.Text = task.Result;
                        }

                        tabControl.Enabled = true;
                    }));
                });
        }
开发者ID:brantburnett,项目名称:N1QlInjection,代码行数:69,代码来源:MainForm.cs

示例9: RemoveZeroes

 private void RemoveZeroes(IDictionary<string, object> dictionary) {
     foreach (var p in dictionary.ToArray()) {
         var val = p.Value;
         if (!val.ToBool()) {
             dictionary.Remove(p.Key);
             continue;
         }
         if (val is Array) {
             if (((Array) val).Length == 0) {
                 dictionary.Remove(p.Key);
             }
             continue;
         }
         if (val is IDictionary<string, object>) {
             RemoveZeroes((IDictionary<string,object>)val);
         }
     }
 }
开发者ID:Qorpent,项目名称:qorpent.sys,代码行数:18,代码来源:JsonGeneratorTaskBase.cs

示例10: Invoke

 /// <summary>
 /// Invoke this function, using named arguments provided as key-value pairs
 /// </summary>
 /// <param name="args">the representation of named arguments, as a dictionary</param>
 /// <returns>The result of the evaluation</returns>
 public override SymbolicExpression Invoke(IDictionary<string, SymbolicExpression> args)
 {
     var a = args.ToArray();
     return InvokeViaPairlist(Array.ConvertAll(a, x => x.Key), Array.ConvertAll(a, x => x.Value));
 }
开发者ID:mgtstrategies,项目名称:rdotnet,代码行数:10,代码来源:Closure.cs

示例11: SetOptions

        public virtual void SetOptions( IDictionary<string, object> options, IToken optionsStartToken )
        {
            if ( options == null )
            {
                this.Options = null;
                return;
            }

            foreach ( var option in options.ToArray() )
            {
                string optionName = option.Key;
                object optionValue = option.Value;
                string stored = SetOption( optionName, optionValue, optionsStartToken );
                if ( stored == null )
                    options.Remove( optionName );
            }
        }
开发者ID:mahanteshck,项目名称:antlrcs,代码行数:17,代码来源:Rule.cs


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