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


C# IEnumerable.OfType方法代码示例

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


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

示例1: ApplyMetadataAwareAttributes

 private static void ApplyMetadataAwareAttributes(IEnumerable<Attribute> attributes, ModelMetadata result)
 {
     foreach (IMetadataAware awareAttribute in attributes.OfType<IMetadataAware>())
     {
         awareAttribute.OnMetadataCreated(result);
     }
 }
开发者ID:KevMoore,项目名称:aspnetwebstack,代码行数:7,代码来源:AssociatedMetadataProvider.cs

示例2: CreateNewConcepts

        public IEnumerable<IConceptInfo> CreateNewConcepts(IEnumerable<IConceptInfo> existingConcepts)
        {
            var newConcepts = new List<IConceptInfo>();

            var changesOnChangesItems = existingConcepts.OfType<ChangesOnChangedItemsInfo>()
                .Where(change => change.Computation == EntityComputedFrom.Source)
                .ToArray();

            newConcepts.AddRange(changesOnChangesItems.Select(change =>
                new KeepSynchronizedOnChangedItemsInfo { EntityComputedFrom = EntityComputedFrom, UpdateOnChange = change, FilterSaveExpression = FilterSaveExpression }));

            // If the computed data source is an extension, but its value does not depend on changes in its base data structure,
            // it should still be computed every time the base data structure data is inserted.

            var dataSourceExtension = existingConcepts.OfType<DataStructureExtendsInfo>()
                .Where(ex => ex.Extension == EntityComputedFrom.Source)
                .SingleOrDefault();

            if (dataSourceExtension != null
                && dataSourceExtension.Base is IWritableOrmDataStructure
                && !changesOnChangesItems.Any(c => c.DependsOn == dataSourceExtension.Base)
                && !existingConcepts.OfType<ChangesOnBaseItemInfo>().Where(c => c.Computation == EntityComputedFrom.Source).Any())
                newConcepts.Add(new ComputeForNewBaseItemsInfo { EntityComputedFrom = EntityComputedFrom, FilterSaveExpression = FilterSaveExpression });

            return newConcepts;
        }
开发者ID:koav,项目名称:Rhetos,代码行数:26,代码来源:KeepSynchronizedInfo.cs

示例3: Populate

 /// <summary>
 /// Populate asynchronously.
 /// </summary>
 /// <param name="done">The callback.</param>
 public void Populate(Action<ISeries> done) {
     _series.Populate(() => {
         _children = _series.Children.Select(x => new Chapter(x) as IChapter).ToArray();
         foreach (var source in _children.OfType<Chapter>()) {
             if (source.Number != -1) continue;
             var differential = new Dictionary<double, int>();
             var origin = null as Chapter;
             foreach (var candidate in _children.OfType<Chapter>()) {
                 if (candidate != source && candidate.Number != -1 && candidate.Volume == source.Volume) {
                     if (origin != null) {
                         var difference = Math.Round(candidate.Number - origin.Number, 4);
                         if (differential.ContainsKey(difference)) {
                             differential[difference]++;
                         } else {
                             differential[difference] = 1;
                         }
                     }
                     origin = candidate;
                 }
             }
             if (differential.Count == 0) {
                 source.Number = origin == null ? 0.5 : origin.Number + origin.Number / 2;
             } else {
                 var shift = differential.OrderByDescending(x => x.Value).FirstOrDefault().Key;
                 source.Number = Math.Round(origin.Number + (shift <= 0 || shift >= 1 ? 1 : shift) / 2, 4);
             }
         }
         done(this);
     });
 }
开发者ID:Kokoro87,项目名称:mangarack.cs,代码行数:34,代码来源:Series.cs

示例4: InitializeVariables

        private void InitializeVariables(IEnumerable<IVariable> variables)
        {
            ValidateInputProperties();

            Index1Variable = variables.OfType<IVariable>().First(v => v.Name == Index1VariableName);
            Index2Variable = variables.OfType<IVariable>().First(v => v.Name == Index2VariableName);
            XVariable = variables.OfType<IVariable<double>>().First(v => v.Name == XVariableName);
            YVariable = variables.OfType<IVariable<double>>().First(v => v.Name == YVariableName);
            ValuesVariable = variables.First(v => v.Name == ValuesVariableName);

            if(!string.IsNullOrEmpty(TimeVariableName))
            {
                TimeVariable = variables.First(v => v.Name == TimeVariableName);
            }

/*
            if(!XVariable.Arguments.SequenceEqual(YVariable.Arguments))
            {
                throw new NotSupportedException("Arguments used in X variable must be the same as in Y variable");
            }

            if (!XVariable.Arguments.SequenceEqual(ValuesVariable.Arguments))
            {
                throw new NotSupportedException("Arguments used in Values variable must be the same as in X and Y variables");
            }
*/
        }
