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


C# ReadOnlyCollection.Where方法代码示例

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


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

示例1: Where_IReadOnlyCollection_ExecutionIsDeferred

        public void Where_IReadOnlyCollection_ExecutionIsDeferred()
        {
            bool funcCalled = false;
            IReadOnlyCollection<Func<bool>> source = new ReadOnlyCollection<Func<bool>>(new List<Func<bool>>() { () => { funcCalled = true; return true; } });

            IEnumerable<Func<bool>> query = source.Where(value => value());
            Assert.False(funcCalled);

            query = source.Where((value, index) => value());
            Assert.False(funcCalled);
        }
开发者ID:chcosta,项目名称:corefx,代码行数:11,代码来源:WhereTests.cs

示例2: PatternMatchRuleProcessor

        private PatternMatchRuleProcessor(ReadOnlyCollection<PatternMatchRule> rules)
        {
            Debug.Assert(rules.Count() != 0, "At least one PatternMatchRule is required");
            Debug.Assert(rules.Where(r => r == null).Count() == 0, "Individual PatternMatchRules must not be null");

            ruleSet = rules;
        }
开发者ID:christiandpena,项目名称:entityframework,代码行数:7,代码来源:PatternMatchRuleProcessor.cs

示例3: Build

        public static void Build(ReadOnlyCollection<Type> targets, ProxyContext context)
        {
            targets.CheckBuildPreconditions();
            context.CheckBuildPreconditions();

            foreach (var target in targets)
            {
                target.CheckBuildPreconditions();
            }

            var nonProxiedTypes = new List<Type>(
                targets.Where(target =>
                {
                    return !BuiltProxies.Mappings.ContainsKey(target);
                })
            );

            if (nonProxiedTypes.Count > 0)
            {
                var items = ProxyBuilder.Generate(targets[0], context);

                foreach (var target in targets)
                {
                    ProxyBuilder.Build(target, items);
                }

                ProxyBuilder.Save(items.Assembly, context);
            }
        }
开发者ID:JasonBock,项目名称:DynamicProxies,代码行数:29,代码来源:ProxyBuilder.cs

示例4: Compare

        /// <summary>
        /// Compares the specified image list to itself.
        /// </summary>
        /// <param name="imageList">The image list.</param>
        /// <returns>
        /// A list of images and the potential matches.
        /// </returns>
        public Dictionary<FileInfo, ReadOnlyCollection<FileInfo>> Compare(ReadOnlyCollection<FileInfo> imageList)
        {
            Dictionary<FileInfo, ReadOnlyCollection<FileInfo>> results = new Dictionary<FileInfo, ReadOnlyCollection<FileInfo>>();

            var comparisonList = imageList.Where(f => f.Extension.ToLower() == ".jpg").GroupBy(f => f.Length).Where(g => g.Count() > 1);
            foreach (var grouping in comparisonList)
            {
                var images = grouping.Select(c => new ComparisonTracker { HasBeenCompared = false, Source = c }).ToArray();
                for (int index = 0; index < images.Count(); index++)
                {
                    if (images[index].HasBeenCompared) continue;
                    images[index].HasBeenCompared = true;
                    List<FileInfo> matches = doByteComparison(images[index].Source, images.Where(c => c.HasBeenCompared == false));
                    if (matches.Count() > 0)
                    {
                        results.Add(images[index].Source, new ReadOnlyCollection<FileInfo>(matches));
                    }
                }
            }

            return results;
        }
开发者ID:basilard99,项目名称:ImageComparer,代码行数:29,代码来源:ImageComparison.cs

示例5: Where_IReadOnlyCollection_ReturnsExpectedValues_True

        public void Where_IReadOnlyCollection_ReturnsExpectedValues_True()
        {
            IReadOnlyCollection<int> source = new ReadOnlyCollection<int>(new List<int> { 1, 2, 3, 4, 5 });
            Func<int, bool> truePredicate = (value) => true;

            IEnumerable<int> result = source.Where(truePredicate);

            Assert.Equal(source.Count, result.Count());
            for (int i = 0; i < source.Count; i++)
            {
                Assert.Equal(source.ElementAt(i), result.ElementAt(i));
            }
        }
