public uint GetBits <T>(int numBits, T attribute, Type enumRepresentation) { if (!CheckReadBits(numBits)) { return(0); } uint value = GetBits(numBits); if (attribute is int) { uint correctValue = (uint)(int)(object)attribute; // Add and verify the attribute FormattedAttribute <string, string> formattedAttribute = new FormattedAttribute <string, string>(GetBitString(numBits, correctValue), GetBitString(numBits, value)); formattedAttribute.Valid = (value == correctValue); AddAttribute(formattedAttribute); } else { if (Enum.IsDefined(enumRepresentation, (int)value)) { AddAttribute(new FormattedAttribute <T, string>(attribute, string.Format(CultureInfo.CurrentCulture, "{0} ({1})", Enum.GetName(enumRepresentation, value), value))); } else { AddAttribute(new FormattedAttribute <T, uint>(attribute, value)); } } return(value); }
public uint GetBits <T>(int numBits, T attribute) { if (!CheckReadBits(numBits)) { return(0); } uint value = GetBits(numBits); if (attribute is int) { uint correctValue = (uint)(int)(object)attribute; // Add and verify the attribute FormattedAttribute <string, string> formattedAttribute = new FormattedAttribute <string, string>(GetBitString(numBits, correctValue), GetBitString(numBits, value)); formattedAttribute.Valid = (value == correctValue); AddAttribute(formattedAttribute); } else { AddAttribute(new FormattedAttribute <T, uint>(attribute, value)); } return(value); }