using System; using System.Collections.Generic; using System.Linq; using System.Threading.Tasks; namespace JsonRPC4.Router { public class RpcParameters { public object Value { get; } public bool IsDictionary { get; } public Dictionary AsDictionary { get { CheckValue(isDictionary: true); return (Dictionary)Value; } } public List AsList { get { CheckValue(isDictionary: false); return (List)Value; } } public RpcParameters(Dictionary parameters) { Value = (parameters ?? throw new ArgumentNullException("parameters")); IsDictionary = true; } public RpcParameters(List parameters) { Value = (parameters ?? throw new ArgumentNullException("parameters")); IsDictionary = false; } public RpcParameters(params IRpcParameter[] parameters) { Value = (parameters?.ToList() ?? throw new ArgumentNullException("parameters")); IsDictionary = false; } private void CheckValue(bool isDictionary) { if (isDictionary != IsDictionary) { throw new InvalidOperationException(); } } } }