public override string ToString() { switch(FieldType) { case FieldType.String: case FieldType.Time: if (!FieldLength.HasValue) throw new Exception("必须指定字段长度"); return StringValue.PadRight(FieldLength.Value); case FieldType.Int: if (!FieldLength.HasValue) throw new Exception("必须指定字段长度"); if (!IntValue.HasValue) throw new Exception("必须指定字段值"); return IntValue.ToString().PadRight(FieldLength.Value , '0'); case FieldType.Decimal: if (!FieldLength.HasValue || !DecimalLength.HasValue) throw new Exception("必须指定字段长度"); if (!DecimalValue.HasValue) throw new Exception("必须指定字段值"); string format = "{0:" + 0.ToString().PadLeft(FieldLength.Value - DecimalLength.Value, '0') + "." + 0.ToString().PadRight(DecimalLength.Value, '0') + "}"; string ret = string.Format(format, DecimalValue); if (DecimalValue.Value < 0) ret = "-" + ret; else ret = "+" + ret; return ret ; case FieldType.Date: if (!DateValue.HasValue) throw new Exception("必须指定字段值"); if (DateValue.Value == DateTime.Parse("1900-01-01")) return "".PadLeft(FieldLength.Value); return DateValue.Value.ToString("MM/dd/yyyy"); default: throw new Exception("未知的字段类型"); } }