Exemplo n.º 1
0
 static Converter()
 {
     BoolConverter.Initialize();
     CharConverter.Initialize();
     ByteConverter.Initialize();
     SByteConverter.Initialize();
     Int16Converter.Initialize();
     UInt16Converter.Initialize();
     Int32Converter.Initialize();
     UInt32Converter.Initialize();
     Int64Converter.Initialize();
     UInt64Converter.Initialize();
     SingleConverter.Initialize();
     DoubleConverter.Initialize();
     DecimalConverter.Initialize();
     BigIntegerConverter.Initialize();
     BytesConverter.Initialize();
     CharsConverter.Initialize();
     StringConverter.Initialize();
     StringBuilderConverter.Initialize();
     DateTimeConverter.Initialize();
     TimeSpanConverter.Initialize();
     GuidConverter.Initialize();
     MemoryStreamConverter.Initialize();
     StreamConverter.Initialize();
 }
Exemplo n.º 2
0
        public void PropertiesTest()
        {
            var converter = new UInt64Converter();

            Assert.AreEqual(true, converter.AcceptsNativeType);
            Assert.AreEqual(typeof(ulong), converter.ConvertedType);
        }
Exemplo n.º 3
0
        private static void ConfigureServices(this IServiceCollection services)
        {
            // Line because optimazation is eating everything?
            _ = new JwtHeader();
            _ = new JwtPayload();
            _ = new UInt64Converter();

#if DEBUG
            const string apiUrl = "https://localhost:44329/";
#else
            const string apiUrl = "https://tranquiliza.dynu.net/AntiHarassmentApi/";
#endif
            services.AddSingleton <IApplicationState, ApplicationState>();
            services.AddSingleton <IApplicationStateManager, ApplicationStateManager>();
            services.AddSingleton <IAdminChannelService, AdminChannelService>();
            services.AddSingleton <IUserChannelService, UserChannelService>();
            services.AddSingleton <IUserService, UserService>();
            services.AddSingleton <ISuspensionService, SuspensionService>();
            services.AddSingleton <ITagService, TagService>();
            services.AddSingleton <IUserReportService, UserReportService>();
            services.AddSingleton <IChannelStatisticsService, ChannelStatisticsService>();
            services.AddSingleton <ISystemReportService, SystemReportService>();
            services.AddSingleton <IUnconfirmedSourceSuspensionService, UnconfirmedSourceSuspensionService>();

            services.AddSingleton(_ => new ChannelsHubSignalRClient(apiUrl));
            services.AddSingleton(_ => new SuspensionsHubSignalRClient(apiUrl));
            services.AddSingleton(_ => new NotificationHubSignalRClient(apiUrl));
            services.AddSingleton <IApiGateway, ApiGateway>(x => new ApiGateway(apiUrl, x.GetRequiredService <IApplicationStateManager>(), x.GetRequiredService <HttpClient>(), x.GetRequiredService <IJSRuntime>()));
        }
Exemplo n.º 4
0
        /// <summary>
        /// Extends ConvertTo so that methods that return a specific type object given a Type parameter can be
        /// used as generic method and casting is not required.
        /// <example>
        /// typeconverter.ConvertTo&lt;int&gt;(value);
        /// </example>
        /// </summary>
        public static T ConvertTo <T>(this UInt64Converter typeconverter, Object value)
        {
            if (typeconverter == null)
            {
                throw new ArgumentNullException("typeconverter");
            }

            return((T)typeconverter.ConvertTo(value, typeof(T)));
        }
Exemplo n.º 5
0
        /// <summary>
        /// Extends ConvertTo so that methods that return a specific type object given a Type parameter can be
        /// used as generic method and casting is not required.
        /// <example>
        /// basenumberconverter.ConvertTo&lt;int&gt;(context, culture, value);
        /// </example>
        /// </summary>
        public static T ConvertTo <T>(this UInt64Converter basenumberconverter, ITypeDescriptorContext context, System.Globalization.CultureInfo culture, Object value)
        {
            if (basenumberconverter == null)
            {
                throw new ArgumentNullException("basenumberconverter");
            }

            return((T)basenumberconverter.ConvertTo(context, culture, value, typeof(T)));
        }
