예제 #1
0
        public static Modification From(ClientRegisterModification m)
        {
            var res = new Modification
            {
                CustomMaxLength = Math.Max(m.MaxLength ?? 120, 120),
                CustomMinLength = 0,
                Enabled         = false,
            };

            if (m.Options != null)
            {
                res.Options = m.Options.ToDictionary(o => o.Id, o => o.Default.Bool as object ?? o.Default.Double as object ?? o.Default.String);
            }

            return(res);
        }
예제 #2
0
        /// <summary>
        /// Returns itself.
        /// </summary>
        public Modification UpdateFrom(ClientRegisterModification msg)
        {
            Tooltip = Tooltip ?? msg.Tooltip;

            if (msg.MaxLength != null)
            {
                CustomMaxLength = Math.Min(CustomMaxLength, (decimal)msg.MaxLength);
                CustomMinLength = Math.Min(CustomMinLength, CustomMaxLength);
            }

            if (msg.Options == null)
            {
                Options.Clear();
            }
            else
            {
                Options = msg.Options.ToDictionary(o => o.Id, o =>
                {
                    if (Options.TryGetValue(o.Id, out var val))
                    {
                        switch (o.NumType)
                        {
                        case null:
                            // boolean or string
                            if (o.Default.Bool != null && val is bool)
                            {
                                return(val);
                            }

                            if (o.Default.String != null && val is string)
                            {
                                return(val);
                            }

                            break;

                        case NumType.Double when val is decimal:
                            return(val);