added .NetFramework4.8 support

This commit is contained in:
Timerix22 2022-10-30 14:33:32 +06:00
parent b89841e39a
commit cacec5de4b
11 changed files with 56 additions and 20 deletions

View File

@ -1,12 +1,13 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net6.0</TargetFramework>
<TargetFrameworks>net6.0;net48</TargetFrameworks>
<LangVersion>preview</LangVersion>
<ImplicitUsings>disable</ImplicitUsings>
<Nullable>disable</Nullable>
<ProduceReferenceAssembly>False</ProduceReferenceAssembly>
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
<ProduceReferenceAssembly>False</ProduceReferenceAssembly>
<DebugType>embedded</DebugType>
<Configurations>Debug;Release</Configurations>
<Platforms>AnyCPU;x64;x86;arm64</Platforms>
</PropertyGroup>

View File

@ -1,11 +1,12 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net6.0</TargetFramework>
<LangVersion>10</LangVersion>
<TargetFrameworks>net6.0;net48</TargetFrameworks>
<LangVersion>preview</LangVersion>
<ImplicitUsings>disable</ImplicitUsings>
<Nullable>disable</Nullable>
<ProduceReferenceAssembly>False</ProduceReferenceAssembly>
<DebugType>embedded</DebugType>
<Configurations>Debug;Release;Release-net48</Configurations>
<Platforms>AnyCPU;x64;x86;arm64</Platforms>
</PropertyGroup>
@ -18,7 +19,6 @@
<ItemGroup Condition=" '$(TargetFramework)' == 'net48' ">
<Reference Include="System.Net" />
<Reference Include="System.Net.Http" />
<Reference Include="System.Dynamic" />
<Reference Include="Microsoft.CSharp" />
</ItemGroup>

View File

@ -1,14 +1,14 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net6.0</TargetFramework>
<TargetFrameworks>net6.0;net48</TargetFrameworks>
<LangVersion>10</LangVersion>
<ImplicitUsings>false</ImplicitUsings>
<Nullable>disable</Nullable>
<CheckForOverflowUnderflow>True</CheckForOverflowUnderflow>
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
<ProduceReferenceAssembly>False</ProduceReferenceAssembly>
<RootNamespace>DTLib.Tests</RootNamespace>
<DebugType>embedded</DebugType>
<Configurations>Debug;Release;Release-net48</Configurations>
<Platforms>AnyCPU;x64;x86;arm64</Platforms>
</PropertyGroup>
@ -30,9 +30,4 @@
<None Update="Dtsod\TestResources\**\*" CopyToOutputDirectory="Always" />
</ItemGroup>
<Target Name="PostBuild" AfterTargets="PostBuildEvent">
<Exec Command="rm -rf ../bin/" />
<Exec Command="cp -r bin/ ../bin/" />
</Target>
</Project>

View File

@ -59,6 +59,14 @@ public static class ColoredConsole
else throw new Exception("ColoredConsole.Write() error: every text string must have color string before");
}
public static void WriteLine() => Console.WriteLine();
public static void WriteLine(params string[] input)
{
Write(input);
WriteLine();
}
// ввод цветного текста
public static string Read(string color)
{

View File

@ -1,6 +1,6 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net6.0</TargetFramework>
<TargetFrameworks>net6.0;net48</TargetFrameworks>
<LangVersion>preview</LangVersion>
<ImplicitUsings>disable</ImplicitUsings>
<Nullable>disable</Nullable>
@ -8,6 +8,7 @@
<!--xxhash uses arithmetic overflow-->
<CheckForOverflowUnderflow>False</CheckForOverflowUnderflow>
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
<DebugType>embedded</DebugType>
<ProduceReferenceAssembly>False</ProduceReferenceAssembly>
<Configurations>Debug;Release</Configurations>
<Platforms>AnyCPU;x64;x86;arm64</Platforms>

View File

@ -9,7 +9,7 @@ public static class DependencyResolver
public static void CopyLibs()
{
if(DepsCopied) return;
string depsdir = "Dependencies" + Путь.Разд;
string depsdir = $"Dependencies{Путь.Разд}";
depsdir += Environment.OSVersion.Platform switch
{
PlatformID.Unix => "linux",

View File

@ -38,7 +38,8 @@ namespace DTLib.Experimental
}
Memory = listMem.ToArray();
Description = listDesc.ToArray();
ColoredConsole.Write("b", "listMem.Count: ", "c", listMem.Count.ToString(), "b", " listDesc.Count: ", "c", listDesc.Count + "\n");
ColoredConsole.Write("b", "listMem.Count: ", "c", listMem.Count.ToString(), "b", " listDesc.Count: ", "c",
$"{listDesc.Count}\n");
for (short i = 0; i < listDesc.Count; i++)
{
ColoredConsole.Write("y", $"{Description[i]}:{Memory[i]}\n");

View File

@ -2,7 +2,9 @@
public static class StringConverter
{
public static ASCIIEncoding ASCII = new ASCIIEncoding();
public static Encoding UTF8 = new UTF8Encoding(false);
public static Encoding UTF8BOM = new UTF8Encoding(true);
public static byte[] ToBytes(this string str) => UTF8.GetBytes(str);
public static string BytesToString(this byte[] bytes) => UTF8.GetString(bytes);

View File

@ -4,7 +4,7 @@ namespace DTLib.Extensions;
public static class Unmanaged
{
public static unsafe IntPtr ToHGlobalUTF8(this string s)
public static unsafe IntPtr StringToHGlobalUTF8(this string s)
{
byte[] buf = s.ToBytes();
int bl = buf.Length;
@ -15,5 +15,29 @@ public static class Unmanaged
return (IntPtr) ptr;
}
public static string ToStringUTF8(this IntPtr p) => Marshal.PtrToStringUTF8(p);
public static unsafe int ASCII_length(IntPtr asciiStr)
{
byte* str = (byte*)asciiStr;
while (*str != (byte)'\0')
str++;
long length = str - (byte*)asciiStr;
if (length > Int32.MaxValue)
throw new Exception($"ascii string length <{length}> > Int32.MaxValue");
return (int)length;
}
public static unsafe string HGlobalUTF8ToString(this IntPtr p)
{
return StringConverter.UTF8.GetString((byte*)p, ASCII_length(p));
/*if (p == IntPtr.Zero)
throw new Exception("string pointer is null");
int length = ASCII_length(p);
byte[] buf = new byte[length];
for (int i = 0; i < length; i++)
buf[i] = ((byte*)p)[i];
fixed(byte* bufptr=&buf[0])
{
return StringConverter.UTF8.GetString(bufptr, length);
}*/
}
}

View File

@ -41,10 +41,14 @@ public class FileLogger : IDisposable
}
public virtual void Dispose()
{
try
{
LogfileStream?.Flush();
LogfileStream?.Close();
}
catch (ObjectDisposedException) { }
}
~FileLogger() => Dispose();
}