Exemplo n.º 1
0
        private void ProcessPropertySetNormalCompareGeneric(IlBuilder processor)
        {
            processor.LoadInt(1);
            processor.LoadInt(0);
            var l1 = processor.Instructions[0];
            var l2 = processor.Instructions[1];

            processor.Instructions.Clear();

            var getValueOrDefault = _handler.Import(_pi.PropertyDefinition.PropertyType.GetMethod("GetValueOrDefault"));
            var getHasValue       = _handler.Import(_pi.PropertyDefinition.PropertyType.GetMethod("get_HasValue"));
            var type     = (GenericInstanceType)_pi.PropertyDefinition.PropertyType;
            var realType = type.GenericArguments[0].FullName;

            var v0 = processor.DeclareLocal(_pi.PropertyDefinition.PropertyType);
            var v1 = processor.DeclareLocal(_pi.PropertyDefinition.PropertyType);

            processor.DeclareLocal(_handler.BoolType);
            processor.LoadArg(1).SetLoc(0).LoadArg(0).LoadField(_pi.FieldDefinition).SetLoc(1).LoadLocala_S(v0);

            if (realType == KnownTypesHandler.Decimal)
            {
                processor.Call(getValueOrDefault).LoadLocala_S(v1).Call(getValueOrDefault)
                .Call(_handler.TypeDict[realType]);
                processor.BrTrue_S(l1).LoadLocala_S(v0).Call(getHasValue).LoadLocala_S(v1).Call(getHasValue);
                processor.Ceq().LoadInt(0).Ceq().Br_S(l2);
            }
            else if (_handler.TypeDict.ContainsKey(realType))
            {
                processor.LoadInt(0).Br_S(l2);
                var l4 = processor.Instructions[processor.Instructions.Count - 2];
                var l3 = processor.Instructions[processor.Instructions.Count - 1];
                processor.Instructions.Remove(l3);
                processor.Instructions.Remove(l4);
                processor.Call(getHasValue).LoadLocala_S(v1).Call(getHasValue).Bne_Un_S(l1);
                processor.LoadLocala_S(v0).Call(getHasValue).BrFalse_S(l4).LoadLocala_S(v0);
                processor.Call(getValueOrDefault).LoadLocala_S(v1).Call(getValueOrDefault)
                .Call(_handler.TypeDict[realType]).Br_S(l3);
                processor.Instructions.Add(l4);
                processor.Instructions.Add(l3);
            }
            else
            {
                processor.Call(getValueOrDefault);
                processor.ConvFloaty(realType);
                processor.LoadLocala_S(v1).Call(getValueOrDefault);
                processor.ConvFloaty(realType);
                processor.Bne_Un_S(l1).LoadLocala_S(v0).Call(getHasValue).LoadLocala_S(v1).Call(getHasValue);
                processor.Ceq().LoadInt(0).Ceq().Br_S(l2);
            }

            processor.Instructions.Add(l1);
            processor.Instructions.Add(l2);
            processor.Ceq().SetLoc(2).LoadLoc(2);
            processor.BrTrue_S(_pi.PropertyDefinition.SetMethod.Body.Instructions.LastItem());
        }
Exemplo n.º 2
0
 private void ProcessPropertySetNormalCompareValueType(IlBuilder processor)
 {
     processor.DeclareLocal(_handler.BoolType);
     processor.LoadArg(1).LoadArg(0).LoadField(_pi.FieldDefinition);
     if (_handler.TypeDict.ContainsKey(_pi.PropertyDefinition.PropertyType.FullName))
     {
         var mi = _handler.TypeDict[_pi.PropertyDefinition.PropertyType.FullName];
         processor.Call(mi).LoadInt(0);
     }
     processor.Ceq().SetLoc(0).LoadLoc(0);
     processor.BrTrue_S(_pi.PropertyDefinition.SetMethod.Body.Instructions.LastItem());
 }