本文整理汇总了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 => { });
}
示例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)));
}
示例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));
});
}
示例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));
}
示例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);
}
示例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)));
}
示例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;
}
示例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));
});
}
示例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));
}
示例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));
}
示例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));
});
}
示例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));
});
}