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


C# Collection.If方法代码示例

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


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

示例1: AddCollectionCode

        static void AddCollectionCode(PropertyDefinition property, bool isFirst, Collection<Instruction> ins, VariableDefinition resultVariable, MethodDefinition method, TypeDefinition type)
        {
            if (isFirst)
            {
                ins.Add(Instruction.Create(OpCodes.Ldc_I4_0));
                ins.Add(Instruction.Create(OpCodes.Stloc, resultVariable));
            }

            ins.If(
                c => LoadVariable(property, c, type),
                t =>
                {
                    LoadVariable(property, t, type);
                    var enumeratorVariable = method.Body.Variables.Add(property.Name + "Enumerator", ReferenceFinder.IEnumerator.TypeReference);
                    var currentVariable = method.Body.Variables.Add(property.Name + "Current", ReferenceFinder.Object.TypeReference);

                    GetEnumerator(t, enumeratorVariable);

                    AddCollectionLoop(resultVariable, t, enumeratorVariable, currentVariable);
                },
                f => { });
        }
开发者ID:GeertvanHorrik,项目名称:Equals,代码行数:22,代码来源:GetHashCodeInjector.cs

示例2: AddCollectionSecondArgumentCheck

 static void AddCollectionSecondArgumentCheck(Collection<Instruction> t)
 {
     t.If(
         ct =>
         {
             ct.Add(Instruction.Create(OpCodes.Ldarg_1));
             ct.Add(Instruction.Create(OpCodes.Ldnull));
             ct.Add(Instruction.Create(OpCodes.Ceq));
         },
         tt => tt.Add(Instruction.Create(OpCodes.Ldc_I4_1)),
         ft => ft.Add(Instruction.Create(OpCodes.Ldc_I4_0)));
 }
开发者ID:rjasica,项目名称:Equals,代码行数:12,代码来源:EqualsInjector.cs

示例3: AddCollectionEquals

        static void AddCollectionEquals(TypeDefinition type, MethodDefinition collectionEquals, PropertyDefinition property, TypeDefinition propType, Collection<Instruction> e, ParameterDefinition left, ParameterDefinition right)
        {
            e.If(
                cf =>
                {
                    cf.Add(Instruction.Create(type.GetLdArgForType(), right));
                    cf.Add(Instruction.Create(OpCodes.Ldnull));
                    cf.Add(Instruction.Create(OpCodes.Ceq));
                },
                t => t.Add(Instruction.Create(OpCodes.Ldc_I4_0)),
                es =>
                {
                    var getMethod = property.GetGetMethod(type);
                    var getMethodImported = ReferenceFinder.ImportCustom(getMethod);

                    es.Add(Instruction.Create(type.GetLdArgForType(), left));
                    es.Add(Instruction.Create(getMethodImported.GetCallForMethod(), getMethodImported));
                    if (propType.IsValueType)
                    {
                        es.Add(Instruction.Create(OpCodes.Box, propType));
                    }

                    es.Add(Instruction.Create(type.GetLdArgForType(), right));
                    es.Add(Instruction.Create(getMethodImported.GetCallForMethod(), getMethodImported));
                    if (propType.IsValueType)
                    {
                        es.Add(Instruction.Create(OpCodes.Box, propType));
                    }

                    es.Add(Instruction.Create(OpCodes.Call, collectionEquals));
                });
        }
开发者ID:rjasica,项目名称:Equals,代码行数:32,代码来源:EqualsInjector.cs

示例4: AddCollectionCheck

 static void AddCollectionCheck(TypeDefinition type, MethodDefinition collectionEquals, Collection<Instruction> c, PropertyDefinition property, TypeDefinition propType, ParameterDefinition left, ParameterDefinition right)
 {
     c.If(
         AddCollectionFirstArgumentCheck,
         AddCollectionSecondArgumentCheck,
         e => AddCollectionEquals(type, collectionEquals, property, propType, e,left,right));
 }
开发者ID:rjasica,项目名称:Equals,代码行数:7,代码来源:EqualsInjector.cs

