Beispiel #1
0
        internal TupleReadContract(Type type, ContractCollection contractCollection)
        {
            if (!TupleWriteContract.CanProcess(type))
            {
                throw new ArgumentException($"Type {type} is not a supported tuple type.", nameof(type));
            }

            Items = type.GetGenericArguments().Select(contractCollection.GetOrAddReadContract).ToList();
        }
        /// <summary>
        /// Get or create a write contract for <paramref name="type"/>.
        /// </summary>
        /// <param name="type">The type to get or create a write contract for.</param>
        /// <returns>The write contract corresponding to <paramref name="type"/>.</returns>
        public IWriteContract GetOrAddWriteContract(Type type)
        {
            if (type == typeof(Empty))
            {
                return(Intern(new EmptyContract()));
            }
            if (PrimitiveContract.CanProcess(type))
            {
                return(Intern(new PrimitiveContract(type)));
            }
            if (EnumContract.CanProcess(type))
            {
                return(Intern(new EnumContract(type)));
            }
            if (TupleWriteContract.CanProcess(type))
            {
                return(Intern(new TupleWriteContract(type, this)));
            }
            if (NullableWriteContract.CanProcess(type))
            {
                return(Intern(new NullableWriteContract(type, this)));
            }
            if (ListWriteContract.CanProcess(type))
            {
                return(Intern(new ListWriteContract(type, this)));
            }
            if (DictionaryWriteContract.CanProcess(type))
            {
                return(Intern(new DictionaryWriteContract(type, this)));
            }
            if (UnionWriteContract.CanProcess(type))
            {
                return(Intern(new UnionWriteContract(type, this)));
            }

            return(Intern(new ComplexWriteContract(type, this)));
        }
Beispiel #3
0
 internal static bool CanProcess(Type type) => TupleWriteContract.CanProcess(type);