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


C# ICollection.Zip方法代码示例

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


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

示例1: BuildBySeedNodes

        public static FeatureExtractor BuildBySeedNodes(
                ICollection<CstNode> nodes, ICollection<string> codes) {
            Contract.Requires<ArgumentException>(nodes.Count == codes.Count);

            int maxUp = 0, maxDown = 0, maxLeft = 0, maxRight = 0;
            var isInner = true;

            foreach (var nodeAndCode in nodes.Zip(codes, Tuple.Create)) {
                var node = nodeAndCode.Item1;
                var code = nodeAndCode.Item2.Trim();

                var ancestorAndIndex = node.AncestorsAndSelf()
                        .Select(Tuple.Create<CstNode, int>)
                        .First(nodeAndIndex => nodeAndIndex.Item1.Code.Contains(code));
                var ancestor = ancestorAndIndex.Item1;
                var index = ancestorAndIndex.Item2;

                maxUp = Math.Max(maxUp, index);
                maxDown = Math.Max(maxUp, ancestor.LengthFromDeepestChild);

                if (index > 0) {
                    isInner = false;
                    var children = ancestor.Children().ToList();
                    var left = 0;
                    var right = children.Count - 1;
                    while (children.Skip(left + 1).Code().Contains(code)) {
                        left++;
                    }
                    while (children.Skip(left).Take(right - left).Code().Contains(code)) {
                        right--;
                    }

                    var leftCount = node.AncestorsAndSelf()
                            .ElementAt(index - 1)
                            .PrevsFromFirst()
                            .Count();
                    maxLeft = Math.Max(maxLeft, leftCount - left);
                    maxRight = Math.Max(maxRight, right - leftCount);
                }
            }
            return isInner ? new FeatureExtractor() : new FeatureExtractor();
        }
开发者ID:RainsSoft,项目名称:Code2Xml,代码行数:42,代码来源:FeatureExtractor.cs

示例2: AreEquals

 private bool AreEquals(ICollection<TemplateItem> templates1, ICollection<TemplateItem> templates2)
 {
     return templates1 != null && templates2 != null && templates1.Count == templates2.Count && templates1.Zip(templates2, (item1, item2) => item1 == item2).All(b => b);
 }
开发者ID:krasilies,项目名称:arcgis-toolkit-dotnet,代码行数:4,代码来源:TemplatePicker.cs

