Example #1
0
 private BinaryTreeElement InnerHandleLeaf(object leaf, PathSet paths)
 {
     if (leaf is null)
     {
         return(this.HandlePrimitiveLeaf(leaf, paths));
     }
     else if (leaf is byte[])
     {
         return(this.HandlePrimitiveLeaf(leaf, paths));
     }
     else if (leaf is string)
     {
         return(this.HandlePrimitiveLeaf(leaf, paths));
     }
     else if (PostchainUtil.IsNumericType(leaf))
     {
         return(this.HandlePrimitiveLeaf(leaf, paths));
     }
     else if (leaf is object[])
     {
         return(this.BuildFromArray((object[])leaf, paths));
     }
     else if (leaf is Dictionary <string, object> )
     {
         return(this.BuildFromDictionary((Dictionary <string, object>)leaf, paths));
     }
     else
     {
         throw new System.Exception("Unsupporting data type: " + leaf.GetType());
     }
 }
Example #2
0
        public static GTXValue ArgToGTXValue(object arg)
        {
            var gtxValue = new GTXValue();

            if (arg is null)
            {
                gtxValue.Choice = GTXValueChoice.Null;
            }
            else if (PostchainUtil.IsNumericType(arg))
            {
                try
                {
                    gtxValue.Choice  = GTXValueChoice.Integer;
                    gtxValue.Integer = Convert.ToInt64(arg);
                }
                catch
                {
                    throw new System.Exception("Chromia.PostchainClient.GTX Gtx.ArgToGTXValue() Integer overflow.");
                }
            }
            else if (arg is byte[])
            {
                gtxValue.Choice    = GTXValueChoice.ByteArray;
                gtxValue.ByteArray = (byte[])arg;
            }
            else if (arg is string)
            {
                gtxValue.Choice = GTXValueChoice.String;
                gtxValue.String = (string)arg;
            }
            else if (arg is object[])
            {
                var array = (object[])arg;
                gtxValue.Choice = GTXValueChoice.Array;

                gtxValue.Array = new List <GTXValue>();
                foreach (var subArg in array)
                {
                    gtxValue.Array.Add(ArgToGTXValue((object)subArg));
                }
            }
            else if (arg is Dictionary <string, object> )
            {
                gtxValue.Choice = GTXValueChoice.Dict;

                var dict = (Dictionary <string, object>)arg;

                gtxValue.Dict = new List <DictPair>();
                foreach (var dictPair in dict)
                {
                    gtxValue.Dict.Add(new DictPair(dictPair.Key, ArgToGTXValue(dictPair.Value)));
                }
            }
            else if (arg is Operation)
            {
                return(((Operation)arg).ToGtxValue());
            }
            else
            {
                throw new System.Exception("Chromia.PostchainClient.GTX Gtx.ArgToGTXValue() Can't create GTXValue out of type " + arg.GetType());
            }


            return(gtxValue);
        }