开发者ID:lishxi,项目名称:_SharpMap,代码行数:27,代码来源:DiscreteGridPointCoverageBuilder.cs

示例5: IsHiddenBy

 private static bool IsHiddenBy(IEntity entity, IEnumerable<IEntity> members)
 {
     var m = entity as IMethod;
     if (m != null)
         return members.OfType<IMethod>().Any(existing => SameNameAndSignature(m, existing));
     return members.OfType<IEntity>().Any(existing => existing.Name == entity.Name);
 }
开发者ID:Bombadil77,项目名称:boo,代码行数:7,代码来源:MemberCollector.cs

示例6: CreateMetadata

        protected override ModelMetadata CreateMetadata(IEnumerable<Attribute> attributes, Type containerType,
                                                        Func<object> modelAccessor, Type modelType, string propertyName) {
            ModelMetadata metadata = base.CreateMetadata(attributes, containerType, modelAccessor, modelType, propertyName);

            DisplayAttribute display = attributes.OfType<DisplayAttribute>().FirstOrDefault();
            if (display != null) {
                string name = display.GetName();
                if (name != null) {
                    metadata.DisplayName = name;
                }

                metadata.Description = display.GetDescription();
                metadata.ShortDisplayName = display.GetShortName();
                metadata.Watermark = display.GetPrompt();
            }

            EditableAttribute editable = attributes.OfType<EditableAttribute>().FirstOrDefault();
            if (editable != null) {
                metadata.IsReadOnly = !editable.AllowEdit;
            }

            DisplayFormatAttribute displayFormat = attributes.OfType<DisplayFormatAttribute>().FirstOrDefault();
            if (displayFormat != null && !displayFormat.HtmlEncode && String.IsNullOrWhiteSpace(metadata.DataTypeName)) {
                metadata.DataTypeName = DataType.Html.ToString();
            }

            foreach (IMetadataAware awareAttribute in attributes.OfType<IMetadataAware>()) {
                awareAttribute.OnMetadataCreated(metadata);
            }

            return metadata;
        }
开发者ID:consumentor,项目名称:Server,代码行数:32,代码来源:DataAnnotations4ModelMetadataProvider.cs

示例7: CreateMetadata

        protected override ModelMetadata CreateMetadata(IEnumerable<Attribute> attributes, Type containerType, Func<object> modelAccessor, Type modelType, string propertyName)
        {
            ModelMetadata metadata = base.CreateMetadata(attributes, containerType, modelAccessor, modelType,
                                                         propertyName);
            RegularExpressionAttribute regularExpressionAttribute =
                attributes.OfType<RegularExpressionAttribute>().FirstOrDefault();
            RangeAttribute rangeAttribute = attributes.OfType<RangeAttribute>().FirstOrDefault();
            CurrencyAttribute currencyAttribute = attributes.OfType<CurrencyAttribute>().FirstOrDefault();
            StringLengthAttribute stringLengthAttribute = attributes.OfType<StringLengthAttribute>().FirstOrDefault();
            MaxLengthAttribute maxLengthAttribute = attributes.OfType<MaxLengthAttribute>().FirstOrDefault();

            if (regularExpressionAttribute != null)
                metadata.AdditionalValues["RegularExpression"] = regularExpressionAttribute;

            if (rangeAttribute != null)
                metadata.AdditionalValues["Range"] = rangeAttribute;

            if (currencyAttribute != null)
                metadata.AdditionalValues["Currency"] = currencyAttribute;

            if (stringLengthAttribute != null && maxLengthAttribute == null && stringLengthAttribute.MaximumLength > 0)
                metadata.AdditionalValues["MaxLength"] = stringLengthAttribute.MaximumLength;

            if (maxLengthAttribute != null)
                metadata.AdditionalValues["MaxLength"] = maxLengthAttribute.Length;

            return metadata;
        }
开发者ID:rajeshwarn,项目名称:Dojo.NET,代码行数:28,代码来源:DojoModelMetadataProvider.cs