Exemplo n.º 6
0
        private JsonFxAOT()
        {
            TypeConverter c;

            c          = new ArrayConverter();
            m_fakeFlag = c.Equals(c);
            //c = new BaseNumberConverter();
            //m_fakeFlag = c.Equals(c);
            c          = new BooleanConverter();
            m_fakeFlag = c.Equals(c);
            c          = new ByteConverter();
            m_fakeFlag = c.Equals(c);
            c          = new CollectionConverter();
            m_fakeFlag = c.Equals(c);
            c          = new ComponentConverter(typeof(int));
            m_fakeFlag = c.Equals(c);
            c          = new CultureInfoConverter();
            m_fakeFlag = c.Equals(c);
            c          = new DateTimeConverter();
            m_fakeFlag = c.Equals(c);
            c          = new DecimalConverter();
            m_fakeFlag = c.Equals(c);
            c          = new DoubleConverter();
            m_fakeFlag = c.Equals(c);
            c          = new EnumConverter(typeof(int));
            m_fakeFlag = c.Equals(c);
            c          = new ExpandableObjectConverter();
            m_fakeFlag = c.Equals(c);
            c          = new Int16Converter();
            m_fakeFlag = c.Equals(c);
            c          = new Int32Converter();
            m_fakeFlag = c.Equals(c);
            c          = new Int64Converter();
            m_fakeFlag = c.Equals(c);
            c          = new NullableConverter(typeof(object));
            m_fakeFlag = c.Equals(c);
            c          = new SByteConverter();
            m_fakeFlag = c.Equals(c);
            c          = new SingleConverter();
            m_fakeFlag = c.Equals(c);
            c          = new StringConverter();
            m_fakeFlag = c.Equals(c);
            c          = new TimeSpanConverter();
            m_fakeFlag = c.Equals(c);
            c          = new UInt16Converter();
            m_fakeFlag = c.Equals(c);
            c          = new UInt32Converter();
            m_fakeFlag = c.Equals(c);
            c          = new UInt64Converter();
            m_fakeFlag = c.Equals(c);
        }
        /// <summary>
        /// Tries to parse a 64-bit unsigned integer from a string. This method should handle hexadecimal values
        /// as well as normal values.
        /// </summary>
        /// <param name="value">The string value to parse.</param>
        /// <param name="result">The parsed integer, if the string was valid. If invalid, this
        /// will be the default integer value.</param>
        /// <returns>True if the conversion was successful; otherwise returns false.</returns>
        public static bool TryParseEx(string value, out ulong result)
        {
            bool canConvert = true;

            try
            {
                var converter = new UInt64Converter();
                result = (ulong)converter.ConvertFromString(value);
            }
            catch (Exception)
            {
                result     = default(ulong);
                canConvert = false;
            }

            return(canConvert);
        }
Exemplo n.º 8
0
        public void ConvertFromExcelTest()
        {
            var converter            = new UInt64Converter();
            var typeConverterOptions = new TypeConverterOptions {
                CultureInfo = CultureInfo.CurrentCulture
            };

            Assert.AreEqual((ulong)123, converter.ConvertFromExcel(typeConverterOptions, (double)123));
            Assert.AreEqual((ulong)123, converter.ConvertFromExcel(typeConverterOptions, "123"));
            Assert.AreEqual((ulong)123, converter.ConvertFromExcel(typeConverterOptions, " 123 "));
            Assert.AreEqual((ulong)0, converter.ConvertFromExcel(typeConverterOptions, null));

            typeConverterOptions.NumberStyle = NumberStyles.HexNumber;
            Assert.AreEqual((ulong)0x123, converter.ConvertFromExcel(typeConverterOptions, "123"));

            try {
                converter.ConvertFromExcel(typeConverterOptions, "");
                Assert.Fail();
            } catch (ExcelTypeConverterException) {
            }
        }
Exemplo n.º 9
0
 public void SetUp()
 {
     converter = new UInt64Converter();
 }
