예제 #1
0
        /// <summary>
        /// Converts an address string to the corresponding value.
        /// </summary>
        /// <param name="context">Type descriptor context.</param>
        /// <param name="culture">Globalization info.</param>
        /// <param name="value">The value being converted.</param>
        /// <returns>The converted value.</returns>
        public override Object ConvertFrom(ITypeDescriptorContext context, CultureInfo culture, Object value)
        {
            Type    valueType = null;
            Boolean isHex     = false;

            if (context.Instance.GetType().IsAssignableFrom(typeof(AddressItem)))
            {
                valueType = (context.Instance as AddressItem)?.ElementType;
            }

            if (context.Instance.GetType().IsAssignableFrom(typeof(AddressItem)))
            {
                isHex = (context.Instance as AddressItem).IsValueHex;
            }

            if (valueType == null || !value.GetType().IsAssignableFrom(typeof(String)))
            {
                return(base.ConvertFrom(context, culture, value));
            }

            if (!(isHex ? CheckSyntax.CanParseHex(valueType, value as String) : CheckSyntax.CanParseValue(valueType, value as String)))
            {
                return(base.ConvertFrom(context, culture, value));
            }

            return(isHex ? Conversions.ParseHexStringAsDynamic(valueType, value as String) : Conversions.ParsePrimitiveStringAsDynamic(valueType, value as String));
        }
예제 #2
0
        /// <summary>
        /// Initializes a new instance of the <see cref="AddressItem" /> class.
        /// </summary>
        /// <param name="baseAddress">The base address. This will be added as an offset from the resolved base identifier.</param>
        /// <param name="elementType">The data type of the value at this address.</param>
        /// <param name="description">The description of this address.</param>
        /// <param name="resolveType">The identifier type for this address item.</param>
        /// <param name="baseIdentifier">The identifier for the base address of this object.</param>
        /// <param name="offsets">The pointer offsets of this address item.</param>
        /// <param name="isValueHex">A value indicating whether the value at this address should be displayed as hex.</param>
        /// <param name="value">The value at this address. If none provided, it will be figured out later. Used here to allow immediate view updates upon creation.</param>
        public AddressItem(
            IntPtr baseAddress,
            Type elementType,
            String description = "New Address",
            AddressResolver.ResolveTypeEnum resolveType = AddressResolver.ResolveTypeEnum.Module,
            String baseIdentifier       = null,
            IEnumerable <Int32> offsets = null,
            Boolean isValueHex          = false,
            String value = null)
            : base(description)
        {
            // Bypass setters to avoid running setter code
            this.baseAddress    = baseAddress;
            this.ElementType    = elementType;
            this.resolveType    = resolveType;
            this.baseIdentifier = baseIdentifier;
            this.offsets        = offsets;
            this.isValueHex     = isValueHex;

            if (!this.isValueHex && CheckSyntax.CanParseValue(elementType, value))
            {
                this.addressValue = Conversions.ParsePrimitiveStringAsDynamic(elementType, value);
            }
            else if (this.isValueHex && CheckSyntax.CanParseHex(elementType, value))
            {
                this.addressValue = Conversions.ParseHexStringAsPrimitiveString(elementType, value);
            }
        }
예제 #3
0
        /// <summary>
        /// Invoked when the convert to decimal menu item is clicked.
        /// </summary>
        /// <param name="sender">Sending object.</param>
        /// <param name="e">Event args.</param>
        private void ConvertToDecMenuItemClick(Object sender, EventArgs e)
        {
            if (CheckSyntax.CanParseHex(this.ElementType, this.Text))
            {
                this.Text = Conversions.ParseHexStringAsPrimitiveString(this.ElementType, this.Text);
            }

            this.IsHex = false;
        }
예제 #4
0
        /// <summary>
        /// Hex string to an Int32.
        /// </summary>
        /// <param name="value">Value to be converted.</param>
        /// <param name="targetType">Type to convert to.</param>
        /// <param name="parameter">Optional conversion parameter.</param>
        /// <param name="culture">Globalization info.</param>
        /// <returns>An Int32. If conversion cannot take place, returns 0.</returns>
        public Object ConvertBack(Object value, Type targetType, Object parameter, CultureInfo culture)
        {
            if (value == null)
            {
                return(0);
            }

            if (value is String)
            {
                if (CheckSyntax.CanParseHex(typeof(Int32), value.ToString()))
                {
                    return(Conversions.ParseHexStringAsDynamic(typeof(Int32), value.ToString()));
                }
            }

            return(0);
        }
예제 #5
0
        /// <summary>
        /// Initializes a new instance of the <see cref="AddressItem" /> class.
        /// </summary>
        /// <param name="baseAddress">The base address. This will be added as an offset from the resolved base identifier.</param>
        /// <param name="dataType">The data type of the value at this address.</param>
        /// <param name="description">The description of this address.</param>
        /// <param name="baseIdentifier">The identifier for the base address of this object.</param>
        /// <param name="offsets">The pointer offsets of this address item.</param>
        /// <param name="isValueHex">A value indicating whether the value at this address should be displayed as hex.</param>
        /// <param name="value">The value at this address. If none provided, it will be figured out later. Used here to allow immediate view updates upon creation.</param>
        public AddressItem(
            Type dataType,
            String description = "New Address",
            Boolean isValueHex = false,
            String value       = null)
            : base(description)
        {
            // Bypass setters to avoid running setter code
            this.dataType   = dataType;
            this.isValueHex = isValueHex;

            if (!this.isValueHex && CheckSyntax.CanParseValue(dataType, value))
            {
                this.addressValue = Conversions.ParsePrimitiveStringAsPrimitive(dataType, value);
            }
            else if (this.isValueHex && CheckSyntax.CanParseHex(dataType, value))
            {
                this.addressValue = Conversions.ParseHexStringAsPrimitiveString(dataType, value);
            }
        }
예제 #6
0
        /// <summary>
        /// Determines if the current text is valid for the current data type.
        /// </summary>
        private void UpdateValidity()
        {
            if (this.IsHex)
            {
                if (CheckSyntax.CanParseHex(this.ElementType, this.Text))
                {
                    this.IsTextValid = true;
                    return;
                }
            }
            else
            {
                if (CheckSyntax.CanParseValue(this.ElementType, this.Text))
                {
                    this.IsTextValid = true;
                    return;
                }
            }

            this.IsTextValid = false;
            return;
        }