Skip to content

Commit c4dcb47

Browse files
committed
[1.8.1]新增转换,修复bug和提高兼容性
* 新增LPS相关转换类 CF_LPS/CF_Line/CF_Sub * 修复字典中因为无内容导致的报错 `TryGetValue` * 更好的nullable兼容性
1 parent 702b358 commit c4dcb47

14 files changed

Lines changed: 425 additions & 174 deletions

File tree

.gitignore

Lines changed: 51 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
## Ignore Visual Studio temporary files, build results, and
22
## files generated by popular Visual Studio add-ons.
33
##
4-
## Get latest from https://github.com/github/gitignore/blob/master/VisualStudio.gitignore
4+
## Get latest from https://github.com/github/gitignore/blob/main/VisualStudio.gitignore
55

66
# User-specific files
77
*.rsuser
@@ -23,6 +23,7 @@ mono_crash.*
2323
[Rr]eleases/
2424
x64/
2525
x86/
26+
[Ww][Ii][Nn]32/
2627
[Aa][Rr][Mm]/
2728
[Aa][Rr][Mm]64/
2829
bld/
@@ -61,6 +62,9 @@ project.lock.json
6162
project.fragment.lock.json
6263
artifacts/
6364

65+
# ASP.NET Scaffolding
66+
ScaffoldingReadMe.txt
67+
6468
# StyleCop
6569
StyleCopReport.xml
6670