示例8: CreateNewConcepts

        public IEnumerable<IConceptInfo> CreateNewConcepts(IEnumerable<IConceptInfo> existingConcepts)
        {
            var newConcepts = new List<IConceptInfo>();

            var cloneMethod = typeof(object).GetMethod("MemberwiseClone", BindingFlags.NonPublic | BindingFlags.Instance);
            var property = (PropertyInfo)cloneMethod.Invoke(Source, null);
            property.DataStructure = Destination;
            newConcepts.Add(property);

            //var destinationEntity = Destination as EntityInfo;
            //if (destinationEntity != null)
            //{

            var required = existingConcepts.OfType<RequiredPropertyInfo>().Where(ci => ci.Property == Source)
                .Select(ci => new RequiredPropertyInfo { Property = property })
                .SingleOrDefault();
            if (required != null)
                newConcepts.Add(required);

            var destinationProperties = new HashSet<string>(
                existingConcepts.OfType<PropertyInfo>()
                    .Where(ci => ci.DataStructure == Destination)
                    .Select(ci => ci.Name));

            if (SqlIndexMultipleInfo.IsSupported(Destination))
                foreach (var sourceIndex in existingConcepts.OfType<SqlIndexMultipleInfo>().Where(ci => ci.Entity == Source.DataStructure))
                {
                    var indexProperties = sourceIndex.PropertyNames.Split(' ');
                    if (property.Name == indexProperties.FirstOrDefault()
                        && indexProperties.Skip(1).All(indexProperty => destinationProperties.Contains(indexProperty)))
                        newConcepts.Add(new SqlIndexMultipleInfo { Entity = Destination, PropertyNames = sourceIndex.PropertyNames });
                }

            return newConcepts;
        }
开发者ID:koav,项目名称:Rhetos,代码行数:35,代码来源:PropertyFromInfo.cs

示例9: CreateMetadata

        protected override ModelMetadata CreateMetadata(
            IEnumerable<Attribute> attributes,
            Type containerType,
            Func<object> modelAccessor,
            Type modelType,
            string propertyName)
        {
            var modelMetadata = base.CreateMetadata(attributes, containerType, modelAccessor, modelType, propertyName);

            //attributes.OfType<DataTypeAttribute>().ToList().ForEach(m => { if (m.DataType.Equals(DataType.Date) || (m.DataType.Equals(DataType.Custom) && m.CustomDataType == "DateTimeDto")) modelMetadata.TemplateHint = "DatePicker"; });
            attributes.OfType<DataTypeAttribute>().ToList().ForEach(m =>
            {
                if (m.DataType.Equals(DataType.Custom) &&
                 (m.CustomDataType == "TimesheetDto"))
                    modelMetadata.TemplateHint = "TimesheetEditor";
            });
            attributes.OfType<DataTypeAttribute>().ToList().ForEach(m =>
            {
                if (m.DataType.Equals(DataType.Custom) &&
                 (m.CustomDataType == "TimesheetDtoList"))
                    modelMetadata.TemplateHint = "TimesheetList";
                if (m.DataType.Equals(DataType.Custom) &&
                (m.CustomDataType == "TerraGraphicDtoList"))
                    modelMetadata.TemplateHint = "TerraGraphicsList";
            });
            //attributes.OfType<DataTypeAttribute>().ToList().ForEach(m =>
            //{
            //    if (m.DataType.Equals(DataType.Custom) && (m.CustomDataType == "DropdownDto"))
            //        modelMetadata.TemplateHint = "Dropdown";
            //});
            attributes.OfType<MetadataAttribute>().ToList().ForEach(x => x.Process(modelMetadata));

            return modelMetadata;
        }
开发者ID:andreyu,项目名称:Reports,代码行数:34,代码来源:CustomModelMetadataProvider.cs

示例10: CacheAttributes

 private void CacheAttributes(IEnumerable<Attribute> attributes)
 {
     Display = attributes.OfType<DisplayAttribute>().FirstOrDefault();
     DisplayFormat = attributes.OfType<DisplayFormatAttribute>().FirstOrDefault();
     Editable = attributes.OfType<EditableAttribute>().FirstOrDefault();
     ReadOnly = attributes.OfType<ReadOnlyAttribute>().FirstOrDefault();
 }
开发者ID:normalian,项目名称:aspnetwebstack,代码行数:7,代码来源:CachedDataAnnotationsMetadataAttributes.cs

