Пример #1
0
        public Property(PropertyId id, PropertyType type)
        {
            if (id == null)
            {
                throw new ArgumentNullException(nameof(id));
            }

            Id   = id;
            Type = type;
        }
Пример #2
0
        public SimpleSendV0(BitcoinAddress sender, BitcoinAddress receiver, PropertyId property, PropertyAmount amount)
            : base(sender, receiver)
        {
            if (sender == null)
            {
                throw new ArgumentNullException(nameof(sender));
            }

            if (property == null)
            {
                throw new ArgumentNullException(nameof(property));
            }

            if (amount <= PropertyAmount.Zero)
            {
                throw new ArgumentOutOfRangeException(nameof(amount), amount, "The value is less than one.");
            }

            Property = property;
            Amount   = amount;
        }
Пример #3
0
        public override object ConvertFrom(ITypeDescriptorContext context, CultureInfo culture, object value)
        {
            // Normalize value.
            switch (value)
            {
            case int i:
                value = (long)i;
                break;
            }

            // Convert.
            if (value is string s)
            {
                try
                {
                    return(PropertyId.Parse(s));
                }
                catch (FormatException ex)
                {
                    throw new NotSupportedException($"Cannot convert {s} to {typeof(PropertyId)}.", ex);
                }
            }
            else if (value is long n)
            {
                try
                {
                    return(new PropertyId(n));
                }
                catch (ArgumentOutOfRangeException ex)
                {
                    throw new NotSupportedException($"Cannot convert {n} to {typeof(PropertyId)}.", ex);
                }
            }
            else
            {
                throw new NotSupportedException(
                          $"Don't know how to convert {value.GetType()} to {typeof(PropertyId)}."
                          );
            }
        }
Пример #4
0
        /// <summary>
        /// Write a <see cref="PropertyId"/> to <paramref name="writer"/>.
        /// </summary>
        protected static void EncodePropertyId(BinaryWriter writer, PropertyId id)
        {
            var value = IPAddress.HostToNetworkOrder((int)id.Value);

            writer.Write(value);
        }