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


C# IList.ElementAtOrDefault方法代码示例

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


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

示例1: Run

        public int Run(IList<string> args)
        {
            string command = args.FirstOrDefault() ?? "";
            _stdout.WriteLine("executing subtree " + command);

            if (string.IsNullOrEmpty(Prefix))
            {
                _stdout.WriteLine("Prefix must be specified, use -p or -prefix");
                return GitTfsExitCodes.InvalidArguments;
            }

            switch (command.ToLower())
            {
                case "add":
                    return DoAdd(args.ElementAtOrDefault(1) ?? "", args.ElementAtOrDefault(2) ?? "");

                case "pull":
                    return DoPull(args.ElementAtOrDefault(1));

                case "split":
                    return DoSplit();

                default:
                    _stdout.WriteLine("Expected one of [add, pull, split]");
                    return GitTfsExitCodes.InvalidArguments;
            }
        }
开发者ID:Galilyou,项目名称:git-tfs,代码行数:27,代码来源:Subtree.cs

示例2: Copy

        private static void Copy(
            IList source,
            IList target,
            MemberSettings settings,
            ReferencePairCollection referencePairs)
        {
            if ((source.IsFixedSize || target.IsFixedSize) && source.Count != target.Count)
            {
                throw State.Copy.Throw.CannotCopyFixesSizeCollections(source, target, settings);
            }

            var copyValues = State.Copy.IsCopyValue(
                        source.GetType().GetItemType(),
                        settings);
            for (var i = 0; i < source.Count; i++)
            {
                if (copyValues)
                {
                    target.SetElementAt(i, source[i]);
                    continue;
                }

                var sv = source[i];
                var tv = target.ElementAtOrDefault(i);
                bool created;
                bool needsSync;
                var clone = State.Copy.CloneWithoutSync(sv, tv, settings, out created, out needsSync);
                if (created)
                {
                    target.SetElementAt(i, clone);
                }

                if (needsSync)
                {
                    State.Copy.Sync(sv, clone, settings, referencePairs);
                }
            }

            target.TrimLengthTo(source);
        }
开发者ID:JohanLarsson,项目名称:Gu.State,代码行数:40,代码来源:ListCopyer.cs

示例3: FindMethodInfo

 private MethodInfo FindMethodInfo(IList<Token> arg)
 {
     var foundClassName = Type.ControllerName().EqualsIC(arg.ElementAtOrDefault(0).Value);
     if (foundClassName)
     {
         var methodName = arg.ElementAtOrDefault(1).Value;
         var methodInfo = FindMethodAmongLexedTokens.FindMethod(Type.GetControllerActionMethods(), methodName, arg);
         return methodInfo;
     }
     return null;
 }
开发者ID:Lundalogik,项目名称:isop,代码行数:11,代码来源:ControllerRecognizer.cs

示例4: AppendDocumentsToPrimaryDocument

        public byte[] AppendDocumentsToPrimaryDocument(byte[] primaryDocument, IList<byte[]> documentstoAppend)
        {
            if (documentstoAppend == null)
            {
                throw new ArgumentNullException("documentstoAppend");
            }

            if (primaryDocument == null)
            {
                throw new ArgumentNullException("primaryDocument");
            }

            byte[] output = null;

            using (var finalDocumentStream = new MemoryStream())
            {
                finalDocumentStream.Write(primaryDocument, 0, primaryDocument.Length);

                using (var finalDocument = WordprocessingDocument.Open(finalDocumentStream, true))
                {
                    SectionProperties finalDocSectionProperties = null;
                    UnprotectDocument(finalDocument);

                    var tempSectionProperties =
                        finalDocument.MainDocumentPart.Document.Descendants<SectionProperties>().LastOrDefault();

                    if (tempSectionProperties != null)
                    {
                        finalDocSectionProperties = tempSectionProperties.CloneNode(true) as SectionProperties;
                    }

                    this.RemoveContentControlsAndKeepContents(finalDocument.MainDocumentPart.Document);

                    foreach (byte[] documentToAppend in documentstoAppend)
                    {
                        var subReportPart =
                            finalDocument.MainDocumentPart.AddAlternativeFormatImportPart(
                                AlternativeFormatImportPartType.WordprocessingML);
                        SectionProperties secProperties = null;

                        using (var docToAppendStream = new MemoryStream())
                        {
                            docToAppendStream.Write(documentToAppend, 0, documentToAppend.Length);

                            using (var docToAppend = WordprocessingDocument.Open(docToAppendStream, true))
                            {
                                UnprotectDocument(docToAppend);

                                tempSectionProperties =
                                    docToAppend.MainDocumentPart.Document.Descendants<SectionProperties>().LastOrDefault();

                                if (tempSectionProperties != null)
                                {
                                    secProperties = tempSectionProperties.CloneNode(true) as SectionProperties;
                                }

                                this.RemoveContentControlsAndKeepContents(docToAppend.MainDocumentPart.Document);
                                docToAppend.MainDocumentPart.Document.Save();
                            }

                            docToAppendStream.Position = 0;
                            subReportPart.FeedData(docToAppendStream);
                        }

                        if (documentstoAppend.ElementAtOrDefault(0).Equals(documentToAppend))
                        {
                            AssignSectionProperties(finalDocument.MainDocumentPart.Document, finalDocSectionProperties);
                        }

                        var altChunk = new AltChunk();
                        altChunk.Id = finalDocument.MainDocumentPart.GetIdOfPart(subReportPart);
                        finalDocument.MainDocumentPart.Document.AppendChild(altChunk);

                        if (!documentstoAppend.ElementAtOrDefault(documentstoAppend.Count - 1).Equals(documentToAppend))
                        {
                            AssignSectionProperties(finalDocument.MainDocumentPart.Document, secProperties);
                        }

                        finalDocument.MainDocumentPart.Document.Save();
                    }

                    finalDocument.MainDocumentPart.Document.Save();
                }

                finalDocumentStream.Position = 0;
                output = new byte[finalDocumentStream.Length];
                finalDocumentStream.Read(output, 0, output.Length);
            }

            return output;
        }
