46 lines
1.3 KiB
C#
46 lines
1.3 KiB
C#
using System;
|
|
using System.Linq;
|
|
using System.Runtime.CompilerServices;
|
|
using LeafWeb.Core.Utility;
|
|
|
|
namespace LeafWeb.Core.Services
|
|
{
|
|
[AttributeUsage(AttributeTargets.Property, AllowMultiple = false, Inherited = true)]
|
|
public class ParseInfoAttribute : Attribute
|
|
{
|
|
public int Position { get; private set; }
|
|
public string Units { get; private set; }
|
|
public string Title { get; private set; }
|
|
public string AlterateTitle { get; private set; }
|
|
public string ExampleValue { get; private set; }
|
|
public string[] FieldNames
|
|
{
|
|
get
|
|
{
|
|
var fieldNames = new[] {Title, Title.SplitCamelCase()};
|
|
if (!string.IsNullOrEmpty(AlterateTitle))
|
|
fieldNames = fieldNames.Concat(new[] { AlterateTitle }).ToArray();
|
|
return fieldNames;
|
|
}
|
|
}
|
|
|
|
public ParseInfoAttribute(int position, [CallerMemberName]string title = null, string units = null, string alternateTitle = null, string exampleValue = null)
|
|
{
|
|
AlterateTitle = alternateTitle;
|
|
ExampleValue = exampleValue;
|
|
Title = title;
|
|
Position = position;
|
|
Units = units;
|
|
}
|
|
|
|
public bool IsTitleMatch(string title)
|
|
{
|
|
return FieldNames.Any(t => string.Compare(title, t, StringComparison.InvariantCultureIgnoreCase) == 0);
|
|
}
|
|
|
|
public bool IsPositionMatch(int index)
|
|
{
|
|
return Position == index;
|
|
}
|
|
}
|
|
} |