Exemplo n.º 1
0
        public string NonGenericEnums_AsString_Decimal()
        {
            string result = null;

            foreach (var value in _values)
            {
                result = NonGenericEnums.AsString(_enumType, value, EnumFormat.DecimalValue);
            }
            return(result);
        }
Exemplo n.º 2
0
        public string NonGenericEnums_AsString_Name()
        {
            string result = null;

            foreach (var value in _values)
            {
                result = NonGenericEnums.AsString(_enumType, value);
            }
            return(result);
        }
Exemplo n.º 3
0
 public override void WriteJson(JsonWriter writer, object value, JsonSerializer serializer)
 {
     if (value == null)
     {
         writer.WriteNull();
     }
     else
     {
         var enumType = value.GetType();
         if (EnumFormat != EnumFormat.DecimalValue)
         {
             var member = NonGenericEnums.GetMember(enumType, value);
             if (member != null)
             {
                 writer.WriteValue(member.AsString(EnumFormat));
                 return;
             }
         }
         writer.WriteRawValue(NonGenericEnums.AsString(enumType, value, EnumFormat.DecimalValue));
     }
 }
Exemplo n.º 4
0
        public static void ToString(DayOfWeek[] dayOfWeekArray)
        {
            const int iterations = 50000;

            using (new OperationTimer("Enum.ToString (Name)"))
            {
                for (var i = 0; i < (iterations << 1); ++i)
                {
                    for (var j = 0; j < 7; ++j)
                    {
                        dayOfWeekArray[j].ToString();
                    }
                }
            }

            var dayOfWeekType = typeof(DayOfWeek);

            using (new OperationTimer("NonGenericEnums.AsString (Name)"))
            {
                for (var i = 0; i < (iterations << 1); ++i)
                {
                    for (var j = 0; j < 7; ++j)
                    {
                        NonGenericEnums.AsString(dayOfWeekType, dayOfWeekArray[j]);
                    }
                }
            }

            using (new OperationTimer("Enums.AsString (Name)"))
            {
                for (var i = 0; i < (iterations << 1); ++i)
                {
                    for (var j = 0; j < 7; ++j)
                    {
                        dayOfWeekArray[j].AsString();
                    }
                }
            }

            using (new OperationTimer("Enum.ToString (Decimal)"))
            {
                for (var i = 0; i < iterations; ++i)
                {
                    for (var j = 0; j < dayOfWeekArray.Length; ++j)
                    {
                        dayOfWeekArray[j].ToString("D");
                    }
                }
            }

            using (new OperationTimer("NonGenericEnums.AsString (Decimal)"))
            {
                for (var i = 0; i < iterations; ++i)
                {
                    for (var j = 0; j < dayOfWeekArray.Length; ++j)
                    {
                        NonGenericEnums.AsString(dayOfWeekType, dayOfWeekArray[j], EnumFormat.DecimalValue);
                    }
                }
            }

            using (new OperationTimer("Enums.AsString (Decimal)"))
            {
                for (var i = 0; i < iterations; ++i)
                {
                    for (var j = 0; j < dayOfWeekArray.Length; ++j)
                    {
                        dayOfWeekArray[j].AsString(EnumFormat.DecimalValue);
                    }
                }
            }
        }