You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@ignite.apache.org by GitBox <gi...@apache.org> on 2020/08/04 18:52:37 UTC

[GitHub] [ignite] gurustron commented on a change in pull request #8110: IGNITE-13293 .NET: Fix enum serialization performance

gurustron commented on a change in pull request #8110:
URL: https://github.com/apache/ignite/pull/8110#discussion_r465259710



##########
File path: modules/platforms/dotnet/Apache.Ignite.Core/Impl/Binary/BinaryUtils.cs
##########
@@ -1749,6 +1753,76 @@ public static TimeSpan LongToTimeSpan(long ms)
 
             return TimeSpan.FromMilliseconds(ms);
         }
+        
+        /// <summary>
+        /// Gets the enum values.
+        /// </summary>
+        public static IDictionary<string, int> GetEnumValues(Type enumType)
+        {
+            Debug.Assert(enumType != null);
+            Debug.Assert(enumType.IsEnum);
+            
+            Dictionary<string,int> res;
+            if (EnumValues.TryGetValue(enumType, out res))
+            {
+                return res;
+            }
+
+            var values = Enum.GetValues(enumType);
+            res = new Dictionary<string, int>(values.Length);
+
+            var underlyingType = Enum.GetUnderlyingType(enumType);
+
+            foreach (var value in values)
+            {
+                var name = Enum.GetName(enumType, value);
+                Debug.Assert(name != null);
+
+                res[name] = GetEnumValueAsInt(underlyingType, value);
+            }
+
+            EnumValues.Set(enumType, res);
+            
+            return res;
+        }
+        
+        /// <summary>
+        /// Gets the enum value as int.
+        /// </summary>
+        private static int GetEnumValueAsInt(Type underlyingType, object value)

Review comment:
       Should we support long?




----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org