开发者ID:NikolayKash,项目名称:BuildManager,代码行数:91,代码来源:OpenXmlHelper.cs

示例5: GetScore

        public int? GetScore(IList<BowlingFrame> frames)
        {
            var nextFrame = frames.ElementAtOrDefault(frames.IndexOf(this) + 1);

            // Strike
            if (IsStrike) {

                if (nextFrame != null) {
                    // Is next ball a strike? If so, we'll need the next frame
                    if (nextFrame.IsStrike) {
                        var thirdFrame = frames.ElementAtOrDefault(frames.IndexOf(nextFrame) + 1);

                        // Get first throw of third frame, if it's a strike it's just +10
                        if (thirdFrame != null && thirdFrame.Ball1 != null) {
                            return 20 + thirdFrame.Ball1.Value;
                        } else if (thirdFrame == null && nextFrame.IsLast) {
                            // 10th frame
                            if (nextFrame.Ball1 != null && nextFrame.Ball2 != null) {
                                return 10 + nextFrame.Ball1.Value + nextFrame.Ball2.Value;
                            }
                        }
                    } else {
                        if (nextFrame.Ball1 == null || nextFrame.Ball2 == null) {
                            return null;
                        } else {
                            return 10 + nextFrame.Ball1.Value + nextFrame.Ball2.Value;
                        }
                    }
                } else {
                    // Last frame and a first or second ball is strike
                    if (Ball2 == Constants.TotalPins && Ball3 != null) {
                        return Ball1 + Ball2 + Ball3;
                    } else if (Ball1 == Constants.TotalPins && Ball2 != null && Ball3 != null) {
                        return Ball1 + Ball2 + Ball3;
                    } else if (IsSpare) {
                        return Ball1 + Ball2 + Ball3;
                    }
                }

                // cannot calculate just yet
                return null;
            }

            // Spare
            if (IsSpare) {

                // Get next ball
                if (nextFrame != null && nextFrame.Ball1 != null) {
                    return 10 + nextFrame.Ball1.Value;
                } else if (nextFrame == null && Ball3 != null) {
                    // last frame
                    return 10 + Ball3.Value;
                }

                // cannot calculate just yet
                return null;
            }

            // Open frame
            if (Ball2 != null && Ball1 != null) {
                return Ball1.Value + Ball2.Value;
            } else {
                return null;
            }
        }
开发者ID:kamranayub,项目名称:wp-bowling,代码行数:65,代码来源:BowlingFrame.cs

