Exemplo n.º 1
0
        public static bool _ConvertFrom_System_ComponentModel_EnumConverter_System_ComponentModel_ITypeDescriptorContext_System_Globalization_CultureInfo_System_Object( )
        {
            //class object
            System.ComponentModel.EnumConverter _System_ComponentModel_EnumConverter = new System.ComponentModel.EnumConverter();

            //Parameters
            System.ComponentModel.ITypeDescriptorContext context = null;
            System.Globalization.CultureInfo             culture = null;
            System.Object _value = null;

            //ReturnType/Value
            System.Object returnVal_Real        = null;
            System.Object returnVal_Intercepted = null;

            //Exception
            System.Exception exception_Real        = null;
            System.Exception exception_Intercepted = null;

            InterceptionMaintenance.disableInterception( );

            try
            {
                returnVal_Real = _System_ComponentModel_EnumConverter.ConvertFrom(context, culture, _value);
            }

            catch (System.Exception e)
            {
                exception_Real = e;
            }


            InterceptionMaintenance.enableInterception( );

            try
            {
                returnVal_Intercepted = _System_ComponentModel_EnumConverter.ConvertFrom(context, culture, _value);
            }

            catch (System.Exception e)
            {
                exception_Intercepted = e;
            }


            return((exception_Real.Messsage == exception_Intercepted.Message) && (returnValue_Real == returnValue_Intercepted));
        }
        public static bool _ConvertFrom_System_ComponentModel_EnumConverter_System_ComponentModel_ITypeDescriptorContext_System_Globalization_CultureInfo_System_Object( )
        {
            //class object
            System.ComponentModel.EnumConverter _System_ComponentModel_EnumConverter = new System.ComponentModel.EnumConverter();

               //Parameters
               System.ComponentModel.ITypeDescriptorContext context = null;
               System.Globalization.CultureInfo culture = null;
               System.Object _value = null;

               //ReturnType/Value
               System.Object returnVal_Real = null;
               System.Object returnVal_Intercepted = null;

               //Exception
               System.Exception exception_Real = null;
               System.Exception exception_Intercepted = null;

               InterceptionMaintenance.disableInterception( );

               try
               {
              returnVal_Real = _System_ComponentModel_EnumConverter.ConvertFrom(context,culture,_value);
               }

               catch( System.Exception e )
               {
              exception_Real = e;
               }

               InterceptionMaintenance.enableInterception( );

               try
               {
              returnVal_Intercepted = _System_ComponentModel_EnumConverter.ConvertFrom(context,culture,_value);
               }

               catch( System.Exception e )
               {
              exception_Intercepted = e;
               }

               return( ( exception_Real.Messsage == exception_Intercepted.Message ) && ( returnValue_Real == returnValue_Intercepted ) );
        }
Exemplo n.º 3
0
        public static object Convert(object value, Type conversionType)
        {
            if ((value == null) || (conversionType.IsAssignableFrom(value.GetType())))
            {
                return(value);
            }
            if (value is string)
            {
                string str = (string)value;
                if (str.Trim() == "")
                {
                    return(null);
                }
                if (str.Trim() == "null")
                {
                    return(null);
                }
                if (conversionType == typeof(bool))
                {
                    if ((str.ToLower() != "true") && (str.ToLower() != "false"))
                    {
                        throw new Exception(str + " не конвертится в Boolean");
                    }
                }
            }
            if (conversionType.IsEnum)
            {
                System.ComponentModel.EnumConverter converter = new System.ComponentModel.EnumConverter(conversionType);
                return(converter.ConvertFrom(value));
            }
            IConvertible convertible = value as IConvertible;

            if (convertible == null)
            {
                throw new Exception("Тип " + value.GetType().ToString() + " не является конвертируемым.");
            }
            object res = null;

            res = convertible.ToType(conversionType, null);
            return(res);
        }