示例5: AddCheckEqualsReference

        static void AddCheckEqualsReference(TypeDefinition type, Collection<Instruction> ins, bool skipBoxingSecond)
        {
            var resolvedType = type.IsValueType ? type.GetGenericInstanceType(type) : null;
            ins.If(
                c =>
                {
                    c.Add(Instruction.Create(OpCodes.Ldnull));
                    c.Add(Instruction.Create(OpCodes.Ldarg_1));
                    if (type.IsValueType && !skipBoxingSecond)
                    {
                        c.Add(Instruction.Create(OpCodes.Box, resolvedType));
                    }
                    c.Add(Instruction.Create(OpCodes.Call, ReferenceFinder.Object.ReferenceEquals));
                },
                AddReturnFalse);

            ins.If(
                c =>
                {
                    c.Add(Instruction.Create(OpCodes.Ldarg_0));
                    if (type.IsValueType)
                    {
                        c.Add(Instruction.Create(OpCodes.Ldobj, resolvedType));
                        c.Add(Instruction.Create(OpCodes.Box, resolvedType));
                    }
                    c.Add(Instruction.Create(OpCodes.Ldarg_1));
                    if (type.IsValueType && !skipBoxingSecond)
                    {
                        c.Add(Instruction.Create(OpCodes.Box, resolvedType));
                    }
                    c.Add(Instruction.Create(OpCodes.Call, ReferenceFinder.Object.ReferenceEquals));
                },
                AddReturnTrue);
        }
开发者ID:rjasica,项目名称:Equals,代码行数:34,代码来源:EqualsInjector.cs

示例6: AddNormalCode

 static void AddNormalCode(PropertyDefinition property, Collection<Instruction> ins, TypeDefinition type)
 {
     ins.If(
         c =>
         {
         },
         t =>
         {
             LoadVariable(property, t, type);
             t.Add(Instruction.Create(OpCodes.Callvirt, ReferenceFinder.Object.GetHashcode));
         },
         f => f.Add(Instruction.Create(OpCodes.Ldc_I4_0)));
 }
开发者ID:GeertvanHorrik,项目名称:Equals,代码行数:13,代码来源:GetHashCodeInjector.cs

示例7: AddNullableProperty

        static VariableDefinition AddNullableProperty(PropertyDefinition property, Collection<Instruction> ins, TypeDefinition type, VariableDefinition variable)
        {
            ins.If(c =>
            {
                var nullablePropertyResolved = property.PropertyType.Resolve();
                var nullablePropertyImported = ReferenceFinder.ImportCustom(property.PropertyType);

                ins.Add(Instruction.Create(OpCodes.Ldarg_0));
                var getMethod = ReferenceFinder.ImportCustom(property.GetGetMethod(type));
                c.Add(Instruction.Create(OpCodes.Call, getMethod));

                variable = new VariableDefinition(getMethod.ReturnType);
                c.Add(Instruction.Create(OpCodes.Stloc, variable));
                c.Add(Instruction.Create(OpCodes.Ldloca, variable));

                var hasValuePropertyResolved = nullablePropertyResolved.Properties.First(x => x.Name == "HasValue").Resolve();
                var hasMethod = ReferenceFinder.ImportCustom(hasValuePropertyResolved.GetGetMethod(nullablePropertyImported));
                c.Add(Instruction.Create(OpCodes.Call, hasMethod));
            },
                t =>
                {
                    var nullableProperty = ReferenceFinder.ImportCustom(property.PropertyType);

                    t.Add(Instruction.Create(OpCodes.Ldarg_0));
                    var imp = property.GetGetMethod(type);
                    var imp2 = ReferenceFinder.ImportCustom(imp);

                    t.Add(Instruction.Create(OpCodes.Call, imp2));
                    t.Add(Instruction.Create(OpCodes.Box, nullableProperty));
                    t.Add(Instruction.Create(OpCodes.Callvirt, ReferenceFinder.Object.GetHashcode));
                },
                e => e.Add(Instruction.Create(OpCodes.Ldc_I4_0)));
            return variable;
        }
开发者ID:GeertvanHorrik,项目名称:Equals,代码行数:34,代码来源:GetHashCodeInjector.cs

