first commit -push
This commit is contained in:
43
RobotNet.MapShares/MapManagerExtensions.cs
Normal file
43
RobotNet.MapShares/MapManagerExtensions.cs
Normal file
@@ -0,0 +1,43 @@
|
||||
using RobotNet.MapShares.Property;
|
||||
using RobotNet.Script.Expressions;
|
||||
|
||||
namespace RobotNet.MapShares;
|
||||
|
||||
public static class MapManagerExtensions
|
||||
{
|
||||
public static Script.Expressions.ElementProperties GetElementProperties(bool isOpen, string content)
|
||||
{
|
||||
var dbool = new Dictionary<string, bool>();
|
||||
var ddouble = new Dictionary<string, double>();
|
||||
var dint = new Dictionary<string, int>();
|
||||
var dstr = new Dictionary<string, string>();
|
||||
|
||||
var elementProperties = System.Text.Json.JsonSerializer.Deserialize<ElementProperty[]>(content, JsonOptionExtends.Read) ?? [];
|
||||
|
||||
foreach (var ep in elementProperties)
|
||||
{
|
||||
if(ep.Type == "System.Boolean" || ep.Type == "Boolean")
|
||||
{
|
||||
dbool.Add(ep.Name, bool.Parse(ep.DefaultValue));
|
||||
}
|
||||
else if(ep.Type == "System.Double" || ep.Type == "Double")
|
||||
{
|
||||
ddouble.Add(ep.Name, double.Parse(ep.DefaultValue));
|
||||
}
|
||||
else if(ep.Type == "System.Int" || ep.Type == "Int")
|
||||
{
|
||||
dint.Add(ep.Name, int.Parse(ep.DefaultValue));
|
||||
}
|
||||
else if(ep.Type == "System.String" || ep.Type == "String")
|
||||
{
|
||||
dstr.Add(ep.Name, ep.DefaultValue);
|
||||
}
|
||||
else
|
||||
{
|
||||
throw new InvalidOperationException($"Unsupported property type: {ep.Type}");
|
||||
}
|
||||
}
|
||||
|
||||
return new ElementProperties(isOpen, dbool, ddouble, dint, dstr);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user