开发者ID:chcosta,项目名称:corefx,代码行数:13,代码来源:WhereTests.cs

示例6: WriteOrderBy

        protected void WriteOrderBy(ReadOnlyCollection<OrderByExpression> orderBys,
            ReadOnlyCollection<ColumnDeclaration> outputColumns)
        {
            if (orderBys != null && orderBys.Count > 0)
            {
                var columns =
                    outputColumns.Where(p => (PigExpressionType) p.Expression.NodeType == PigExpressionType.Column).
                        ToList();
                var aggs =
                    outputColumns.Where(p => (PigExpressionType) p.Expression.NodeType == PigExpressionType.Aggregate).
                        ToList();
                var columnMaps = new Dictionary<String, String>();
                foreach (ColumnDeclaration column in columns)
                {
                    columnMaps.Add(column.Name, ((ColumnExpression) column.Expression).Name);
                }
                Write(String.Format("{0} = order {1} by (", GetNextAliasName(), GetLastAliasName(_alias)));

                for (Int32 i = 0, n = orderBys.Count; i < n; i++)
                {
                    OrderByExpression orderBy = orderBys[i];
                    if (i > 0)
                    {
                        Write(", ");
                    }

                    var colExp = orderBy.Expression as ColumnExpression;
                    if (colExp != null)
                    {
                        WriteColumnName(columnMaps.FirstOrDefault(x => x.Value == colExp.Name).Key);
                    }
                    var aggExp = orderBy.Expression as AggregateExpression;
                    if (aggExp != null)
                    {
                        if (aggs.Count == 1)
                        {
                            WriteColumnName(aggs[0].Name);
                        }
                    }
                    var parseExp = orderBy.Expression as MethodCallExpression;
                    if (parseExp != null)
                    {
                        foreach (ColumnDeclaration col in outputColumns)
                        {
                            var mce = col.Expression as MethodCallExpression;
                            if (mce != null && parseExp.Method == mce.Method &&
                                parseExp.Method.DeclaringType == mce.Method.DeclaringType)
                            {
                                WriteColumnName(col.Name);
                            }
                        }
                    }

                    var memberExp = orderBy.Expression as MemberExpression;
                    if (memberExp != null)
                    {
                        WriteColumnName(memberExp.Member.Name);
                    }

                    if (orderBy.Expression.NodeType == ExpressionType.Convert)
                    {
                        var dynamicOrderExp = (UnaryExpression)orderBy.Expression;
                        var columnExpression = dynamicOrderExp.Operand as ColumnExpression;
                        if (columnExpression != null)
                        {
                            WriteColumnName(columnMaps.FirstOrDefault(x => x.Value == columnExpression.Name).Key);
                        }
                        else
                        {
                            var dynamicProperty = dynamicOrderExp.Operand as MemberExpression;
                            if (dynamicProperty != null)
                            {
                                WriteColumnName(dynamicProperty.Member.Name);
                            }
                            else
                            {
                                var dynamicAgg = dynamicOrderExp.Operand as AggregateExpression;
                                if (dynamicAgg != null)
                                {
                                    WriteColumnName(aggs[0].Name);
                                }
                            }
                        }
                    }

                    WriteOrderByDirection(orderBy.Direction);
                }
                Write("); ");
                AddAlias();
            }
        }
开发者ID:sprucemedia,项目名称:oinq,代码行数:91,代码来源:PigFormatter.cs

示例7: Add_Citation_HTML_Rows

        private void Add_Citation_HTML_Rows(string Row_Name, ReadOnlyCollection<string> Values, string indent, StringBuilder results)
        {
            // Only add if there is a value
            if (Values.Count <= 0) return;

            results.AppendLine(indent + "    <tr>");
            results.AppendLine(indent + "      <td width=\"15\"> </td>");
            results.Append(indent + "      <td width=\"" + width + "\" valign=\"top\"><b>");

            // Add with proper language
            switch (CurrentMode.Language)
            {
                case Web_Language_Enum.French:
                    results.Append(Translator.Get_French(Row_Name));
                    break;

                case Web_Language_Enum.Spanish:
                    results.Append(Translator.Get_Spanish(Row_Name));
                    break;

                default:
                    results.Append(Row_Name);
                    break;
            }

            results.AppendLine(": </b></td>");
            results.Append( indent + "      <td>");
            bool first = true;
            foreach (string thisValue in Values.Where(thisValue => thisValue.Length > 0))
            {
                if (first)
                {
                    results.Append(thisValue);
                    first = false;
                }
                else
                {
                    results.Append("<br />" + thisValue);
                }
            }
            results.AppendLine("</td>");
            results.AppendLine( indent + "    </tr>");
        }
