init
This commit is contained in:
@@ -0,0 +1,45 @@
|
||||
using System;
|
||||
using System.ComponentModel;
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
using System.Linq;
|
||||
|
||||
namespace IRIGCh10
|
||||
{
|
||||
/// <summary>
|
||||
/// allows annotating enums with a description attribute, in chapter 10 this allows us
|
||||
/// to associate an enum with a string to put in the TMATS file for that enum
|
||||
/// </summary>
|
||||
public static class DescriptionDecoder
|
||||
{
|
||||
public static string GetDescription(Enum value)
|
||||
{
|
||||
var fi = value.GetType().GetField(value.ToString());
|
||||
var attributes = (DescriptionAttribute[])fi.GetCustomAttributes(
|
||||
typeof(DescriptionAttribute), false);
|
||||
if (attributes.Any())
|
||||
{
|
||||
return attributes.First().Description;
|
||||
}
|
||||
return value.ToString();
|
||||
}
|
||||
}
|
||||
/// <summary>
|
||||
/// a lot of attributes in chapter 10 have a max length associated with them
|
||||
/// note however though that max length in chapter 10 is just a suggested
|
||||
/// max length, not a requirement ...
|
||||
/// </summary>
|
||||
public static class MaxLengthDecoder
|
||||
{
|
||||
public static int GetMaxLength(Enum value)
|
||||
{
|
||||
var fi = value.GetType().GetField(value.ToString());
|
||||
var attributes = (MaxLengthAttribute[])fi.GetCustomAttributes(
|
||||
typeof(MaxLengthAttribute), false);
|
||||
if (attributes.Any())
|
||||
{
|
||||
return attributes.First().Length;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user