示例6: ValidateEntity

 private void ValidateEntity(object o, object id, PersistenceOperationEnum persistenceOperation, IList<string> properties, IList<IType> types, IList<object> currentState, IList<object> previousState)
 {
     if (ReferenceEquals(_session, null)) return;
     if (!ReferenceEquals(_session.Transaction, null) && _session.Transaction.WasRolledBack) return;
     var factoryName = _session.GetSessionImplementation().Factory.Settings.SessionFactoryName;
     var epc = new EntityPersistenceContext {FactoryName = factoryName, Id = id};
     if (properties != null)
     {
         for (var i = 0; i < properties.Count; i++)
         {
             if (currentState != null) epc.CurrentState.Add(properties[i], currentState.ElementAtOrDefault(i));
             if (types != null) epc.Types.Add(properties[i], types.ElementAtOrDefault(i));
         }    
     }
     switch (persistenceOperation)
     {
         case PersistenceOperationEnum.Adding:
             epc.IsBeingAdded = true;
             break;
         case PersistenceOperationEnum.Updating:
             epc.IsBeingModified = true;
             if (properties == null || previousState == null) break;
             for (var i = 0; i < properties.Count; i++ )
             {
                 epc.PreviousState.Add(properties[i], previousState.ElementAtOrDefault(i));    
             }
             break;
         case PersistenceOperationEnum.Removing:
             epc.IsBeingRemoved = true;
             break;
         default:
             throw new ArgumentOutOfRangeException(persistenceOperation.ToString());
     }
     var validationResults = EntityValidator.DoMemberValidation(o, epc).ToList();
     if (validationResults.Count() == 0)
     {
         if (_validationResults.ContainsKey(o))
         {
             //remove the validation errors from a previous flush
             _validationResults.Remove(o);
         }
         return;
     }
     if (!_validationResults.ContainsKey(o))
     {
         //add the validation results for the entity
         _validationResults.Add(o, validationResults);
     }
     else
     {
         //replace the validation results for the entity
         _validationResults[o] = validationResults;
     }
 }
开发者ID:razvan-panda,项目名称:NHibernate.Extensions,代码行数:54,代码来源:ValidationInterceptor.cs

