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


C# ITaskItem.FirstOrDefault方法代码示例

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


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

示例1: GenerateDependencies

        // Generate the combines dependencies from the projectjson jObject and from AdditionalDependencies
        private JObject GenerateDependencies(JObject projectJsonRoot, ITaskItem[] externalPackageVersions, string framework = null)
        {
            var originalDependenciesList = new List<JToken>();
            var returnDependenciesList = new List<JToken>();
            var frameworkDependencies = GetFrameworkDependenciesSection(projectJsonRoot, framework);
            if (frameworkDependencies != null)
            {
                originalDependenciesList = frameworkDependencies.Children().ToList();

                // Update versions in dependencies
                foreach (JProperty property in originalDependenciesList.Select(od => od))
                {
                    // Validate that the package matches the identity regex for packages we want to update.
                    Match updateDependency = _identityRegex.Match(property.Name);

                    // if the package is in the external packages list then we'll
                    // need to replace the version with the version from the list
                    string externalVersion = null;
                    if (externalPackageVersions != null)
                        externalVersion = externalPackageVersions.FirstOrDefault(epv => epv.ItemSpec.Equals(property.Name, StringComparison.OrdinalIgnoreCase))?.GetMetadata("Version");

                    if (updateDependency.Success || externalVersion != null)
                    {
                        NuGetVersion nuGetVersion;
                        if (externalVersion == null)
                        {
                            if (NuGetVersion.TryParse(property.Value.ToString(), out nuGetVersion))
                            {
                                Match m = _versionStructureRegex.Match(nuGetVersion.ToString());

                                if (m.Success)
                                {
                                    NuGetVersion dependencyVersion = nuGetVersion;
                                    nuGetVersion = NuGetVersion.Parse(string.Join(".", dependencyVersion.Major, dependencyVersion.Minor, dependencyVersion.Patch) + "-" + PackageBuildNumberOverride);
                                }
                            }
                        }
                        else
                        {
                            nuGetVersion = NuGetVersion.Parse(externalVersion);
                        }

                        // Only add the original dependency if it wasn't passed as an AdditionalDependency, ie. AdditionalDependencies may override dependencies in project.json
                        if (AdditionalDependencies.FirstOrDefault(d => d.GetMetadata("Name").Equals(property.Name, StringComparison.OrdinalIgnoreCase)) == null)
                        {
                            JProperty addProperty;
                            if (nuGetVersion != null)
                            {
                                addProperty = new JProperty(property.Name, nuGetVersion.ToString());
                            }
                            else
                            {
                                addProperty = property;
                            }
                            returnDependenciesList.Add(addProperty);
                        }
                    }
                    else
                    {
                        returnDependenciesList.Add(property);
                    }
                }
            }

            foreach (var dependency in AdditionalDependencies)
            {
                string name = dependency.GetMetadata("Name");
                // Don't add a new dependency if one already exists.
                if (returnDependenciesList.FirstOrDefault(rd => ((JProperty)rd).Name.Equals(name)) == null)
                {
                    string version = null;
                    if (externalPackageVersions != null)
                        version = externalPackageVersions.FirstOrDefault(epv => epv.ItemSpec.Equals(name, StringComparison.OrdinalIgnoreCase))?.GetMetadata("Version");

                    if (version == null)
                    {
                        NuGetVersion dependencyVersion = NuGetVersion.Parse(dependency.GetMetadata("Version"));
                        version = string.Join(".", dependencyVersion.Major, dependencyVersion.Minor, dependencyVersion.Patch);
                        if (!string.IsNullOrWhiteSpace(PackageBuildNumberOverride))
                        {
                            version += "-" + PackageBuildNumberOverride;
                        }
                    }
                    JProperty property = new JProperty(name, version);
                    returnDependenciesList.Add(property);
                }
                else
                {
                    Log.LogMessage("Ignoring AdditionalDependency '{0}', dependency is already present in {1}", name, ProjectJson);
                }
            }
            
            return new JObject(returnDependenciesList.ToArray());
        }
开发者ID:schaabs,项目名称:buildtools,代码行数:95,代码来源:AddDependenciesToProjectJson.cs


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