bool TransformDecimalFieldToConstant(LdObj inst, out LdcDecimal result) { if (inst.MatchLdsFld(out var field) && field.DeclaringType.IsKnownType(KnownTypeCode.Decimal)) { decimal?value = null; if (field.Name == "One") { value = decimal.One; } else if (field.Name == "MinusOne") { value = decimal.MinusOne; } else if (field.Name == "Zero") { value = decimal.Zero; } if (value != null) { result = new LdcDecimal(value.Value).WithILRange(inst).WithILRange(inst.Target); return(true); } } result = null; return(false); }
bool TransformDecimalCtorToConstant(NewObj inst, out LdcDecimal result) { IType t = inst.Method.DeclaringType; result = null; if (!t.IsKnownType(KnownTypeCode.Decimal)) { return(false); } var args = inst.Arguments; if (args.Count == 1) { int val; if (args[0].MatchLdcI4(out val)) { result = new LdcDecimal(val); return(true); } } else if (args.Count == 5) { int lo, mid, hi, isNegative, scale; if (args[0].MatchLdcI4(out lo) && args[1].MatchLdcI4(out mid) && args[2].MatchLdcI4(out hi) && args[3].MatchLdcI4(out isNegative) && args[4].MatchLdcI4(out scale)) { result = new LdcDecimal(new decimal(lo, mid, hi, isNegative != 0, (byte)scale)); return(true); } } return(false); }