static void AddNormalCheck(TypeDefinition type, Collection<Instruction> c, PropertyDefinition property, ParameterDefinition left, ParameterDefinition right) { var genericInstance = new Lazy<TypeReference>(() => property.PropertyType.GetGenericInstanceType(type)); var getMethodImported = ReferenceFinder.ImportCustom(property.GetGetMethod(type)); c.Add(Instruction.Create(type.GetLdArgForType(), left)); c.Add(Instruction.Create(getMethodImported.GetCallForMethod(), getMethodImported)); if (property.PropertyType.IsValueType || property.PropertyType.IsGenericParameter) { c.Add(Instruction.Create(OpCodes.Box, genericInstance.Value)); } c.Add(Instruction.Create(type.GetLdArgForType(), right)); c.Add(Instruction.Create(getMethodImported.GetCallForMethod(), getMethodImported)); if (property.PropertyType.IsValueType || property.PropertyType.IsGenericParameter) { c.Add(Instruction.Create(OpCodes.Box, genericInstance.Value)); } c.Add(Instruction.Create(OpCodes.Call, ReferenceFinder.Object.StaticEquals)); }
static void AddSimpleValueCheck(Collection<Instruction> c, PropertyDefinition property, TypeDefinition type, ParameterDefinition left, ParameterDefinition right) { var getMethod = property.GetGetMethod(type); var getMethodImported = ReferenceFinder.ImportCustom(getMethod); c.Add(Instruction.Create(type.GetLdArgForType(), left)); c.Add(Instruction.Create(getMethodImported.GetCallForMethod(), getMethodImported)); c.Add(Instruction.Create(type.GetLdArgForType(), right)); c.Add(Instruction.Create(getMethodImported.GetCallForMethod(), getMethodImported)); c.Add(Instruction.Create(OpCodes.Ceq)); }
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)); }); }