public abstract class FieldBase {
FieldTagAttribute fieldTagAttribute = (FieldTagAttribute) (
GetType().GetCustomAttribute(typeof(FieldTagAttribute), inherit: false)
if (fieldTagAttribute == null) {
throw new InvalidOperationException(String.Format("Class {0} has no attribute [FieldTag]. Please add the attribute to this class.", GetType()));
return fieldTagAttribute.FieldTag;
[System.AttributeUsageAttribute(System.AttributeTargets.Class, Inherited = false)]
public class FieldTagAttribute : Attribute {
public FieldTagAttribute(string fieldTag) {
public string FieldTag { get; set; }
public class Field32A : FieldBase {
public string Value{ get; set; }
public override string ToString() {
return ":" + FieldTag + ":" + Value;
public static void Main() {
Field32A field32A = new Field32A { Value = "12345" };
field32A.ToString().Dump();