private void setNewValue(string text, SetterType type)
        {
            if (int.TryParse(text, out int newValue))
            {
                if ((newValue >= MainPage.maxValue) && (type == SetterType.INCREMENT || type == SetterType.NONE))
                {
                    itemCountEditor.Text = MainPage.maxValue.ToString();
                    return;
                }

                if ((newValue <= MainPage.minValue) && (type == SetterType.DECREMENT || type == SetterType.NONE))
                {
                    itemCountEditor.Text = MainPage.minValue.ToString();
                    return;
                }

                switch (type)
                {
                case SetterType.INCREMENT:
                    ++newValue;
                    break;

                case SetterType.DECREMENT:
                    --newValue;
                    break;

                default:
                    break;
                }

                itemCountEditor.Text = newValue.ToString();
            }
        }
Exemple #2
0
        protected void CreateSetNotNullValue(ILGenerator ilOut, SetterType setterType, Type propType)
        {
            switch (setterType)
            {
            case SetterType.Enum:
                GenerateSetUnboxedToSubType(ilOut, propType, null);
                break;

            case SetterType.Value:
                GenerateSetUnboxedToSubType(ilOut, propType, null);
                break;

            case SetterType.ReferenceNI:
                GenerateSetConverted(ilOut, propType, true);
                break;

            case SetterType.ValueNI:
                GenerateSetConverted(ilOut, propType, false);
                break;

            case SetterType.Struct:
                GenerateSetUnboxedToSubType(ilOut, propType, null);
                break;

            case SetterType.StructNI:
                GenerateSetConverted(ilOut, propType, false);
                break;

            case SetterType.Nullable:
                GenerateSetUnboxedToSubType(ilOut, propType, propType.GetGenericArguments()[0]);
                break;

            case SetterType.NullableNI:
                GenerateConvertedToSubType(ilOut, propType, propType.GetGenericArguments()[0]);
                break;

            case SetterType.Reference:
                GenerateSetRef(ilOut, propType);
                break;
            }
        }
Exemple #3
0
        public void CreateExtractScalar(
            ILGenerator ilOut,
            PropertyInfo prop,
            FieldInfo field,
            Type sourceDataType,
            int propIndex)
        {
            Type       storeType;
            MethodInfo setProp = null;

            if (field != null)
            {
                storeType = field.FieldType;
            }
            else
            {
                storeType = prop.PropertyType;
                setProp   = prop.GetSetMethod();
            }

            Label lblElse = ilOut.DefineLabel();
            Label lblEnd  = ilOut.DefineLabel();

            GeneratePropSetterHeader(ilOut, propIndex);

            ilOut.Emit(OpCodes.Bne_Un, lblElse);

            SetterType setterType = GetSetterType(storeType, sourceDataType);

            CreateSetNullValue(setterType, ilOut, storeType);
            GenerateSet(ilOut, setProp, field);

            ilOut.Emit(OpCodes.Br, lblEnd);
            ilOut.MarkLabel(lblElse);

            CreateSetNotNullValue(ilOut, setterType, storeType);
            GenerateSet(ilOut, setProp, field);

            ilOut.MarkLabel(lblEnd);
        }
Exemple #4
0
        protected void CreateSetNullValue(SetterType setterType, ILGenerator ilGen, Type propType)
        {
            switch (setterType)
            {
            case SetterType.Enum:
                GenerateSetDefault(ilGen);
                break;

            case SetterType.Value:
                GenerateSetDefault(ilGen);
                break;

            case SetterType.ValueNI:
                GenerateSetDefault(ilGen);
                break;

            case SetterType.Struct:
                GenerateSetEmpty(ilGen, propType);
                break;

            case SetterType.StructNI:
                GenerateSetEmpty(ilGen, propType);
                break;

            case SetterType.Nullable:
                GenerateSetEmpty(ilGen, propType);
                break;

            case SetterType.NullableNI:
                GenerateSetEmpty(ilGen, propType);
                break;

            case SetterType.ReferenceNI:
            case SetterType.Reference:
                GenerateSetNull(ilGen);
                break;
            }
        }
Exemple #5
0
        public void CreateExtractScalar(
            ILGenerator ilOut,
            PropertyInfo prop,
            FieldInfo field,
            Type sourceDataType,
            int memberIx)
        {
            Type       storeType;
            MethodInfo setProp = null;

            if (field != null)
            {
                storeType = field.FieldType;
            }
            else
            {
                storeType = prop.PropertyType;
                setProp   = prop.GetSetMethod();
            }

            Label lblElse    = ilOut.DefineLabel();
            Label lblSetNull = ilOut.DefineLabel();
            Label lblEnd     = ilOut.DefineLabel();

            GeneratePropSetterHeader(ilOut, memberIx);

            //ilOut.Emit(OpCodes.Brfalse, lblElse);
            ilOut.Emit(OpCodes.Ldc_I4_0);
            ilOut.Emit(OpCodes.Blt, lblSetNull);

            ilOut.Emit(OpCodes.Ldarg_1);
            ilOut.Emit(OpCodes.Ldloc_1);
            ilOut.Emit(OpCodes.Call, _IsDBNull);
            ilOut.Emit(OpCodes.Brfalse, lblElse);

            ilOut.MarkLabel(lblSetNull);

            SetterType setterType = GetSetterType(storeType, sourceDataType);

            CreateSetNullValue(setterType, ilOut, storeType);
            GenerateSet(ilOut, setProp, field);

            ilOut.Emit(OpCodes.Br, lblEnd);
            ilOut.MarkLabel(lblElse);

            bool readerMethodExist = _ReaderGetMethods.ContainsKey(sourceDataType);
            bool useDirectSet;

            if (storeType.IsEnum && sourceDataType == typeof(int))
            {
                useDirectSet = true;
            }
            else
            {
                useDirectSet = readerMethodExist && storeType == sourceDataType;
            }

            if (setterType == SetterType.Nullable &&
                prop.PropertyType.GetGenericArguments()[0] == sourceDataType)
            {
                GenerateSetDirect(
                    ilOut,
                    memberIx,
                    storeType,
                    _ReaderGetMethods[sourceDataType],
                    sourceDataType);
            }
            else if (setterType == SetterType.NullableNI)
            {
                CreateSetNotNullValueFromSubType(
                    ilOut,
                    memberIx,
                    storeType,
                    storeType.GetGenericArguments()[0]);
            }
            else if (useDirectSet)
            {
                GenerateSetDirect(
                    ilOut,
                    memberIx,
                    storeType,
                    _ReaderGetMethods[sourceDataType],
                    null);
            }
            else
            {
                CreateSetNotNullValue(ilOut, memberIx, storeType);
            }

            GenerateSet(ilOut, setProp, field);
            ilOut.MarkLabel(lblEnd);
        }