示例#1
0
 internal Usage(string unit, int currentValue, long limit, UsageName name)
 {
     Unit         = unit;
     CurrentValue = currentValue;
     Limit        = limit;
     Name         = name;
 }
        internal static Usage DeserializeUsage(JsonElement element)
        {
            string    unit         = default;
            int       currentValue = default;
            long      limit        = default;
            UsageName name         = default;

            foreach (var property in element.EnumerateObject())
            {
                if (property.NameEquals("unit"))
                {
                    unit = property.Value.GetString();
                    continue;
                }
                if (property.NameEquals("currentValue"))
                {
                    currentValue = property.Value.GetInt32();
                    continue;
                }
                if (property.NameEquals("limit"))
                {
                    limit = property.Value.GetInt64();
                    continue;
                }
                if (property.NameEquals("name"))
                {
                    name = UsageName.DeserializeUsageName(property.Value);
                    continue;
                }
            }
            return(new Usage(unit, currentValue, limit, name));
        }
示例#3
0
        internal Usage(int currentValue, long limit, UsageName name)
        {
            if (name == null)
            {
                throw new ArgumentNullException(nameof(name));
            }

            Unit         = "Count";
            CurrentValue = currentValue;
            Limit        = limit;
            Name         = name;
        }