Пример #1
0
        /// <summary>Initializes a <see langword="For...Next" /> loop.</summary>
        /// <param name="Counter">The loop counter variable.</param>
        /// <param name="Start">The initial value of the loop counter.</param>
        /// <param name="Limit">The value of the <see langword="To" /> option.</param>
        /// <param name="StepValue">The value of the <see langword="Step" /> option.</param>
        /// <param name="LoopForResult">An object that contains verified values for loop values.</param>
        /// <param name="CounterResult">The counter value for the next loop iteration.</param>
        /// <returns>
        /// <see langword="False" /> if the loop has terminated; otherwise, <see langword="True" />.</returns>
        public static bool ForLoopInitObj(object Counter, object Start, object Limit, object StepValue, ref object LoopForResult, ref object CounterResult)
        {
            if (Start == null)
            {
                throw new ArgumentException(Utils.GetResourceString("Argument_InvalidNullValue1", new string[1]
                {
                    nameof(Start)
                }));
            }
            if (Limit == null)
            {
                throw new ArgumentException(Utils.GetResourceString("Argument_InvalidNullValue1", new string[1]
                {
                    nameof(Limit)
                }));
            }
            if (StepValue == null)
            {
                throw new ArgumentException(Utils.GetResourceString("Argument_InvalidNullValue1", new string[1]
                {
                    "Step"
                }));
            }
            Type     type1      = Start.GetType();
            Type     type2      = Limit.GetType();
            Type     type3      = StepValue.GetType();
            TypeCode widestType = ObjectType.GetWidestType(Start, Limit, false);
            TypeCode typeCode1  = ObjectType.GetWidestType(StepValue, widestType);

            if (typeCode1 == TypeCode.String)
            {
                typeCode1 = TypeCode.Double;
            }
            if (typeCode1 == TypeCode.Object)
            {
                throw new ArgumentException(Utils.GetResourceString("ForLoop_CommonType3", Utils.VBFriendlyName(type1), Utils.VBFriendlyName(type2), Utils.VBFriendlyName(StepValue)));
            }
            FlowControl.ObjectFor LoopFor = new FlowControl.ObjectFor();
            TypeCode typeCode2            = Type.GetTypeCode(type1);
            TypeCode typeCode3            = Type.GetTypeCode(type2);
            TypeCode typeCode4            = Type.GetTypeCode(type3);
            Type     type4 = (Type)null;

            if (typeCode2 == typeCode1 && type1.IsEnum)
            {
                type4 = type1;
            }
            if (typeCode3 == typeCode1 && type2.IsEnum)
            {
                if (type4 != null && type4 != type2)
                {
                    type4 = (Type)null;
                    goto label_18;
                }
                else
                {
                    type4 = type2;
                }
            }
            if (typeCode4 == typeCode1 && type3.IsEnum)
            {
                type4 = type4 == null || type4 == type3 ? type3 : (Type)null;
            }
label_18:
            LoopFor.EnumType = type4;
            try
            {
                LoopFor.Counter = ObjectType.CTypeHelper(Start, typeCode1);
            }
            catch (StackOverflowException ex)
            {
                throw ex;
            }
            catch (OutOfMemoryException ex)
            {
                throw ex;
            }
            catch (ThreadAbortException ex)
            {
                throw ex;
            }
            catch (Exception ex)
            {
                throw new ArgumentException(Utils.GetResourceString("ForLoop_ConvertToType3", nameof(Start), Utils.VBFriendlyName(type1), Utils.VBFriendlyName(ObjectType.TypeFromTypeCode(typeCode1))));
            }
            try
            {
                LoopFor.Limit = ObjectType.CTypeHelper(Limit, typeCode1);
            }
            catch (StackOverflowException ex)
            {
                throw ex;
            }
            catch (OutOfMemoryException ex)
            {
                throw ex;
            }
            catch (ThreadAbortException ex)
            {
                throw ex;
            }
            catch (Exception ex)
            {
                throw new ArgumentException(Utils.GetResourceString("ForLoop_ConvertToType3", nameof(Limit), Utils.VBFriendlyName(type2), Utils.VBFriendlyName(ObjectType.TypeFromTypeCode(typeCode1))));
            }
            try
            {
                LoopFor.StepValue = ObjectType.CTypeHelper(StepValue, typeCode1);
            }
            catch (StackOverflowException ex)
            {
                throw ex;
            }
            catch (OutOfMemoryException ex)
            {
                throw ex;
            }
            catch (ThreadAbortException ex)
            {
                throw ex;
            }
            catch (Exception ex)
            {
                throw new ArgumentException(Utils.GetResourceString("ForLoop_ConvertToType3", "Step", Utils.VBFriendlyName(type3), Utils.VBFriendlyName(ObjectType.TypeFromTypeCode(typeCode1))));
            }
            object obj = ObjectType.CTypeHelper((object)0, typeCode1);

            LoopFor.PositiveStep = ((IComparable)LoopFor.StepValue).CompareTo(obj) >= 0;
            LoopForResult        = (object)LoopFor;
            CounterResult        = LoopFor.EnumType == null ? LoopFor.Counter : Enum.ToObject(LoopFor.EnumType, LoopFor.Counter);
            return(FlowControl.CheckContinueLoop(LoopFor));
        }
