You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
57 lines
1.7 KiB
57 lines
1.7 KiB
using Application.Domain.Entities;
|
|
using System.Collections.Generic;
|
|
using System.Text.Encodings.Web;
|
|
using System.Text.Json;
|
|
using System.Text.Unicode;
|
|
|
|
namespace System.ComponentModel.DataAnnotations
|
|
{
|
|
public class IoTDataConfigAttribute : Attribute
|
|
{
|
|
public IoTDataConfigAttribute(IoTDataType propType= IoTDataType.Data, IoTValueType valueType= IoTValueType.String, string unit = null, string enumValues = null,bool hide=false)
|
|
{
|
|
this.PropType = propType;
|
|
this.ValueType = valueType;
|
|
this._enumValues = enumValues;
|
|
this.Unit = unit;
|
|
this.Hide = hide;
|
|
}
|
|
|
|
public IoTDataType PropType { get; private set; }
|
|
|
|
public IoTValueType ValueType { get; private set; }
|
|
|
|
private readonly string _enumValues;
|
|
|
|
public string Unit { get; }
|
|
public bool Hide { get; }
|
|
|
|
public string GetEnumValues()
|
|
{
|
|
if (string.IsNullOrEmpty(this._enumValues))
|
|
{
|
|
return null;
|
|
}
|
|
var list = new Dictionary<string, string>();
|
|
var values = _enumValues.Split(',');
|
|
int i = 0;
|
|
foreach (var item in values)
|
|
{
|
|
var value = item;
|
|
if (item.Contains("="))
|
|
{
|
|
var kv = item.Split('=');
|
|
i = Convert.ToInt32(kv[0]);
|
|
value = kv[1];
|
|
}
|
|
list.Add(i.ToString(), value);
|
|
i++;
|
|
}
|
|
return JsonSerializer.Serialize(list, new JsonSerializerOptions
|
|
{
|
|
Encoder = JavaScriptEncoder.Create(UnicodeRanges.All)
|
|
});
|
|
}
|
|
}
|
|
}
|