Exemplo n.º 1
0
        public static SsslObject ConvertFrom(this ISsslConverter converter, object?value)
        {
            if (converter is null)
            {
                throw new ArgumentNullException(nameof(converter));
            }

            return(converter.TryConvertFrom(value, out var result)
                ? result
                : throw new InvalidCastException());
        }
Exemplo n.º 2
0
        public static bool TryConvertFrom(ISsslConverter converter, object value, [NotNullWhen(true)] out SsslObject result)
        {
            var type   = value.GetType();
            var obj    = new SsslRecord(SsslRecordType.Braces, type.GetFullName());
            var values = GetModelInfo(type).ConvertFrom(value);

            foreach (var(name, val) in values)
            {
                if (!converter.TryConvertFrom(val, out var ssslVal))
                {
                    result = null !;
                    return(false);
                }

                obj[name] = ssslVal;
            }

            result = obj;
            return(true);
        }