Пример #2
0
        /// <summary>Increments a <see langword="For...Next" /> loop.</summary>
        /// <param name="Counter">The loop counter variable.</param>
        /// <param name="LoopObj">An object that contains verified values for loop values.</param>
        /// <param name="CounterResult">The counter value for the next loop iteration.</param>
        /// <returns>
        /// <see langword="False" /> if the loop has terminated; otherwise, <see langword="True" />.</returns>
        public static bool ForNextCheckObj(object Counter, object LoopObj, ref object CounterResult)
        {
            if (LoopObj == null)
            {
                throw ExceptionUtils.VbMakeException(92);
            }
            if (Counter == null)
            {
                throw new NullReferenceException(Utils.GetResourceString("Argument_InvalidNullValue1", new string[1]
                {
                    nameof(Counter)
                }));
            }
            FlowControl.ObjectFor LoopFor = (FlowControl.ObjectFor)LoopObj;
            TypeCode typeCode1            = ((IConvertible)Counter).GetTypeCode();
            TypeCode typeCode2            = ((IConvertible)LoopFor.StepValue).GetTypeCode();
            TypeCode typeCode3;

            if (typeCode1 == typeCode2 && typeCode1 != TypeCode.String)
            {
                typeCode3 = typeCode1;
            }
            else
            {
                typeCode3 = ObjectType.GetWidestType((object)typeCode1, typeCode2);
                if (typeCode3 == TypeCode.String)
                {
                    typeCode3 = TypeCode.Double;
                }
                TypeCode typeCode4 = TypeCode.Empty;
                if (typeCode4 == TypeCode.Object)
                {
                    throw new ArgumentException(Utils.GetResourceString("ForLoop_CommonType2", Utils.VBFriendlyName(ObjectType.TypeFromTypeCode(typeCode1)), Utils.VBFriendlyName(ObjectType.TypeFromTypeCode(typeCode2))));
                }
                try
                {
                    Counter = ObjectType.CTypeHelper(Counter, typeCode3);
                }
                catch (StackOverflowException ex)
                {
                    throw ex;
                }
                catch (OutOfMemoryException ex)
                {
                    throw ex;
                }
                catch (ThreadAbortException ex)
                {
                    throw ex;
                }
                catch (Exception ex)
                {
                    throw new ArgumentException(Utils.GetResourceString("ForLoop_ConvertToType3", "Start", Utils.VBFriendlyName(Counter.GetType()), Utils.VBFriendlyName(ObjectType.TypeFromTypeCode(typeCode3))));
                }
                try
                {
                    LoopFor.Limit = ObjectType.CTypeHelper(LoopFor.Limit, typeCode3);
                }
                catch (StackOverflowException ex)
                {
                    throw ex;
                }
                catch (OutOfMemoryException ex)
                {
                    throw ex;
                }
                catch (ThreadAbortException ex)
                {
                    throw ex;
                }
                catch (Exception ex)
                {
                    throw new ArgumentException(Utils.GetResourceString("ForLoop_ConvertToType3", "Limit", Utils.VBFriendlyName(LoopFor.Limit.GetType()), Utils.VBFriendlyName(ObjectType.TypeFromTypeCode(typeCode3))));
                }
                try
                {
                    LoopFor.StepValue = ObjectType.CTypeHelper(LoopFor.StepValue, typeCode3);
                }
                catch (StackOverflowException ex)
                {
                    throw ex;
                }
                catch (OutOfMemoryException ex)
                {
                    throw ex;
                }
                catch (ThreadAbortException ex)
                {
                    throw ex;
                }
                catch (Exception ex)
                {
                    throw new ArgumentException(Utils.GetResourceString("ForLoop_ConvertToType3", "Step", Utils.VBFriendlyName(LoopFor.StepValue.GetType()), Utils.VBFriendlyName(ObjectType.TypeFromTypeCode(typeCode3))));
                }
            }
            LoopFor.Counter = ObjectType.AddObj(Counter, LoopFor.StepValue);
            TypeCode typeCode5 = ((IConvertible)LoopFor.Counter).GetTypeCode();

            CounterResult = LoopFor.EnumType == null ? LoopFor.Counter : Enum.ToObject(LoopFor.EnumType, LoopFor.Counter);
            if (typeCode5 == typeCode3)
            {
                return(FlowControl.CheckContinueLoop(LoopFor));
            }
            LoopFor.Limit     = ObjectType.CTypeHelper(LoopFor.Limit, typeCode5);
            LoopFor.StepValue = ObjectType.CTypeHelper(LoopFor.StepValue, typeCode5);
            return(false);
        }