Exemplo n.º 1
0
 protected internal StackItem Convert(object value)
 {
     return(value switch
     {
         null => StackItem.Null,
         bool b => b,
         sbyte i => i,
         byte i => (BigInteger)i,
         short i => i,
         ushort i => (BigInteger)i,
         int i => i,
         uint i => i,
         long i => i,
         ulong i => i,
         Enum e => Convert(System.Convert.ChangeType(e, e.GetTypeCode())),
         byte[] data => data,
         string s => s,
         BigInteger i => i,
         IInteroperable interoperable => interoperable.ToStackItem(ReferenceCounter),
         ISerializable i => i.ToArray(),
         StackItem item => item,
         (object a, object b) => new Struct(ReferenceCounter)
         {
             Convert(a), Convert(b)
         },
         Array array => new VMArray(ReferenceCounter, array.OfType <object>().Select(p => Convert(p))),
         _ => StackItem.FromInterface(value)
     });
Exemplo n.º 2
0
 private StackItem ConvertReturnValue(object value)
 {
     return(value switch
     {
         null => StackItem.Null,
         bool b => b,
         sbyte i => i,
         byte i => (BigInteger)i,
         short i => i,
         ushort i => (BigInteger)i,
         int i => i,
         uint i => i,
         long i => i,
         ulong i => i,
         Enum e => ConvertReturnValue(Convert.ChangeType(e, e.GetTypeCode())),
         byte[] data => data,
         string s => s,
         UInt160 i => i.ToArray(),
         UInt256 i => i.ToArray(),
         IInteroperable interoperable => interoperable.ToStackItem(ReferenceCounter),
         IInteroperable[] array => new VMArray(ReferenceCounter, array.Select(p => p.ToStackItem(ReferenceCounter))),
         StackItem item => item,
         _ => StackItem.FromInterface(value)
     });