Flatwhite.WebApi.FlatwhiteStatusController.GetObjectSize C# (CSharp) Méthode

GetObjectSize() private static méthode

Calculates the lenght in bytes of an object and returns the size
private static GetObjectSize ( object obj ) : int
obj object
Résultat int
        private static int GetObjectSize(object obj)
        {
            if (obj == null)
            {
                return 0;
            }
            try
            {
                var bf = new BinaryFormatter();
                using (var ms = new MemoryStream())
                {
                    bf.Serialize(ms, obj);
                    var array = ms.ToArray();
                    return array.Length;
                }
            }
            catch (SerializationException)
            {
            }

            try
            {
                return JsonConvert.SerializeObject(obj).Length;
            }
            catch
            {
            }
            return -1;
        }