Exemplo n.º 10
0
        internal static TypeConverter GetCoreConverterFromCustomType(Type type)
        {
            TypeConverter result = null;

            if (type.IsEnum)
            {
                result = new EnumConverter(type);
            }
            else if (typeof(int).IsAssignableFrom(type))
            {
                result = new Int32Converter();
            }
            else if (typeof(short).IsAssignableFrom(type))
            {
                result = new Int16Converter();
            }
            else if (typeof(long).IsAssignableFrom(type))
            {
                result = new Int64Converter();
            }
            else if (typeof(uint).IsAssignableFrom(type))
            {
                result = new UInt32Converter();
            }
            else if (typeof(ushort).IsAssignableFrom(type))
            {
                result = new UInt16Converter();
            }
            else if (typeof(ulong).IsAssignableFrom(type))
            {
                result = new UInt64Converter();
            }
            else if (typeof(bool).IsAssignableFrom(type))
            {
                result = new BooleanConverter();
            }
            else if (typeof(double).IsAssignableFrom(type))
            {
                result = new DoubleConverter();
            }
            else if (typeof(float).IsAssignableFrom(type))
            {
                result = new SingleConverter();
            }
            else if (typeof(byte).IsAssignableFrom(type))
            {
                result = new ByteConverter();
            }
            else if (typeof(sbyte).IsAssignableFrom(type))
            {
                result = new SByteConverter();
            }
            else if (typeof(char).IsAssignableFrom(type))
            {
                result = new CharConverter();
            }
            else if (typeof(decimal).IsAssignableFrom(type))
            {
                result = new DecimalConverter();
            }
            else if (typeof(TimeSpan).IsAssignableFrom(type))
            {
                result = new TimeSpanConverter();
            }
            else if (typeof(Guid).IsAssignableFrom(type))
            {
                result = new GuidConverter();
            }
            else if (typeof(string).IsAssignableFrom(type))
            {
                result = new StringConverter();
            }
            else if (typeof(CultureInfo).IsAssignableFrom(type))
            {
                result = new CultureInfoConverter();
            }
            else if (typeof(Type).IsAssignableFrom(type))
            {
                result = new TypeTypeConverter();
            }
            else if (typeof(DateTime).IsAssignableFrom(type))
            {
                result = new DateTimeConverter2();
            }
            return(result);
        }
Exemplo n.º 11
0
        private static TypeConverter GetCoreConverterFromCoreType(Type type)
        {
            TypeConverter result = null;

            if (type == typeof(int))
            {
                result = new Int32Converter();
            }
            else if (type == typeof(short))
            {
                result = new Int16Converter();
            }
            else if (type == typeof(long))
            {
                result = new Int64Converter();
            }
            else if (type == typeof(uint))
            {
                result = new UInt32Converter();
            }
            else if (type == typeof(ushort))
            {
                result = new UInt16Converter();
            }
            else if (type == typeof(ulong))
            {
                result = new UInt64Converter();
            }
            else if (type == typeof(bool))
            {
                result = new BooleanConverter();
            }
            else if (type == typeof(double))
            {
                result = new DoubleConverter();
            }
            else if (type == typeof(float))
            {
                result = new SingleConverter();
            }
            else if (type == typeof(byte))
            {
                result = new ByteConverter();
            }
            else if (type == typeof(sbyte))
            {
                result = new SByteConverter();
            }
            else if (type == typeof(char))
            {
                result = new CharConverter();
            }
            else if (type == typeof(decimal))
            {
                result = new DecimalConverter();
            }
            else if (type == typeof(TimeSpan))
            {
                result = new TimeSpanConverter();
            }
            else if (type == typeof(Guid))
            {
                result = new GuidConverter();
            }
            else if (type == typeof(string))
            {
                result = new StringConverter();
            }
            else if (type == typeof(CultureInfo))
            {
                result = new CultureInfoConverter();
            }
            else if (type == typeof(Type))
            {
                result = new TypeTypeConverter();
            }
            else if (type == typeof(DateTime))
            {
                result = new DateTimeConverter2();
            }
            else if (ReflectionHelper.IsNullableType(type))
            {
                result = new NullableConverter(type);
            }
            return(result);
        }