示例3: CreateGenericTypeDefinitionNoLock

        private static Type CreateGenericTypeDefinitionNoLock(string genericTypeDefinitionName, ICollection<string> propertyNames, bool isMutable)
        {
            var typeBuilder = moduleBuilder.DefineType(genericTypeDefinitionName,
                attr: TypeAttributes.Public | TypeAttributes.AutoLayout
                | TypeAttributes.AnsiClass | TypeAttributes.Class
                | TypeAttributes.Sealed | TypeAttributes.BeforeFieldInit
            );
            var typeParameterNames = propertyNames
                .Select(propertyName => string.Format("<{0}>j__TPar", propertyName))
                .ToArray();
            var typeParameters = typeBuilder.DefineGenericParameters(typeParameterNames);

            var typeParameterPairs = propertyNames.Zip(typeParameters,
                (propertyName, typeParameter) => new KeyValuePair<string, GenericTypeParameterBuilder>(propertyName, typeParameter)
            ).ToArray();

            var fieldBuilders = new List<FieldBuilder>(typeParameterPairs.Length);
            foreach (var pair in typeParameterPairs)
            {
                var propertyName = pair.Key;
                var typeParameter = pair.Value;
                var fieldAttributes = FieldAttributes.Private;
                if (!isMutable)
                {
                    fieldAttributes = fieldAttributes | FieldAttributes.InitOnly;
                }
                var fieldBuilder = typeBuilder.DefineField(string.Format("<{0}>i__Field", propertyName), typeParameter, fieldAttributes);
                fieldBuilders.Add(fieldBuilder);
                var property = typeBuilder.DefineProperty(propertyName, System.Reflection.PropertyAttributes.None, typeParameter, Type.EmptyTypes);

                var getMethodBuilder = typeBuilder.DefineMethod(
                    name: string.Format("get_{0}", propertyName),
                    attributes: MethodAttributes.PrivateScope | MethodAttributes.Public | MethodAttributes.HideBySig | MethodAttributes.SpecialName,
                    callingConvention: CallingConventions.Standard | CallingConventions.HasThis,
                    returnType: typeParameter,
                    parameterTypes: Type.EmptyTypes
                );
                var getMethodIlGenerator = getMethodBuilder.GetILGenerator();
                getMethodIlGenerator.Emit(OpCodes.Ldarg_0);
                getMethodIlGenerator.Emit(OpCodes.Ldfld, fieldBuilder);
                getMethodIlGenerator.Emit(OpCodes.Ret);
                property.SetGetMethod(getMethodBuilder);

                if (isMutable)
                {
                    var setMethodBuilder = typeBuilder.DefineMethod(
                        name: string.Format("set_{0}", propertyName),
                        attributes: MethodAttributes.PrivateScope | MethodAttributes.Public | MethodAttributes.HideBySig | MethodAttributes.SpecialName,
                        callingConvention: CallingConventions.Standard | CallingConventions.HasThis,
                        returnType: null,
                        parameterTypes: new[] { typeParameter }
                    );
                    var setMethodIlGenerator = setMethodBuilder.GetILGenerator();
                    setMethodIlGenerator.Emit(OpCodes.Ldarg_0);
                    setMethodIlGenerator.Emit(OpCodes.Ldarg_1);
                    setMethodIlGenerator.Emit(OpCodes.Stfld, fieldBuilder);
                    setMethodIlGenerator.Emit(OpCodes.Ret);
                    property.SetSetMethod(setMethodBuilder);
                }
            }

            var constructorBuilder = typeBuilder.DefineConstructor(
                attributes: MethodAttributes.PrivateScope | MethodAttributes.Public | MethodAttributes.HideBySig | MethodAttributes.SpecialName | MethodAttributes.RTSpecialName,
                callingConvention: CallingConventions.Standard | CallingConventions.HasThis,
                parameterTypes: typeParameters
            );
            foreach (var o in propertyNames.Select((propertyName, index) => new { propertyName, index }))
            {
                constructorBuilder.DefineParameter(o.index + 1, ParameterAttributes.None, o.propertyName);
            }
            var constructorIlGenerator = constructorBuilder.GetILGenerator();
            constructorIlGenerator.Emit(OpCodes.Ldarg_0);
            constructorIlGenerator.Emit(OpCodes.Call, typeof(object).GetConstructors().Single());
            foreach (var obj in fieldBuilders.Select((fieldBuilder, index) => new { fieldBuilder, index }))
            {
                constructorIlGenerator.Emit(OpCodes.Ldarg_0);

                var field = obj.fieldBuilder;
                var index = obj.index;
                switch (index)
                {
                    case 0:
                        constructorIlGenerator.Emit(OpCodes.Ldarg_1);
                        break;

                    case 1:
                        constructorIlGenerator.Emit(OpCodes.Ldarg_2);
                        break;

                    case 2:
                        constructorIlGenerator.Emit(OpCodes.Ldarg_3);
                        break;

                    default:
                        constructorIlGenerator.Emit(OpCodes.Ldarg_S, index + 1);
                        break;
                }
                constructorIlGenerator.Emit(OpCodes.Stfld, field);
            }
            constructorIlGenerator.Emit(OpCodes.Ret);
//.........这里部分代码省略.........
开发者ID:tingvast,项目名称:EF7-Sandbox,代码行数:101,代码来源:AnonymousTypeUtils.cs

示例4: ConstructorCallToSql

 private string ConstructorCallToSql(ICollection<MemberInfo> members, ICollection<Expression> arguments)
 {
     var columns = members.Zip(
         arguments, 
         (member, arg) => string.Format("{0} AS [{1}]", ExpressionToSql(arg, false), member.Name));
     return string.Join(", ", columns);
 }
开发者ID:jacentino,项目名称:TypesafeSQL,代码行数:7,代码来源:SqlCommandBuilder.cs

示例5: AddRow

        private void AddRow(ICollection<IControl> controls, ICollection<int> percentWidths, double y)
        {
            if (controls.Count != percentWidths.Count)
            {
                throw new ArgumentException("Control count have to be equal to percentWidths count");
            }

            if (percentWidths.Sum() != 100)
            {
                throw new ArgumentException("Percents sum have to be 100");
            }

            double left = 0;
            double maxWidth = Rect.Width - MarginLeft - MarginRight;

            var controlWidthPairs = controls.Zip(percentWidths, (c, p) => new {Control = c, PercentWidth = p});
            foreach (var pair in controlWidthPairs)
            {
                double x = left;
                double width = maxWidth*pair.PercentWidth/100;
                double height = pair.Control.Rect.Height;

                pair.Control.Rect = new XRect(x, y, width, height);
                left += width;
                Controls.Add(pair.Control);
            }

            _currentY = controls.Select(x => (x.Rect.Height + x.Rect.Y)).Max();
            Rect = new XRect(Rect.X, Rect.Y, Rect.Width, _currentY + MarginTop + MarginBottom);
        }
开发者ID:batas2,项目名称:PdfSharp.Controls,代码行数:30,代码来源:Groupbox.cs

示例6: GenerateSrcMLFromStrings

 /// <summary>
 /// Generates srcML from the given string of source code
 /// </summary>
 /// <param name="sources">list of strings of code (each string is a whole file)</param>
 /// <param name="unitFilename">What name to give the unit</param>
 /// <param name="language">The language</param>
 /// <param name="namespaceArguments">additional arguments</param>
 /// <param name="omitXmlDeclaration">If true, the XML header is omitted</param>
 /// <returns>The srcML</returns>
 public ICollection<string> GenerateSrcMLFromStrings(ICollection<string> sources, ICollection<string> unitFilename, Language language, ICollection<UInt32> namespaceArguments, bool omitXmlDeclaration) {
     Contract.Requires(sources.Count == unitFilename.Count);
     try {
         using (Archive srcmlArchive = new Archive()) {
             srcmlArchive.SetArchiveLanguage(LanguageEnumDictionary[language]);
             srcmlArchive.EnableOption(GenerateArguments(namespaceArguments));
             var sourceandfile = sources.Zip(unitFilename, (src, fle) => new { source = src, file = fle });
             foreach (var pair in sourceandfile) {
                 using (Unit srcmlUnit = new Unit()) {
                     if (omitXmlDeclaration) {
                         srcmlArchive.DisableOption(LibSrcMLRunner.SrcMLOptions.SRCML_OPTION_XML_DECL);
                     }
                     srcmlUnit.SetUnitBuffer(pair.source);
                     srcmlUnit.SetUnitFilename(pair.file);
                     srcmlUnit.SetUnitLanguage(LanguageEnumDictionary[language]);
                     srcmlArchive.AddUnit(srcmlUnit);
                 }
             }
             return RunSrcML(srcmlArchive, LibSrcMLRunner.SrcmlCreateArchiveMtM);
         }
     }
     catch (Exception e) {
         throw new SrcMLException(e.Message, e);
     }
 }
开发者ID:cnewman,项目名称:SrcML.NET,代码行数:34,代码来源:LibSrcMLRunner.cs

示例7: assertPathsEqual

 private void assertPathsEqual(
     ICollection<GraphObject> expected,
     ICollection<GraphObject> actual)
 {
     Assert.AreEqual(expected.Count, actual.Count, "length missmatch");
     Assert.IsTrue(expected
         .Zip(actual, (a, b) => a.GraphObjectId == b.GraphObjectId)
         .All(x => x), "value missmatch");
 }
开发者ID:dbeti,项目名称:GPS,代码行数:9,代码来源:AStarPathFinderTest.cs


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