开发者ID:randomyed,项目名称:SobekCM-Web-Application,代码行数:43,代码来源:Citation_ItemViewer.cs

示例8: RenderingOptionInfo

 public RenderingOptionInfo(string optionName, ReadOnlyCollection<OptionInfo> optionInfos)
 {
     Name = optionName;
     Info = optionInfos.Where(oi => oi.Name == Name).First();
     Value = OptionApi.GetString(optionName);
 }
开发者ID:killbug2004,项目名称:WSProf,代码行数:6,代码来源:RenderingOptionInfo.cs

示例9: WhereSelectSelect_IReadOnlyCollection_ReturnsExpectedValues

        public void WhereSelectSelect_IReadOnlyCollection_ReturnsExpectedValues()
        {
            IReadOnlyCollection<int> source = new ReadOnlyCollection<int>(new List<int> { 1, 2, 3, 4, 5 });
            Func<int, bool> evenPredicate = (value) => value % 2 == 0;
            Func<int, int> addSelector = (value) => value + 1;

            IEnumerable<int> result = source.Where(evenPredicate).Select(i => i).Select(addSelector);

            Assert.Equal(2, result.Count());
            Assert.Equal(3, result.ElementAt(0));
            Assert.Equal(5, result.ElementAt(1));
        }
开发者ID:chcosta,项目名称:corefx,代码行数:12,代码来源:WhereTests.cs

示例10: Where_IReadOnlyCollection_CurrentIsDefaultOfTAfterEnumeration

        public void Where_IReadOnlyCollection_CurrentIsDefaultOfTAfterEnumeration()
        {
            IReadOnlyCollection<int> source = new ReadOnlyCollection<int>(new List<int>() { 1 });
            Func<int, bool> truePredicate = (value) => true;

            var enumerator = source.Where(truePredicate).GetEnumerator();
            while (enumerator.MoveNext()) ;

            Assert.Equal(default(int), enumerator.Current);
        }
开发者ID:chcosta,项目名称:corefx,代码行数:10,代码来源:WhereTests.cs

示例11: ValidateType

 private void ValidateType(ReadOnlyCollection<ResourceProperty> declaredProperties)
 {
     if (this.BaseType != null)
     {
         using (IEnumerator<ResourceProperty> enumerator = this.BaseType.Properties.GetEnumerator())
         {
             Func<ResourceProperty, bool> predicate = null;
             ResourceProperty rp;
             while (enumerator.MoveNext())
             {
                 rp = enumerator.Current;
                 if (predicate == null)
                 {
                     predicate = p => p.Name == rp.Name;
                 }
                 if (declaredProperties.Where<ResourceProperty>(predicate).FirstOrDefault<ResourceProperty>() != null)
                 {
                     throw new InvalidOperationException(System.Data.Services.Strings.ResourceType_PropertyWithSameNameAlreadyExists(rp.Name, this.FullName));
                 }
             }
             goto Label_00C0;
         }
     }
     if ((this.ResourceTypeKind == System.Data.Services.Providers.ResourceTypeKind.EntityType) && ((from p in declaredProperties
         where p.IsOfKind(ResourcePropertyKind.Key)
         select p).FirstOrDefault<ResourceProperty>() == null))
     {
         throw new InvalidOperationException(System.Data.Services.Strings.ResourceType_MissingKeyPropertiesForEntity(this.FullName));
     }
 Label_00C0:
     foreach (ResourceProperty property in declaredProperties)
     {
         property.SetReadOnly();
         if (property.CanReflectOnInstanceTypeProperty)
         {
             this.GetPropertyInfoDecaredOnThisType(property);
         }
     }
     try
     {
         if (!this.EpmInfoInitialized)
         {
             this.BuildDynamicEpmInfo(this, declaredProperties);
             this.MarkEpmInfoInitialized(declaredProperties);
         }
     }
     catch
     {
         if (this.HasEntityPropertyMappings && !this.EpmInfoInitialized)
         {
             this.epmInfo.Reset();
         }
         throw;
     }
 }
