Esempio n. 1
0
        /// <inheritdoc />
        public bool TryRecompose(object obj, Type tobj, Type trecomposed, out object recomposed)
        {
            recomposed = null;

            if (trecomposed != TComplex)
            {
                return(false);
            }

            // ie<double>
            if (TDoubleEnumerable.IsAssignableFrom(tobj) && obj is IEnumerable <double> ied)
            {
                if (ied.Count() < 2)
                {
                    return(false);
                }

                var(real, imag) = ied.FirstTwoOrDefault();
                recomposed      = new Complex(real, imag);
                return(true);
            }

            // ie<obj>
            if (TObjectEnumerable.IsAssignableFrom(tobj) && obj is IEnumerable <object> ieo)
            {
                if (ieo.Count() < 2)
                {
                    return(false);
                }

                var(real, imag) = ieo.FirstTwoOrDefault();
                if (real is not double dreal || imag is not double dimag)
                {
                    return(false);
                }

                recomposed = new Complex(dreal, dimag);
                return(true);
            }

            return(false);
        }
Esempio n. 2
0
 /// <inheritdoc />
 public bool CanRecompose(Type t)
 => t == TDoubleArray ||
 t == TObjectArray ||
 TDoubleEnumerable.IsAssignableFrom(t) ||
 TObjectEnumerable.IsAssignableFrom(t);