CntrlComparison parsing
This commit is contained in:
@@ -0,0 +1,45 @@
|
||||
using System;
|
||||
using System.Linq;
|
||||
using System.Runtime.CompilerServices;
|
||||
|
||||
namespace LeafWeb.Core.Utility
|
||||
{
|
||||
[AttributeUsage(AttributeTargets.Property)]
|
||||
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;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user