@@ -86,6 +90,7 @@ StyleCopReport.xml
8690
*.tmp_proj
8791
*_wpftmp.csproj
8892
*.log
93+
*.tlog
8994
*.vspscc
9095
*.vssscc
9196
.builds
@@ -137,6 +142,11 @@ _TeamCity*
137142
.axoCover/*
138143
!.axoCover/settings.json
139144

145+
# Coverlet is a free, cross platform Code Coverage Tool
146+
coverage*.json
147+
coverage*.xml
148+
coverage*.info
149+
140150
# Visual Studio code coverage results
141151
*.coverage
142152
*.coveragexml
@@ -182,7 +192,8 @@ publish/
182192
# in these scripts will be unencrypted
183193
PublishScripts/
184194

185-
195+
# NuGet Packages
196+
*.nupkg
186197
# NuGet Symbol Packages
187198
*.snupkg
188199
# The packages folder can be ignored because of Package Restore
@@ -283,6 +294,17 @@ node_modules/
283294
# Visual Studio 6 auto-generated workspace file (contains which files were open etc.)
284295
*.vbw
285296

297+
# Visual Studio 6 auto-generated project file (contains which files were open etc.)
298+
*.vbp
299+
300+
# Visual Studio 6 workspace and project file (working project files containing files to include in project)
301+
*.dsw
302+
*.dsp
303+
304+
# Visual Studio 6 technical files
305+
*.ncb
306+
*.aps
307+
286308
# Visual Studio LightSwitch build output
287309
**/*.HTMLClient/GeneratedArtifacts
288310
**/*.DesktopClient/GeneratedArtifacts
@@ -339,6 +361,9 @@ ASALocalRun/
339361
# Local History for Visual Studio
340362
.localhistory/
341363

364+
# Visual Studio History (VSHistory) files
365+
.vshistory/
366+
342367
# BeatPulse healthcheck temp database
343368
healthchecksdb
344369

@@ -347,3 +372,27 @@ MigrationBackup/
347372

348373
# Ionide (cross platform F# VS Code tools) working folder
349374
.ionide/
375+
376+
# Fody - auto-generated XML schema
377+
FodyWeavers.xsd
378+
379+
# VS Code files for those working on multiple tools
380+
.vscode/*
381+
!.vscode/settings.json
382+
!.vscode/tasks.json
383+
!.vscode/launch.json
384+
!.vscode/extensions.json
385+
*.code-workspace
386+
387+
# Local History for Visual Studio Code
388+
.history/
389+
390+
# Windows Installer files from build outputs
391+
*.cab
392+
*.msi
393+
*.msix
394+
*.msm
395+
*.msp
396+
397+
# JetBrains Rider
398+
*.sln.iml

LinePutScript/Converter/LPSConvert.cs

Lines changed: 86 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -39,31 +39,101 @@ public ConvertFunction() { }
3939
/// <param name="type">ConvertFunction</param>
4040
/// <param name="value">要转换的值</param>
4141
/// <returns>String:Info</returns>
42-
public static string Convert(Type type, dynamic value)
42+
public static string Convert(Type type, dynamic? value)
4343
{
44-
#pragma warning disable CS8600
4544
var mi = type.GetMethod("Convert");
46-
#pragma warning disable CS8602
47-
object[] args = { value };
48-
return (string)mi.Invoke(Activator.CreateInstance(type), args);
49-
#pragma warning restore CS8600
50-
#pragma warning restore CS8602
45+
object?[] args = { value };
46+
return (string)(mi?.Invoke(Activator.CreateInstance(type), args) ?? "");
5147
}
5248
/// <summary>
5349
/// 通过Type获取转换方法
5450
/// </summary>
5551
/// <param name="type">ConvertFunction</param>
5652
/// <param name="info">储存的Info</param>
5753
/// <returns>要转换的值</returns>
58-
public static dynamic ConvertBack(Type type, string info)
54+
public static dynamic? ConvertBack(Type type, string info)
5955
{
60-
#pragma warning disable CS8600
6156
var mi = type.GetMethod("ConvertBack");
62-
#pragma warning disable CS8602
6357
object[] args = { info };
64-
return mi.Invoke(Activator.CreateInstance(type), args);
65-
#pragma warning restore CS8600
66-
#pragma warning restore CS8602
58+
return mi?.Invoke(Activator.CreateInstance(type), args);
59+
}
60+
/// <summary>
61+
/// LPS储存转换器
62+
/// </summary>
63+
public class CF_LPS<T> : ConvertFunction where T : ILPS, new()
64+
{
65+
/// <summary>
66+
/// 指定转换方法
67+
/// </summary>
68+
/// <param name="value">要转换的值</param>
69+
/// <returns>String:Info</returns>
70+
public override string Convert(dynamic value)
71+
{
72+
return Sub.TextReplace(((T)value).ToString() ?? "");
73+
}
74+
/// <summary>
75+
/// 指定反转方法
76+
/// </summary>
77+
/// <param name="info">储存的Info</param>
78+
/// <returns>要转换的值</returns>
79+
public override dynamic ConvertBack(string info)
80+
{
81+
T t = new T();
82+
t.Load(info);
83+
return t;
84+
}
85+
}
86+
/// <summary>
87+
/// Line储存转换器
88+
/// </summary>
89+
public class CF_Line<T> : ConvertFunction where T : ILine, new()
90+
{
91+
/// <summary>
92+
/// 指定转换方法
93+
/// </summary>
94+
/// <param name="value">要转换的值</param>
95+
/// <returns>String:Info</returns>
96+
public override string Convert(dynamic value)
97+
{
98+
return Sub.TextReplace(((T)value).ToString() ?? "");
99+
}
100+
/// <summary>
101+
/// 指定反转方法
102+
/// </summary>
103+
/// <param name="info">储存的Info</param>
104+
/// <returns>要转换的值</returns>
105+
public override dynamic ConvertBack(string info)
106+
{
107+
T t = new T();
108+
t.Load(info);
109+
return t;
110+
}
111+
}
112+
/// <summary>
113+
/// Sub储存转换器
114+
/// </summary>
115+
public class CF_Sub<T> : ConvertFunction where T : ISub, new()
116+
{
117+
/// <summary>
118+
/// 指定转换方法
119+
/// </summary>
120+
/// <param name="value">要转换的值</param>
121+
/// <returns>String:Info</returns>
122+
public override string Convert(dynamic value)
123+
{
124+
return Sub.TextReplace(((T)value).ToString() ?? "");
125+
}
126+
/// <summary>
127+
/// 指定反转方法
128+
/// </summary>
129+
/// <param name="info">储存的Info</param>
130+
/// <returns>要转换的值</returns>
131+
public override dynamic ConvertBack(string info)
132+
{
133+
T t = new T();
134+
t.Load(info);
135+
return t;
136+
}
67137
}
68138
}
69139
/// <summary>
@@ -380,7 +450,9 @@ public static string GetObjectString(object? value, ConvertType type = ConvertTy
380450
#pragma warning disable CS8602
381451
MethodInfo miConstructed = mi.MakeGenericMethod(att.ILineType);
382452
object[] args = { value, linename };
453+
#pragma warning disable CS8603 // 可能返回 null 引用。
383454
return (TLine)miConstructed.Invoke(null, args);
455+
#pragma warning restore CS8603 // 可能返回 null 引用。
384456
#pragma warning restore CS8600
385457
#pragma warning restore CS8602
386458
case ConvertType.Converter:
@@ -545,7 +617,7 @@ public static string GetObjectString(object? value, ConvertType type = ConvertTy
545617
case ConvertType.ToDictionary:
546618
var subtypes = type.GetGenericArguments();
547619
IDictionary dict = (IDictionary)Activator.CreateInstance(type);
548-
foreach (Sub s in line)
620+
foreach (ISub s in line)
549621
{
550622
var k = GetStringObject(s.Name, subtypes[0]);
551623
if (k != null)

LinePutScript/Converter/LineAttribute.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ public class LineAttribute : Attribute
1212

1313

1414
/// <summary>
15-
/// 将改内容转换成Line
15+
/// 将该内容转换成Line
1616
/// </summary>
1717
public LineAttribute()
1818
{

LinePutScript/Core/LinePutScript.Core.csproj

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

33
<PropertyGroup>
44
<ImplicitUsings>disable</ImplicitUsings>
5-
<TargetFramework>net6.0</TargetFramework>
5+
<TargetFramework>netcoreapp3.1</TargetFramework>
66
<LangVersion>9.0</LangVersion>
77
<Nullable>enable</Nullable>
88
<GenerateDocumentationFile>True</GenerateDocumentationFile>
@@ -16,6 +16,14 @@
1616
<AssemblyName>LinePutScript</AssemblyName>
1717
<RootNamespace>LinePutScript</RootNamespace>
1818
</PropertyGroup>
19+
20+
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|AnyCPU'">
21+
<NoWarn>1701;1702;IDE0090;</NoWarn>
22+
</PropertyGroup>
23+
24+
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|AnyCPU'">
25+
<NoWarn>1701;1702;IDE0090;</NoWarn>
26+
</PropertyGroup>
1927
<ItemGroup>
2028
<Compile Include="..\gobj.cs" />
2129
<Compile Include="..\Interface\IGetOBJ.cs" Link="Interface\IGetOBJ.cs" />

0 commit comments

Comments
 (0)