Example #1
0
		public override MetaField CloneValue()
		{
			var result = new EnumData(Name, Offset, FieldAddress, _type, _value, base.PluginLine);
			foreach (EnumValue option in Values)
			{
				var copiedValue = new EnumValue(option.Name, option.Value);
				result.Values.Add(copiedValue);
				if (_selectedValue != null && copiedValue.Value == _selectedValue.Value)
					result._selectedValue = copiedValue;
			}
			return result;
		}
Example #2
0
        public void VisitEnum(EnumData field)
        {
            SeekToOffset(field.Offset);
            switch (field.Type)
            {
                case EnumType.Enum8:
                    field.Value = _reader.ReadSByte();
                    break;
                case EnumType.Enum16:
                    field.Value = _reader.ReadInt16();
                    break;
                case EnumType.Enum32:
                    field.Value = _reader.ReadInt32();
                    break;
            }

            // Search for the corresponding option and select it
            EnumValue selected = null;
            foreach (EnumValue option in field.Values)
            {
                // Typecast the field value and the option value based upon the enum type
                switch (field.Type)
                {
                    case EnumType.Enum8:
                        if ((sbyte) option.Value == (sbyte) field.Value)
                            selected = option;
                        break;
                    case EnumType.Enum16:
                        if ((short) option.Value == (short) field.Value)
                            selected = option;
                        break;
                    case EnumType.Enum32:
                        if (option.Value == field.Value)
                            selected = option;
                        break;
                }
                if (selected != null)
                    break;
            }
            if (selected == null)
            {
                // Nothing matched, so just add an option for it
                selected = new EnumValue(field.Value.ToString(), field.Value);
                field.Values.Add(selected);
            }
            field.SelectedValue = selected;
        }