解决JSON序列化的BUG和PInvoke函数与Unity兼容问题

This commit is contained in:
小红帽 2024-01-05 00:02:58 +08:00
parent 1d727a09ef
commit 1305f55fef
6 changed files with 38 additions and 17 deletions

View File

@ -1490,8 +1490,10 @@ BLENDFUNCTION blendFunction // alpha-blending function
//[DllImport("shell32.dll", CharSet = CharSet.Auto)] //[DllImport("shell32.dll", CharSet = CharSet.Auto)]
//public static extern int DragQueryFile(HandleRef hDrop, int iFile, StringBuilder lpszFile, int cch); //public static extern int DragQueryFile(HandleRef hDrop, int iFile, StringBuilder lpszFile, int cch);
[DllImport("dwmapi.dll", PreserveSig = false)] //[DllImport("dwmapi.dll", PreserveSig = false)]
public static extern bool DwmIsCompositionEnabled(); //public static extern bool DwmIsCompositionEnabled();
[DllImport("dwmapi.dll", BestFitMapping = false)]
public static extern int DwmIsCompositionEnabled(out Int32 enabled);
[DllImport("dwmapi.dll")] [DllImport("dwmapi.dll")]
public static extern int DwmEnableBlurBehindWindow(IntPtr hWnd, ref DWM_BLURBEHIND pBlurBehind); public static extern int DwmEnableBlurBehindWindow(IntPtr hWnd, ref DWM_BLURBEHIND pBlurBehind);

View File

@ -83,7 +83,7 @@ namespace CPF.Windows
} }
posttime = Application.Elapsed; posttime = Application.Elapsed;
var v = System.Environment.OSVersion.Version; var v = System.Environment.OSVersion.Version;
if (v.Major >= 6 && DwmIsCompositionEnabled() && !Application.DesignMode) if (v.Major >= 6 && DwmIsCompositionEnabled(out var e) == 0 && e == 1 && !Application.DesignMode)
{ {
} }
else else

View File

@ -620,7 +620,7 @@ namespace CPF
throw new Exception($"错误:{ex}"); throw new Exception($"错误:{ex}");
} }
} }
CpfObject SourceProperty = null; //CpfObject SourceProperty = null;
private void Target_PropertyChanged(object sender, PropertyChangedEventArgs e) private void Target_PropertyChanged(object sender, PropertyChangedEventArgs e)
{ {
//重新绑定 //重新绑定

View File

@ -163,6 +163,10 @@ namespace CPF.Json
{ {
sd = new Dictionary<string, myPropInfo>(); sd = new Dictionary<string, myPropInfo>();
var bf = BindingFlags.Public | BindingFlags.Instance | BindingFlags.Static; var bf = BindingFlags.Public | BindingFlags.Instance | BindingFlags.Static;
if (type.Name == "Nullable`1")
{
type = type.GetGenericArguments()[0];
}
PropertyInfo[] pr = type.GetProperties(bf); PropertyInfo[] pr = type.GetProperties(bf);
foreach (PropertyInfo p in pr) foreach (PropertyInfo p in pr)
{ {
@ -316,6 +320,15 @@ namespace CPF.Json
_constrcache.Add(objtype, c); _constrcache.Add(objtype, c);
} }
else // structs else // structs
{
if (objtype.Name == "Nullable`1")
{
var sType = objtype.GetGenericArguments()[0];
var create = objtype.GetConstructor(new Type[] { sType });
c = () => create.Invoke(new object[] { null });
_constrcache.Add(objtype, c);
}
else
{ {
DynamicMethod dynMethod = new DynamicMethod("_", typeof(object), null); DynamicMethod dynMethod = new DynamicMethod("_", typeof(object), null);
ILGenerator ilGen = dynMethod.GetILGenerator(); ILGenerator ilGen = dynMethod.GetILGenerator();
@ -328,6 +341,7 @@ namespace CPF.Json
c = (CreateObject)dynMethod.CreateDelegate(typeof(CreateObject)); c = (CreateObject)dynMethod.CreateDelegate(typeof(CreateObject));
_constrcache.Add(objtype, c); _constrcache.Add(objtype, c);
} }
}
return c(); return c();
} }
} }

View File

@ -228,6 +228,11 @@ namespace CPF.Platform
get; get;
set; set;
} }
/// <summary>
/// 某些平台下不能使用CPF的消息循环需要将该属性改成false
/// </summary>
public static bool NeedRunLoop { get; set; } = true;
//#if NETSTANDARD //#if NETSTANDARD
// /// <summary> // /// <summary>
// /// 启用AOT功能net5以及以上版本才能使用其中包括禁用弱引用事件功能一般在Aot的release发布的时候设置。如果不用Aot请勿设置否则可能有内存泄露风险而且会导致性能降低。 以及切换windows的com包装 // /// 启用AOT功能net5以及以上版本才能使用其中包括禁用弱引用事件功能一般在Aot的release发布的时候设置。如果不用Aot请勿设置否则可能有内存泄露风险而且会导致性能降低。 以及切换windows的com包装

View File

@ -100,7 +100,7 @@ namespace CPF.Threading
} }
if (tempTimers.Count > 0) if (tempTimers.Count > 0)
{ {
if (CPF.Platform.Application.Main != null) if ((CPF.Platform.Application.NeedRunLoop && CPF.Platform.Application.Main != null) || !CPF.Platform.Application.NeedRunLoop)
{ {
Dispatcher.MainThread.Invoke(() => Dispatcher.MainThread.Invoke(() =>
{ {