示例11: CachedDataAnnotationsMetadataAttributes

 public CachedDataAnnotationsMetadataAttributes(IEnumerable<Attribute> attributes)
 {
     Display = attributes.OfType<DisplayAttribute>().FirstOrDefault();
     DisplayFormat = attributes.OfType<DisplayFormatAttribute>().FirstOrDefault();
     DisplayName = attributes.OfType<DisplayNameAttribute>().FirstOrDefault();
     Editable = attributes.OfType<EditableAttribute>().FirstOrDefault();
     ReadOnly = attributes.OfType<ReadOnlyAttribute>().FirstOrDefault();
 }
开发者ID:huangw-t,项目名称:aspnetwebstack,代码行数:8,代码来源:CachedDataAnnotationsMetadataAttributes.cs

示例12: FromAttributes

 public static PropertyValidator FromAttributes(IEnumerable attributes, string propertyName) {
     try {
         var validationAttributes = attributes != null ? attributes.OfType<ValidationAttribute>().ToArray() : new ValidationAttribute[0];
         var dxValidationAttributes = attributes != null ? attributes.OfType<DXValidationAttribute>().ToArray() : new DXValidationAttribute[0];
         return validationAttributes.Any() || dxValidationAttributes.Any() ? new PropertyValidator(validationAttributes, dxValidationAttributes, propertyName) : null;
     } catch(TypeAccessException) {
         return null;
     }
 }
开发者ID:JustGitHubUser,项目名称:DevExpress.Mvvm.Free,代码行数:9,代码来源:PropertyValidator.cs

示例13: GetPackagingProject

		PackagingProject GetPackagingProject (IEnumerable<IWorkspaceFileObject> items)
		{
			Solution solution = items.OfType<Solution> ().FirstOrDefault ();
			if (solution != null) {
				return GetPackagingProject (solution.GetAllProjects ());
			}

			return items.OfType<PackagingProject> ().FirstOrDefault ();
		}
开发者ID:PlayScriptRedux,项目名称:monodevelop,代码行数:9,代码来源:PackagingProjectTemplateWizard.cs

示例14: IsContradicting

        internal override bool IsContradicting(IEnumerable<BinaryRelationship> relationships)
        {
            // a < b and a <= b contradicts b < a
            var isLessOpContradicting = relationships
                .OfType<ComparisonRelationship>()
                .Where(c => c.ComparisonKind == ComparisonKind.Less)
                .Any(rel => AreOperandsSwapped(rel));

            if (isLessOpContradicting)
            {
                return true;
            }

            if (ComparisonKind == ComparisonKind.Less)
            {
                // a < b contradicts b <= a
                var isLessEqualOpContradicting = relationships
                    .OfType<ComparisonRelationship>()
                    .Where(c => c.ComparisonKind == ComparisonKind.LessOrEqual)
                    .Any(rel => AreOperandsSwapped(rel));

                if (isLessEqualOpContradicting)
                {
                    return true;
                }

                // a < b contradicts a == b and b == a
                var isEqualOpContradicting = relationships
                    .OfType<EqualsRelationship>()
                    .Any(rel => AreOperandsMatching(rel));

                if (isEqualOpContradicting)
                {
                    return true;
                }
            }

            if (ComparisonKind == ComparisonKind.LessOrEqual)
            {
                // a <= b contradicts a >= b && a != b
                var isLessEqualOp = relationships
                    .OfType<ComparisonRelationship>()
                    .Where(c => c.ComparisonKind == ComparisonKind.LessOrEqual)
                    .Any(rel => AreOperandsSwapped(rel));

                var isNotEqualOpContradicting = relationships
                    .OfType<ValueNotEqualsRelationship>()
                    .Any(rel => AreOperandsMatching(rel));

                if (isLessEqualOp && isNotEqualOpContradicting)
                {
                    return true;
                }
            }

            return false;
        }
开发者ID:duncanpMS,项目名称:sonarlint-vs,代码行数:57,代码来源:ComparisonRelationship.cs

示例15: GetLibraryProjects

		IEnumerable<DotNetProject> GetLibraryProjects (IEnumerable<IWorkspaceFileObject> items)
		{
			Solution solution = items.OfType<Solution> ().FirstOrDefault ();
			if (solution != null) {
				return GetLibraryProjects (solution.GetAllProjects ());
			}

			return items.OfType<DotNetProject> ().Where (p => !(p is PackagingProject));
		}
开发者ID:PlayScriptRedux,项目名称:monodevelop,代码行数:9,代码来源:CrossPlatformLibraryTemplateWizard.cs


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