示例7: ApplyValues

		public void ApplyValues(string groupName, IList<string> values)
		{
			switch (groupName)
			{
				case "ribbon_group_1_name":
					RibbonGroupDigitalLogoTitle = values.ElementAtOrDefault(0);
					break;
				case "top_level_subtab_names":
					SectionsHomeTitle = values.ElementAtOrDefault(0);
					SectionsListTitle = values.ElementAtOrDefault(1);
					SectionsProductTitle = values.ElementAtOrDefault(2);
					SectionsSummaryTitle = values.ElementAtOrDefault(3);
					SectionsProductPackageTitle = values.ElementAtOrDefault(4);
					SectionsStandalonePackageTitle = values.ElementAtOrDefault(5);
					break;
				case "tab_2_column_header_names":
					ListColumnsGroupTitle = values.ElementAtOrDefault(0);
					ListColumnsProductTitle = values.ElementAtOrDefault(1);
					ListColumnsPricingTitle = values.ElementAtOrDefault(2);
					ListColumnsOptionsTitle = values.ElementAtOrDefault(3);
					break;
				case "tab_2_left_panel_button_names":
					ListSettingsDimensionTitle = values.ElementAtOrDefault(0);
					ListSettingsLocationTitle = values.ElementAtOrDefault(1);
					ListSettingsStrategyTitle = values.ElementAtOrDefault(2);
					ListSettingsTargetingTitle = values.ElementAtOrDefault(3);
					ListSettingsRichMediaTitle = values.ElementAtOrDefault(4);
					break;
				case "tab_2_new_line_placeholder_names":
					ListEditorsGroupTitle = values.ElementAtOrDefault(0);
					ListEditorsProductTitle = values.ElementAtOrDefault(1);
					ListEditorsLocationTitle = values.ElementAtOrDefault(2);
					break;
				case "tab_2_new_line_options_label_names":
					ListEditorsTargetingTitle = values.ElementAtOrDefault(0);
					ListEditorsRichMediaTitle = values.ElementAtOrDefault(1);
					break;
				case "tab_2_add_product_hover_tip":
					RibbonButtonDigitalAddTitle = values.ElementAtOrDefault(0);
					RibbonButtonDigitalAddTooltip = values.ElementAtOrDefault(1);
					break;
				case "tab_2_delete_product_hover_tip":
					RibbonButtonDigitalDeleteTitle = values.ElementAtOrDefault(0);
					RibbonButtonDigitalDeleteTooltip = values.ElementAtOrDefault(1);
					break;
				case "tab_2_clone_product_hover_tip":
					RibbonButtonDigitalCloneTitle = values.ElementAtOrDefault(0);
					RibbonButtonDigitalCloneTooltip = values.ElementAtOrDefault(1);
					break;
				case "tab_2_warning_popup":
					ListPopupGroupText = values.ElementAtOrDefault(0);
					break;
				case "tab_3_section_titles":
					ProductEditorsSitesTitle = values.ElementAtOrDefault(0);
					ProductEditorsNameTitle = values.ElementAtOrDefault(1);
					ProductEditorsDescriptionTitle = values.ElementAtOrDefault(2);
					ProductEditorsPricingTitle = values.ElementAtOrDefault(3);
					ProductEditorsCommentsTitle = values.ElementAtOrDefault(4);
					break;
				case "tab_3_section_icons":
					var imageRootFolder = Path.Combine(
						Path.GetDirectoryName(typeof(DigitalControlsConfiguration).Assembly.Location),
						"Data",
						"!Main_Dashboard",
						"Online Source",
						"Icon Images");
					if (!Directory.Exists(imageRootFolder)) break;
					ProductEditorsSitesLogo = !String.IsNullOrEmpty(values.ElementAtOrDefault(0)) ? Image.FromFile(Path.Combine(imageRootFolder, values[0])) : null;
					ProductEditorsNameLogo = !String.IsNullOrEmpty(values.ElementAtOrDefault(1)) ? Image.FromFile(Path.Combine(imageRootFolder, values[1])) : null;
					ProductEditorsDescriptionLogo = !String.IsNullOrEmpty(values.ElementAtOrDefault(2)) ? Image.FromFile(Path.Combine(imageRootFolder, values[2])) : null;
					ProductEditorsPricingLogo = !String.IsNullOrEmpty(values.ElementAtOrDefault(3)) ? Image.FromFile(Path.Combine(imageRootFolder, values[3])) : null;
					ProductEditorsCommentsLogo = !String.IsNullOrEmpty(values.ElementAtOrDefault(4)) ? Image.FromFile(Path.Combine(imageRootFolder, values[4])) : null;
					break;
				case "tab_5_column_header_names":
					ProductPackageColumnsCategoryTitle = values.ElementAtOrDefault(0);
					ProductPackageColumnsSubCategoryTitle = values.ElementAtOrDefault(1);
					ProductPackageColumnsProductTitle = values.ElementAtOrDefault(2);
					ProductPackageColumnsInfoTitle = values.ElementAtOrDefault(3);
					ProductPackageColumnsLocationTitle = values.ElementAtOrDefault(4);
					ProductPackageColumnsInvestmentTitle = values.ElementAtOrDefault(5);
					ProductPackageColumnsImpressionsTitle = values.ElementAtOrDefault(6);
					ProductPackageColumnsCPMTitle = values.ElementAtOrDefault(7);
					ProductPackageColumnsRateTitle = values.ElementAtOrDefault(8);
					break;
				case "tab_5_left_panel_button_names":
					ProductPackageSettingsCategoryTitle = values.ElementAtOrDefault(0);
					ProductPackageSettingsSubCategoryTitle = values.ElementAtOrDefault(1);
					ProductPackageSettingsProductTitle = values.ElementAtOrDefault(2);
					ProductPackageSettingsInfoTitle = values.ElementAtOrDefault(3);
					ProductPackageSettingsLocationTitle = values.ElementAtOrDefault(4);
					ProductPackageSettingsInvestmentTitle = values.ElementAtOrDefault(5);
					ProductPackageSettingsImpressionsTitle = values.ElementAtOrDefault(6);
					ProductPackageSettingsCPMTitle = values.ElementAtOrDefault(7);
					ProductPackageSettingsRateTitle = values.ElementAtOrDefault(8);
					ProductPackageSettingsScreenshotTitle = values.ElementAtOrDefault(9);
					ProductPackageSettingsFormulaTitle = values.ElementAtOrDefault(10);
					break;
				case "tab_6_column_header_names":
					StandalonePackageColumnsCategoryTitle = values.ElementAtOrDefault(0);
					StandalonePackageColumnsSubCategoryTitle = values.ElementAtOrDefault(1);
//.........这里部分代码省略.........
开发者ID:w01f,项目名称:VolgaTeam.Dashboard,代码行数:101,代码来源:DigitalControlsConfiguration.cs

示例8: Server

        private async static void Server(IList<string> list, AHistory c)
        {
            string pwd = null;
            int port = 0;

            if (list.ElementAtOrDefault(1) == null)
                throw new ErrorBIRC(MainPage.GetErrorString("InvalidServerCmd"));
            if (list.ElementAtOrDefault(2) != null)
            {
                if (int.TryParse(list[2], out port) == false)
                    port = IrcClient.DefaultPort;
            }
            else
                port = IrcClient.DefaultPort;
            if (list.ElementAtOrDefault(3) != null)
                pwd = await Encryption.Protect(list[3]);
            Connection newc = new Connection()
            {
                AutoConnect = true,
                Name = list[1],
                Port = port,
                Password = pwd
            };
            AHistory cur = ConnectionUtils.Add(newc);
            ((BIRCViewModel)MainPage.currentDataContext).ServerSelection = cur;
            if (!cur.Command.IsConnected())
                cur.Command.Connect();
        }
开发者ID:charla-n,项目名称:BIRC,代码行数:28,代码来源:PromptCommandParser.cs


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