Skip to content

Commit 9b14854

Browse files
committed
转换支持忽略大小写
1 parent c4dcb47 commit 9b14854

4 files changed

Lines changed: 26 additions & 10 deletions

File tree

LinePutScript/Converter/LPSConvert.cs

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -632,7 +632,14 @@ public static string GetObjectString(object? value, ConvertType type = ConvertTy
632632
if (latt != null && latt is LineAttribute la)
633633
{
634634
var name = la.Name ?? mi.Name;
635-
var s = line.Find(name);
635+
ISub? s;
636+
if (la.IgnoreCase)
637+
{
638+
name = name.ToLower();
639+
s = line.FirstOrDefault(s => s.Name.ToLower() == name);
640+
}
641+
else
642+
s = line.Find(name);
636643
if (s != null)
637644
mi.SetValue(obj, GetSubObject(s, mi.PropertyType, att: la));
638645
}
@@ -643,7 +650,14 @@ public static string GetObjectString(object? value, ConvertType type = ConvertTy
643650
if (latt != null && latt is LineAttribute la)
644651
{
645652
var name = la.Name ?? mi.Name;
646-
var s = line.Find(name);
653+
ISub? s;
654+
if (la.IgnoreCase)
655+
{
656+
name = name.ToLower();
657+
s = line.FirstOrDefault(s => s.Name.ToLower() == name);
658+
}
659+
else
660+
s = line.Find(name);
647661
if (s != null)
648662
mi.SetValue(obj, GetSubObject(s, mi.FieldType, att: la));
649663
}

LinePutScript/Converter/LineAttribute.cs

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,7 @@ public class LineAttribute : Attribute
1414
/// <summary>
1515
/// 将该内容转换成Line
1616
/// </summary>
17-
public LineAttribute()
18-
{
19-
}
17+
public LineAttribute() { }
2018
/// <summary>
2119
/// 将改内容转换成Line
2220
/// </summary>
@@ -25,13 +23,14 @@ public LineAttribute()
2523
/// <param name="name">指定名称</param>
2624
/// <param name="iLineType">如果为类,指定转换ILine的类型,默认为T</param>
2725
/// <param name="fourceToString">强制转换内容为String (多用于当前类为Sub)</param>
28-
public LineAttribute(ConvertType type = ConvertType.Default, Type? converter = null, string? name = null, Type? iLineType = null, bool fourceToString = false)
26+
public LineAttribute(ConvertType type = ConvertType.Default, Type? converter = null, string? name = null, Type? iLineType = null, bool fourceToString = false, bool ignoreCase = false)
2927
{
3028
Type = type;
3129
Converter = converter;
3230
Name = name;
3331
ILineType = iLineType;
3432
FourceToString = fourceToString;
33+
IgnoreCase = ignoreCase;
3534
}
3635
/// <summary>
3736
/// 自定义转换方法
@@ -71,8 +70,7 @@ public LineAttribute(ConvertType type = ConvertType.Default, Type? converter = n
7170
/// <returns>转换结果</returns>
7271
public T ConvertToLine<T>(string name, object? value, bool fourceToString = false) where T : ILine, new()
7372
{
74-
75-
string ln = Name == null ? name : Name;
73+
string ln = Name ?? name;
7674
//如果为null储存空
7775
if (value == null)
7876
{
@@ -94,5 +92,9 @@ public LineAttribute(ConvertType type = ConvertType.Default, Type? converter = n
9492
return LPSConvert.GetObjectLine<T>(value, ln, Type, this);
9593
}
9694
}
95+
/// <summary>
96+
/// 忽略大小写
97+
/// </summary>
98+
public bool IgnoreCase { get; set; } = false;
9799
}
98100
}

LinePutScript/Core/LinePutScript.Core.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
<PropertyGroup>
44
<ImplicitUsings>disable</ImplicitUsings>
5-
<TargetFramework>netcoreapp3.1</TargetFramework>
5+
<TargetFramework>net6.0</TargetFramework>
66
<LangVersion>9.0</LangVersion>
77
<Nullable>enable</Nullable>
88
<GenerateDocumentationFile>True</GenerateDocumentationFile>

LinePutScript/LinePutScript.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
<AppDesignerFolder>Properties</AppDesignerFolder>
1010
<RootNamespace>LinePutScript</RootNamespace>
1111
<AssemblyName>LinePutScript</AssemblyName>
12-
<TargetFrameworkVersion>v4.8</TargetFrameworkVersion>
12+
<TargetFrameworkVersion>v4.6.2</TargetFrameworkVersion>
1313
<LangVersion>9.0</LangVersion>
1414
<FileAlignment>512</FileAlignment>
1515
<Deterministic>true</Deterministic>

0 commit comments

Comments
 (0)