12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364 |
- 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<string, IRpcParameter> AsDictionary
- {
- get
- {
- CheckValue(isDictionary: true);
- return (Dictionary<string, IRpcParameter>)Value;
- }
- }
- public List<IRpcParameter> AsList
- {
- get
- {
- CheckValue(isDictionary: false);
- return (List<IRpcParameter>)Value;
- }
- }
- public RpcParameters(Dictionary<string, IRpcParameter> parameters)
- {
- Value = (parameters ?? throw new ArgumentNullException("parameters"));
- IsDictionary = true;
- }
- public RpcParameters(List<IRpcParameter> 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();
- }
- }
- }
- }
|