开发者ID:nickchal,项目名称:pash,代码行数:55,代码来源:ResourceType.cs

示例12: WindowsZones

 private WindowsZones(string version, string tzdbVersion, string windowsVersion, ReadOnlyCollection<MapZone> mapZones)
 {
     this.Version = version;
     this.TzdbVersion = tzdbVersion;
     this.WindowsVersion = windowsVersion;
     this.MapZones = mapZones;
     this.PrimaryMapping = new NodaReadOnlyDictionary<string, string>(
         mapZones.Where(z => z.Territory == MapZone.PrimaryTerritory)
                 .ToDictionary(z => z.WindowsId, z => z.TzdbIds.Single()));
 }
开发者ID:nicklbailey,项目名称:nodatime,代码行数:10,代码来源:WindowsZones.cs

示例13: ValidateType

        /// <summary>
        /// This method is called only when the Properties property is called and the type is already set to read-only.
        /// This method validates all the properties w.r.t to the base type and calls SetReadOnly on all the properties.
        /// </summary>
        /// <param name="declaredProperties">The declaredProperties of the current type.</param>
        private void ValidateType(ReadOnlyCollection<ResourceProperty> declaredProperties)
        {
            Debug.Assert(this.isLoadPropertiesMethodCalled && this.IsReadOnly, "This method must be invoked only if LoadPropertiesDeclaredOnThisType has been called and the type is set to ReadOnly");

            if (this.BaseType != null)
            {
                // make sure that there are no properties with the same name. Properties with duplicate name within the type
                // is already checked in AddProperty method
                foreach (ResourceProperty rp in this.BaseType.Properties)
                {
                    if (declaredProperties.Where(p => p.Name == rp.Name).FirstOrDefault() != null)
                    {
                        throw new InvalidOperationException(Strings.ResourceType_PropertyWithSameNameAlreadyExists(rp.Name, this.FullName));
                    }
                }
            }
            else if (this.ResourceTypeKind == ResourceTypeKind.EntityType)
            {
                if (declaredProperties.Where(p => p.IsOfKind(ResourcePropertyKind.Key)).FirstOrDefault() == null)
                {
                    throw new InvalidOperationException(Strings.ResourceType_MissingKeyPropertiesForEntity(this.FullName));
                }
            }

            // set all the properties to readonly
            foreach (ResourceProperty p in declaredProperties)
            {
                p.SetReadOnly();

                // Note that we cache the propertyinfo objects for each CLR properties in the ResourceType class
                // rather than the ResourceProperty class because the same ResourceProperty instance can be added
                // to multiple ResourceType instances.
                if (p.CanReflectOnInstanceTypeProperty)
                {
                    this.GetPropertyInfoDecaredOnThisType(p);
                }
            }
        }
开发者ID:AlineGuan,项目名称:odata.net,代码行数:43,代码来源:ResourceType.cs

示例14: GetHeaderRows

 private static IEnumerable<IWebElement> GetHeaderRows(ReadOnlyCollection<IWebElement> allRows)
 {
     var theadHeaderRows = allRows.Where(x => String.Compare(x.GetParent().TagName, "thead", true) == 0);
     var inlineHeaderRows = allRows.Where(x => x.FindElements(By.TagName("th")).Any());
     return theadHeaderRows.Union(inlineHeaderRows);
 }
开发者ID:mvbalaw,项目名称:FluentWebUITesting,代码行数:6,代码来源:TableWrapper.cs

示例15: Where_IReadOnlyCollection_ReturnsExpectedValues_False

        public void Where_IReadOnlyCollection_ReturnsExpectedValues_False()
        {
            IReadOnlyCollection<int> source = new ReadOnlyCollection<int>(new List<int> { 1, 2, 3, 4, 5 });
            Func<int, bool> falsePredicate = (value) => false;

            IEnumerable<int> result = source.Where(falsePredicate);

            Assert.Equal(0, result.Count());
        }
开发者ID:chcosta,项目名称:corefx,代码行数:9,代码来源:WhereTests.cs


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