示例8: AddCollectionEquals

        private static void AddCollectionEquals(TypeDefinition type, MethodDefinition collectionEquals, PropertyDefinition property, TypeDefinition propType, Collection<Instruction> e)
        {
            e.If(
                cf =>
                {
                    cf.Add(Instruction.Create(OpCodes.Ldarg_1));
                    cf.Add(Instruction.Create(OpCodes.Ldnull));
                    cf.Add(Instruction.Create(OpCodes.Ceq));
                },
                t => { t.Add(Instruction.Create(OpCodes.Ldc_I4_0)); },
                es =>
                {
                    es.Add(Instruction.Create(OpCodes.Ldarg_0));
                    es.Add(Instruction.Create(OpCodes.Callvirt, property.GetGetMethod(type)));
                    if (propType.IsValueType)
                    {
                        es.Add( Instruction.Create( OpCodes.Box, propType ) );
                    }

                    es.Add(Instruction.Create(OpCodes.Ldarg_1));
                    es.Add(Instruction.Create(OpCodes.Callvirt, property.GetGetMethod(type)));
                    if (propType.IsValueType)
                    {
                        es.Add( Instruction.Create( OpCodes.Box, propType ) );
                    }

                    es.Add(Instruction.Create(OpCodes.Call, collectionEquals));
                });
        }
开发者ID:kzaikin,项目名称:Equals,代码行数:29,代码来源:EqualsInjector.cs

示例9: AddCollectionCheck

 private static void AddCollectionCheck(TypeDefinition type, MethodDefinition collectionEquals, Collection<Instruction> c, PropertyDefinition property, TypeDefinition propType)
 {
     c.If(
         cf => AddCollectionFirstArgumentCheck(cf),
         t => AddCollectionSecondArgumentCheck(t),
         e => AddCollectionEquals(type, collectionEquals, property, propType, e));
 }
开发者ID:kzaikin,项目名称:Equals,代码行数:7,代码来源:EqualsInjector.cs

示例10: AddCheckEqualsReference

        private static void AddCheckEqualsReference(TypeDefinition type, Collection<Instruction> ins)
        {
            ins.If(
                c =>
                {
                    c.Add(Instruction.Create(OpCodes.Ldnull));
                    c.Add(Instruction.Create(OpCodes.Ldarg_1));
                    c.Add(Instruction.Create(OpCodes.Call, ReferenceFinder.Object.ReferenceEquals));
                },
                t => AddReturnFalse(t));

            ins.If(
                c =>
                {
                    c.Add(Instruction.Create(OpCodes.Ldarg_0));
                    if (type.IsValueType)
                    {
                        c.Add(Instruction.Create(OpCodes.Box, type));
                    }
                    c.Add(Instruction.Create(OpCodes.Ldarg_1));
                    c.Add(Instruction.Create(OpCodes.Call, ReferenceFinder.Object.ReferenceEquals));
                },
                t => AddReturnTrue(t));
        }
开发者ID:kzaikin,项目名称:Equals,代码行数:24,代码来源:EqualsInjector.cs

示例11: AddRightAndNullReferenceEquals

 private static void AddRightAndNullReferenceEquals(Collection<Instruction> ins, ParameterDefinition right)
 {
     ins.If(
         c =>
         {
             ins.Add(Instruction.Create(OpCodes.Ldarg, right));
             ins.Add(Instruction.Create(OpCodes.Ldnull));
             ins.Add(Instruction.Create(OpCodes.Call, ReferenceFinder.Object.ReferenceEquals));
         },
         t =>
         {
             ins.Add(Instruction.Create(OpCodes.Ldc_I4_0));
             ins.Add(Instruction.Create(OpCodes.Ret));
         });
 }
开发者ID:kzaikin,项目名称:Equals,代码行数:15,代码来源:CollectionHelperInjector.cs

示例12: AddLeftAndRightReferenceEquals

 static void AddLeftAndRightReferenceEquals(Collection<Instruction> ins, ParameterDefinition left, ParameterDefinition right)
 {
     ins.If(
         c =>
         {
             ins.Add(Instruction.Create(OpCodes.Ldarg, left));
             ins.Add(Instruction.Create(OpCodes.Ldarg, right));
             ins.Add(Instruction.Create(OpCodes.Call, ReferenceFinder.Object.ReferenceEquals));
         },
         t =>
         {
             ins.Add(Instruction.Create(OpCodes.Ldc_I4_1));
             ins.Add(Instruction.Create(OpCodes.Ret));
         });
 }
开发者ID:GeertvanHorrik,项目名称:Equals,代码行数:15,代码来源:CollectionHelperInjector.cs


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