From 1f5525b793c8ed9c87a022dce8daa5ae3f0ae293 Mon Sep 17 00:00:00 2001 From: qaz734913414 <734913414@qq.com> Date: Thu, 28 Dec 2023 08:50:27 +0800 Subject: [PATCH] =?UTF-8?q?=E6=9B=B4=E6=96=B0=E4=BB=A3=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- CPF.Linux/CPF.Linux.csproj | 7 +- CPF.Mac/CPF.Mac.csproj | 5 +- CPF.Skia/CPF.Skia.csproj | 7 +- CPF.Skia/SkiaDrawingContext.cs | 5 - CPF.Windows/CPF.Windows.csproj | 7 +- CPF/AttachedProperties.cs | 46 +- CPF/Binding.cs | 4 +- CPF/BindingDescribe.cs | 56 +- CPF/CPF.csproj | 8 +- CPF/Controls/CodeTextBox/CodeTextBox.cs | 6 +- CPF/Controls/CodeTextBox/CodeTextView.cs | 2 +- CPF/Controls/DataGrid/DataGrid.cs | 2 +- CPF/Controls/ItemCollection.cs | 2 +- CPF/Controls/ResponsivePanel.cs | 1 - CPF/Controls/View.cs | 2 +- CPF/CpfObject.cs | 31 +- CPF/Design/CommandMessage.cs | 14 +- CPF/Design/DesignPlatform.cs | 2 +- CPF/Documents/Block.cs | 2 +- CPF/Documents/IDocumentContainer.cs | 2 +- CPF/Drawing/SolidColorBrush.cs | 38 +- CPF/Json/Attribute/AliasAttribute.cs | 22 + CPF/Json/Attribute/IgnoreAttribute.cs | 13 + .../Attribute/IgnoreDefaultValueAttribute.cs | 14 + .../Attribute/JsonDeserializeCtorAttribute.cs | 24 + .../Attribute/JsonOnlyIncludeAttribute.cs | 13 + CPF/Json/Attribute/JsonOrderAttribute.cs | 22 + CPF/Json/Attribute/ValueFormatAttribute.cs | 51 + ...nDeserializationTypeResolutionException.cs | 53 + ...JsonNoSupportedDeserializeTypeException.cs | 26 + .../Exception/JsonWrongCharacterException.cs | 68 + CPF/Json/Formatter.cs | 73 - .../Deserializer/Default/BaseType.cs | 103 ++ .../Deserializer/Default/DateTime.cs | 1251 ++++++++++++++++ .../Deserializer/Default/Primitive.cs | 1247 ++++++++++++++++ .../Deserializer/Default/SpecialConditions.cs | 80 ++ .../Deserializer/Default/SpecialType.cs | 414 ++++++ .../Deserializer/Default/TimeSpan.cs | 576 ++++++++ .../Deserializer/DefaultJsonResolve.cs | 8 + .../Deserializer/DeserializeObjectJump.cs | 92 ++ .../Deserializer/Expression/ArrayBuild.cs | 96 ++ .../Deserializer/Expression/BuildFactory.cs | 68 + .../Deserializer/Expression/BuildTypeEnum.cs | 17 + .../Expression/CollectionBuild.cs | 107 ++ .../Expression/CtorInjectBuild.cs | 35 + .../Expression/DictionaryBuild.cs | 120 ++ .../Deserializer/Expression/DynamicBuild.cs | 109 ++ .../Expression/ExpressionMembers.cs | 151 ++ .../Expression/KeyValueObjectBuild.cs | 503 +++++++ .../Expression/KeyValuePairBuild.cs | 66 + .../Deserializer/Expression/LazyBuild.cs | 37 + .../Expression/MultiArrayBuild.cs | 136 ++ .../Expression/WrongGenericKeyBuild.cs | 36 + .../Deserializer/ExpressionJsonResolve.cs | 9 + CPF/Json/Formatter/Deserializer/JArray.cs | 11 + CPF/Json/Formatter/Deserializer/JObject.cs | 18 + CPF/Json/Formatter/Deserializer/JsonReader.cs | 765 ++++++++++ .../Formatter/Deserializer/JsonResolveBase.cs | 6 + .../Options/GlobalValueFormatDelegate.cs | 15 + .../Options/JsonDeserializeHandler.cs | 26 + .../Options/JsonDeserializeOption.cs | 57 + .../Formatter/Deserializer/ResolveFind.cs | 459 ++++++ .../Formatter/Deserializer/ResolveProvider.cs | 48 + CPF/Json/Formatter/Internal/BootTable.cs | 87 ++ .../Formatter/Internal/BootTableTypeEnum.cs | 8 + CPF/Json/Formatter/Internal/CharHelper.cs | 22 + CPF/Json/Formatter/Internal/CharTries.cs | 36 + .../Internal/DeserializeBootTable.cs | 7 + .../Formatter/Internal/ExpressionHelper.cs | 78 + .../Internal/ExpressionTypeAttribute.cs | 23 + .../Formatter/Internal/FuncLableAttribute.cs | 21 + CPF/Json/Formatter/Internal/FuncType.cs | 9 + CPF/Json/Formatter/Internal/GuidStruct.cs | 54 + .../Internal/JsonCharacterReadStateEnum.cs | 31 + .../Formatter/Internal/MemberExtension.cs | 34 + .../Formatter/Internal/MethodInfoOrder.cs | 19 + .../Formatter/Internal/RemoveWriterHelper.cs | 205 +++ .../Formatter/Internal/SerializerBootTable.cs | 7 + CPF/Json/Formatter/Internal/StreamOperate.cs | 71 + CPF/Json/Formatter/Internal/TypeUtils.cs | 434 ++++++ .../Formatter/Serializer/Default/BaseType.cs | 41 + .../Formatter/Serializer/Default/Primitive.cs | 400 ++++++ .../Serializer/Default/SpecialConditions.cs | 283 ++++ .../Serializer/Default/SpecialType.cs | 1066 ++++++++++++++ .../Serializer/DefaultJsonFormatter.cs | 6 + .../Serializer/Expression/BuildFactory.cs | 66 + .../Serializer/Expression/BuildTypeEnum.cs | 15 + .../Expression/ExpressionMembers.cs | 188 +++ .../Expression/IDictionaryGenericBuild.cs | 71 + .../Expression/IEnumerableGenericBuild.cs | 58 + .../Expression/IListGenericBuild.cs | 73 + .../Expression/KeyValueObjectBuild.cs | 183 +++ .../Expression/KeyValuePairBuild.cs | 31 + .../Serializer/Expression/LazyBuild.cs | 22 + .../Serializer/Expression/NullableBuild.cs | 22 + .../Expression/WrongGenericKeyBuild.cs | 24 + .../Serializer/ExpressionJsonFormatter.cs | 6 + .../Formatter/Serializer/FormatterFind.cs | 462 ++++++ .../Serializer/FormattingProvider.cs | 15 + .../Formatter/Serializer/JsonFormatterBase.cs | 7 + .../Serializer/Option/DatetimeFormatEnum.cs | 44 + .../Option/GlobalValueFormatDelegate.cs | 16 + .../Option/JsonRefernceHandlingEnum.cs | 31 + .../Option/JsonSerializerHandler.cs | 85 ++ .../Serializer/Option/JsonSerializerOption.cs | 88 ++ .../Serializer/Option/TimespanFormatEnum.cs | 19 + .../Serializer/SerializerObjectJump.cs | 57 + CPF/Json/Getters.cs | 10 - CPF/Json/JSerializer.cs | 663 --------- CPF/Json/JsonParser.cs | 443 ------ CPF/Json/JsonSerializer.cs | 1253 ++--------------- CPF/Json/Reflection.cs | 705 ---------- CPF/Json/SafeDictionary.cs | 51 - CPF/Net4/EventHandler.cs | 2 +- CPF/Net4/WeakReference.cs | 2 +- CPF/ObjectExtenstions.cs | 4 +- CPF/Platform/Application.cs | 2 +- CPF/Platform/RuntimePlatform.cs | 2 +- CPF/Platform/Screen.cs | 2 +- CPF/Shapes/Polyline.cs | 2 +- CPF/SolidColorFill.cs | 2 +- CPF/Threading/DispatcherTimer.cs | 2 +- CPF/UIElement.cs | 2 +- CPF/UIElementCollection.cs | 2 +- ClassLibrary1/ClassLibrary1.csproj | 2 +- ConsoleApp1.sln | 152 +- ConsoleApp1/ConsoleApp1.csproj | 2 +- 127 files changed, 11723 insertions(+), 3401 deletions(-) create mode 100644 CPF/Json/Attribute/AliasAttribute.cs create mode 100644 CPF/Json/Attribute/IgnoreAttribute.cs create mode 100644 CPF/Json/Attribute/IgnoreDefaultValueAttribute.cs create mode 100644 CPF/Json/Attribute/JsonDeserializeCtorAttribute.cs create mode 100644 CPF/Json/Attribute/JsonOnlyIncludeAttribute.cs create mode 100644 CPF/Json/Attribute/JsonOrderAttribute.cs create mode 100644 CPF/Json/Attribute/ValueFormatAttribute.cs create mode 100644 CPF/Json/Exception/JsonDeserializationTypeResolutionException.cs create mode 100644 CPF/Json/Exception/JsonNoSupportedDeserializeTypeException.cs create mode 100644 CPF/Json/Exception/JsonWrongCharacterException.cs delete mode 100644 CPF/Json/Formatter.cs create mode 100644 CPF/Json/Formatter/Deserializer/Default/BaseType.cs create mode 100644 CPF/Json/Formatter/Deserializer/Default/DateTime.cs create mode 100644 CPF/Json/Formatter/Deserializer/Default/Primitive.cs create mode 100644 CPF/Json/Formatter/Deserializer/Default/SpecialConditions.cs create mode 100644 CPF/Json/Formatter/Deserializer/Default/SpecialType.cs create mode 100644 CPF/Json/Formatter/Deserializer/Default/TimeSpan.cs create mode 100644 CPF/Json/Formatter/Deserializer/DefaultJsonResolve.cs create mode 100644 CPF/Json/Formatter/Deserializer/DeserializeObjectJump.cs create mode 100644 CPF/Json/Formatter/Deserializer/Expression/ArrayBuild.cs create mode 100644 CPF/Json/Formatter/Deserializer/Expression/BuildFactory.cs create mode 100644 CPF/Json/Formatter/Deserializer/Expression/BuildTypeEnum.cs create mode 100644 CPF/Json/Formatter/Deserializer/Expression/CollectionBuild.cs create mode 100644 CPF/Json/Formatter/Deserializer/Expression/CtorInjectBuild.cs create mode 100644 CPF/Json/Formatter/Deserializer/Expression/DictionaryBuild.cs create mode 100644 CPF/Json/Formatter/Deserializer/Expression/DynamicBuild.cs create mode 100644 CPF/Json/Formatter/Deserializer/Expression/ExpressionMembers.cs create mode 100644 CPF/Json/Formatter/Deserializer/Expression/KeyValueObjectBuild.cs create mode 100644 CPF/Json/Formatter/Deserializer/Expression/KeyValuePairBuild.cs create mode 100644 CPF/Json/Formatter/Deserializer/Expression/LazyBuild.cs create mode 100644 CPF/Json/Formatter/Deserializer/Expression/MultiArrayBuild.cs create mode 100644 CPF/Json/Formatter/Deserializer/Expression/WrongGenericKeyBuild.cs create mode 100644 CPF/Json/Formatter/Deserializer/ExpressionJsonResolve.cs create mode 100644 CPF/Json/Formatter/Deserializer/JArray.cs create mode 100644 CPF/Json/Formatter/Deserializer/JObject.cs create mode 100644 CPF/Json/Formatter/Deserializer/JsonReader.cs create mode 100644 CPF/Json/Formatter/Deserializer/JsonResolveBase.cs create mode 100644 CPF/Json/Formatter/Deserializer/Options/GlobalValueFormatDelegate.cs create mode 100644 CPF/Json/Formatter/Deserializer/Options/JsonDeserializeHandler.cs create mode 100644 CPF/Json/Formatter/Deserializer/Options/JsonDeserializeOption.cs create mode 100644 CPF/Json/Formatter/Deserializer/ResolveFind.cs create mode 100644 CPF/Json/Formatter/Deserializer/ResolveProvider.cs create mode 100644 CPF/Json/Formatter/Internal/BootTable.cs create mode 100644 CPF/Json/Formatter/Internal/BootTableTypeEnum.cs create mode 100644 CPF/Json/Formatter/Internal/CharHelper.cs create mode 100644 CPF/Json/Formatter/Internal/CharTries.cs create mode 100644 CPF/Json/Formatter/Internal/DeserializeBootTable.cs create mode 100644 CPF/Json/Formatter/Internal/ExpressionHelper.cs create mode 100644 CPF/Json/Formatter/Internal/ExpressionTypeAttribute.cs create mode 100644 CPF/Json/Formatter/Internal/FuncLableAttribute.cs create mode 100644 CPF/Json/Formatter/Internal/FuncType.cs create mode 100644 CPF/Json/Formatter/Internal/GuidStruct.cs create mode 100644 CPF/Json/Formatter/Internal/JsonCharacterReadStateEnum.cs create mode 100644 CPF/Json/Formatter/Internal/MemberExtension.cs create mode 100644 CPF/Json/Formatter/Internal/MethodInfoOrder.cs create mode 100644 CPF/Json/Formatter/Internal/RemoveWriterHelper.cs create mode 100644 CPF/Json/Formatter/Internal/SerializerBootTable.cs create mode 100644 CPF/Json/Formatter/Internal/StreamOperate.cs create mode 100644 CPF/Json/Formatter/Internal/TypeUtils.cs create mode 100644 CPF/Json/Formatter/Serializer/Default/BaseType.cs create mode 100644 CPF/Json/Formatter/Serializer/Default/Primitive.cs create mode 100644 CPF/Json/Formatter/Serializer/Default/SpecialConditions.cs create mode 100644 CPF/Json/Formatter/Serializer/Default/SpecialType.cs create mode 100644 CPF/Json/Formatter/Serializer/DefaultJsonFormatter.cs create mode 100644 CPF/Json/Formatter/Serializer/Expression/BuildFactory.cs create mode 100644 CPF/Json/Formatter/Serializer/Expression/BuildTypeEnum.cs create mode 100644 CPF/Json/Formatter/Serializer/Expression/ExpressionMembers.cs create mode 100644 CPF/Json/Formatter/Serializer/Expression/IDictionaryGenericBuild.cs create mode 100644 CPF/Json/Formatter/Serializer/Expression/IEnumerableGenericBuild.cs create mode 100644 CPF/Json/Formatter/Serializer/Expression/IListGenericBuild.cs create mode 100644 CPF/Json/Formatter/Serializer/Expression/KeyValueObjectBuild.cs create mode 100644 CPF/Json/Formatter/Serializer/Expression/KeyValuePairBuild.cs create mode 100644 CPF/Json/Formatter/Serializer/Expression/LazyBuild.cs create mode 100644 CPF/Json/Formatter/Serializer/Expression/NullableBuild.cs create mode 100644 CPF/Json/Formatter/Serializer/Expression/WrongGenericKeyBuild.cs create mode 100644 CPF/Json/Formatter/Serializer/ExpressionJsonFormatter.cs create mode 100644 CPF/Json/Formatter/Serializer/FormatterFind.cs create mode 100644 CPF/Json/Formatter/Serializer/FormattingProvider.cs create mode 100644 CPF/Json/Formatter/Serializer/JsonFormatterBase.cs create mode 100644 CPF/Json/Formatter/Serializer/Option/DatetimeFormatEnum.cs create mode 100644 CPF/Json/Formatter/Serializer/Option/GlobalValueFormatDelegate.cs create mode 100644 CPF/Json/Formatter/Serializer/Option/JsonRefernceHandlingEnum.cs create mode 100644 CPF/Json/Formatter/Serializer/Option/JsonSerializerHandler.cs create mode 100644 CPF/Json/Formatter/Serializer/Option/JsonSerializerOption.cs create mode 100644 CPF/Json/Formatter/Serializer/Option/TimespanFormatEnum.cs create mode 100644 CPF/Json/Formatter/Serializer/SerializerObjectJump.cs delete mode 100644 CPF/Json/Getters.cs delete mode 100644 CPF/Json/JSerializer.cs delete mode 100644 CPF/Json/JsonParser.cs delete mode 100644 CPF/Json/Reflection.cs delete mode 100644 CPF/Json/SafeDictionary.cs diff --git a/CPF.Linux/CPF.Linux.csproj b/CPF.Linux/CPF.Linux.csproj index 391f66f..e31f366 100644 --- a/CPF.Linux/CPF.Linux.csproj +++ b/CPF.Linux/CPF.Linux.csproj @@ -1,8 +1,9 @@ - netstandard2.0 - 0.9.6.7 + net8.0 + 0.9.6.5 + false QQ:761716178 QQ:761716178 QQ:761716178 跨平台UI框架 @@ -12,7 +13,7 @@ Xhm.CPF.Linux false true - false + false diff --git a/CPF.Mac/CPF.Mac.csproj b/CPF.Mac/CPF.Mac.csproj index 6a7dcf0..a30566f 100644 --- a/CPF.Mac/CPF.Mac.csproj +++ b/CPF.Mac/CPF.Mac.csproj @@ -1,9 +1,9 @@ - netstandard2.1 + net8.0 QQ:761716178 跨平台UI框架 - 0.9.6.7 + 0.9.6.6 Xhm.CPF.Mac CPF(Cross platform UI framework) QQ:761716178 跨平台UI框架 http://cpf.cskin.net/ Copyright (c) 2020 by http://cpf.cskin.net/ @@ -11,7 +11,6 @@ QQ:761716178 QQ:761716178 true - false diff --git a/CPF.Skia/CPF.Skia.csproj b/CPF.Skia/CPF.Skia.csproj index e004b4b..1d7e589 100644 --- a/CPF.Skia/CPF.Skia.csproj +++ b/CPF.Skia/CPF.Skia.csproj @@ -1,16 +1,15 @@ - netstandard2.0 + net8.0 QQ:761716178 跨平台UI框架 - 0.9.6.7 + 0.9.6.6 Xhm.CPF.Skia CPF(Cross platform UI framework) QQ:761716178 跨平台UI框架 http://cpf.cskin.net/ Copyright (c) 2020 by http://cpf.cskin.net/ CPF(Cross platform UI framework) QQ:761716178 跨平台UI框架 http://cpf.cskin.net/ QQ:761716178 QQ:761716178 - false @@ -31,7 +30,7 @@ - + diff --git a/CPF.Skia/SkiaDrawingContext.cs b/CPF.Skia/SkiaDrawingContext.cs index 1541bca..d156a44 100644 --- a/CPF.Skia/SkiaDrawingContext.cs +++ b/CPF.Skia/SkiaDrawingContext.cs @@ -52,11 +52,6 @@ namespace CPF.Skia public SkiaDrawingContext(IRenderTarget target, SkiaDrawingFactory drawingFactory) { this.drawingFactory = drawingFactory; - if (target.Width < 1 || target.Height < 1) - { - Debug.WriteLine("绘图表面为空"); - Console.WriteLine("绘图表面为空"); - } if (!target.CanUseGPU || !drawingFactory.UseGPU) { IntPtr hdc = IntPtr.Zero; diff --git a/CPF.Windows/CPF.Windows.csproj b/CPF.Windows/CPF.Windows.csproj index 3e8368f..1b1dda5 100644 --- a/CPF.Windows/CPF.Windows.csproj +++ b/CPF.Windows/CPF.Windows.csproj @@ -1,9 +1,9 @@ - net40;netstandard2.0;net5 + net8.0 QQ:761716178 跨平台UI框架 - 0.9.6.7 + 0.9.6.6 Xhm.CPF.Windows CPF(Cross platform UI framework) QQ:761716178 跨平台UI框架 http://cpf.cskin.net/ http://cpf.cskin.net/ @@ -12,6 +12,8 @@ QQ:761716178 QQ:761716178 true + $(NoWarn);SYSLIB0011 + true @@ -55,7 +57,6 @@ Net4 - false diff --git a/CPF/AttachedProperties.cs b/CPF/AttachedProperties.cs index 7c7cf95..a0e2988 100644 --- a/CPF/AttachedProperties.cs +++ b/CPF/AttachedProperties.cs @@ -226,16 +226,16 @@ namespace CPF { Value = value; } - ///// - ///// 设置和绑定附加属性 - ///// - ///// - ///// - ///// - //public AttachedDescribe(object value, string sourceProperty, BindingMode binding) : base(sourceProperty, binding) - //{ - // Value = value; - //} + /// + /// 设置和绑定附加属性 + /// + /// + /// + /// + public AttachedDescribe(object value, string sourceProperty, BindingMode binding) : base(sourceProperty, binding) + { + Value = value; + } /// /// 设置和绑定附加属性 /// @@ -257,17 +257,17 @@ namespace CPF { Value = value; } - ///// - ///// 设置和绑定附加属性 - ///// - ///// - ///// - ///// - ///// - //public AttachedDescribe(object value, object source, string sourceProperty, Func convert) : base(source, sourceProperty, convert) - //{ - // Value = value; - //} + /// + /// 设置和绑定附加属性 + /// + /// + /// + /// + /// + public AttachedDescribe(object value, object source, string sourceProperty, Func convert) : base(source, sourceProperty, convert) + { + Value = value; + } /// /// 设置和绑定附加属性 /// @@ -308,10 +308,6 @@ namespace CPF { Value = value; } - public AttachedDescribe(object value, Func find, string sourceProperty, BindingMode binding, Func convert, Func convertBack, Action SourceToTargetError, Action TargetToSourceError) : base(find, sourceProperty, binding, convert, convertBack, SourceToTargetError, TargetToSourceError) - { - Value = value; - } public object Value { get; set; } diff --git a/CPF/Binding.cs b/CPF/Binding.cs index d72013f..f58af5c 100644 --- a/CPF/Binding.cs +++ b/CPF/Binding.cs @@ -1009,7 +1009,7 @@ namespace CPF public bool ReadValue(out T value) where T : struct { value = default; -#if NET40 +#if Net4 int len = Marshal.SizeOf(typeof(T)); #else int len = Marshal.SizeOf(); @@ -1018,7 +1018,7 @@ namespace CPF { IntPtr ptr = Marshal.AllocHGlobal(len); Marshal.Copy(data, 0, ptr, len); -#if NET40 +#if Net4 value = (T)Marshal.PtrToStructure(ptr, typeof(T)); #else value = Marshal.PtrToStructure(ptr); diff --git a/CPF/BindingDescribe.cs b/CPF/BindingDescribe.cs index 8f76f2d..ec0f1ce 100644 --- a/CPF/BindingDescribe.cs +++ b/CPF/BindingDescribe.cs @@ -18,11 +18,11 @@ namespace CPF PropertyName = sourceProperty; } - //public BindingDescribe(string sourceProperty, BindingMode binding) - //{ - // PropertyName = sourceProperty; - // BindingMode = binding; - //} + public BindingDescribe(string sourceProperty, BindingMode binding) + { + PropertyName = sourceProperty; + BindingMode = binding; + } /// /// 设置绑定 /// @@ -39,24 +39,25 @@ namespace CPF /// 设置绑定 /// /// 如果是int或者byte,0是自己,1是Parent,2是Parent.Parent.... + /// /// public BindingDescribe(object source, string sourceProperty) { PropertyName = sourceProperty; Source = source; } - ///// - ///// 设置绑定 - ///// - ///// 如果是int或者byte,0是自己,1是Parent,2是Parent.Parent.... - ///// - ///// - //public BindingDescribe(object source, string sourceProperty, Func convert) - //{ - // PropertyName = sourceProperty; - // Source = source; - // Convert = convert; - //} + /// + /// 设置绑定 + /// + /// 如果是int或者byte,0是自己,1是Parent,2是Parent.Parent.... + /// + /// + public BindingDescribe(object source, string sourceProperty, Func convert) + { + PropertyName = sourceProperty; + Source = source; + Convert = convert; + } /// /// 设置绑定 /// @@ -79,7 +80,7 @@ namespace CPF /// /// /// - public BindingDescribe(object source, string sourceProperty, BindingMode binding, Func convert = null, Func convertBack = null) + public BindingDescribe(object source, string sourceProperty, BindingMode binding, Func convert, Func convertBack) { BindingMode = binding; PropertyName = sourceProperty; @@ -97,7 +98,7 @@ namespace CPF /// /// /// - public BindingDescribe(object source, string sourceProperty, BindingMode binding, Func convert = null, Func convertBack = null, Action SourceToTargetError = null, Action TargetToSourceError = null) + public BindingDescribe(object source, string sourceProperty, BindingMode binding, Func convert, Func convertBack, Action SourceToTargetError, Action TargetToSourceError) { BindingMode = binding; PropertyName = sourceProperty; @@ -108,23 +109,11 @@ namespace CPF this.TargetToSourceError = TargetToSourceError; } - public BindingDescribe(Func find, string sourcePropertyName, BindingMode bindingMode = BindingMode.OneWay, Func convert = null, Func convertBack = null, Action SourceToTargetError = null, Action TargetToSourceError = null) + public BindingDescribe(CommandDescribe command) { - BindingMode = bindingMode; - PropertyName = sourcePropertyName; - Source = find; - //Find = find; - Convert = convert; - ConvertBack = convertBack; - this.SourceToTargetError = SourceToTargetError; - this.TargetToSourceError = TargetToSourceError; + Command = command; } - //public BindingDescribe(CommandDescribe command) - //{ - // Command = command; - //} - /// /// 数据绑定的转换 /// @@ -400,7 +389,6 @@ namespace CPF //} public BindingMode BindingMode { get; set; } = BindingMode.OneWay; public object Source { get; set; } - //public Func Find { get; set; } public Action SourceToTargetError { get; set; } public Action TargetToSourceError { get; set; } diff --git a/CPF/CPF.csproj b/CPF/CPF.csproj index 16e32b4..cea335b 100644 --- a/CPF/CPF.csproj +++ b/CPF/CPF.csproj @@ -1,12 +1,12 @@ - netstandard2.0;net40 + net8.0 QQ:761716178 QQ:761716178 QQ:761716178 跨平台UI框架 CPF(Cross platform UI framework) QQ:761716178 跨平台UI框架 http://cpf.cskin.net/ - 0.9.6.7 + 0.9.6.6 9.0 Xhm.CPF @@ -50,7 +50,7 @@ - + @@ -95,7 +95,7 @@ - false + Net4 diff --git a/CPF/Controls/CodeTextBox/CodeTextBox.cs b/CPF/Controls/CodeTextBox/CodeTextBox.cs index 4879bbb..9aa4271 100644 --- a/CPF/Controls/CodeTextBox/CodeTextBox.cs +++ b/CPF/Controls/CodeTextBox/CodeTextBox.cs @@ -225,7 +225,7 @@ namespace CPF.Controls /// /// 布局好的行 /// -#if NET40 +#if Net4 public IList Lines { get { return codeTextView.Lines; } @@ -269,7 +269,7 @@ namespace CPF.Controls if (render) { render = false; -#if NET40 +#if Net4 await TaskEx.Delay(30); #else await Task.Delay(30); @@ -285,7 +285,7 @@ namespace CPF.Controls Cancellation = new CancellationTokenSource(); } var ks = KeywordsStyles.ToArray(); -#if NET40 +#if Net4 var styles = await TaskEx.Run(() => CodeTextView.RenderKeywords(Cancellation.Token, ks, codeTextView.Text)); #else var styles = await Task.Run(() => CodeTextView.RenderKeywords(Cancellation.Token, ks, codeTextView.Text)); diff --git a/CPF/Controls/CodeTextBox/CodeTextView.cs b/CPF/Controls/CodeTextBox/CodeTextView.cs index dd71e63..c530f13 100644 --- a/CPF/Controls/CodeTextBox/CodeTextView.cs +++ b/CPF/Controls/CodeTextBox/CodeTextView.cs @@ -742,7 +742,7 @@ namespace CPF.Controls /// /// 布局好的行 /// -#if NET40 +#if Net4 public IList Lines { get { return lines; } diff --git a/CPF/Controls/DataGrid/DataGrid.cs b/CPF/Controls/DataGrid/DataGrid.cs index 0975dc2..9b7ea82 100644 --- a/CPF/Controls/DataGrid/DataGrid.cs +++ b/CPF/Controls/DataGrid/DataGrid.cs @@ -860,7 +860,7 @@ namespace CPF.Controls List list = new List(); foreach (var item in SelectedIndexs) { - if (item >= items.Count || item < 0) + if (item >= items.Count && item < 0) { continue; } diff --git a/CPF/Controls/ItemCollection.cs b/CPF/Controls/ItemCollection.cs index 0cb5a1b..b8c9b61 100644 --- a/CPF/Controls/ItemCollection.cs +++ b/CPF/Controls/ItemCollection.cs @@ -273,7 +273,7 @@ namespace CPF.Controls /// 缓存的属性 /// 降序 public void Sort(Comparison comparison, string propertyName = null, bool descending = false) - { + {//选择排序 Events[nameof(StartSort)]?.Invoke(this, EventArgs.Empty); this.comparison = comparison; diff --git a/CPF/Controls/ResponsivePanel.cs b/CPF/Controls/ResponsivePanel.cs index 945ea54..5b3a8c3 100644 --- a/CPF/Controls/ResponsivePanel.cs +++ b/CPF/Controls/ResponsivePanel.cs @@ -686,7 +686,6 @@ namespace CPF.Controls /// /// 响应布局元素的可见性 /// - [Flags] public enum RVisible : byte { Hidden = 0, diff --git a/CPF/Controls/View.cs b/CPF/Controls/View.cs index f5b4662..e5bd630 100644 --- a/CPF/Controls/View.cs +++ b/CPF/Controls/View.cs @@ -174,7 +174,7 @@ namespace CPF.Controls { try { -#if NET40 +#if Net4 if (item.CanRead && item.GetGetMethod().GetParameters().Length == 0) { var v = item.GetValue(ele, null); diff --git a/CPF/CpfObject.cs b/CPF/CpfObject.cs index a7bb332..121e386 100644 --- a/CPF/CpfObject.cs +++ b/CPF/CpfObject.cs @@ -223,10 +223,6 @@ namespace CPF { Bindings.Add(propertyName, value.PropertyName, layer1, value.BindingMode, value.Convert, value.ConvertBack, value.SourceToTargetError, value.TargetToSourceError); } - else if (value.Source is Func find) - { - Bindings.Add(propertyName, value.PropertyName, find, value.BindingMode, value.Convert, value.ConvertBack, value.SourceToTargetError, value.TargetToSourceError); - } else { Bindings.Add(propertyName, value.PropertyName, value.Source, value.BindingMode, value.Convert, value.ConvertBack, value.SourceToTargetError, value.TargetToSourceError); @@ -3044,32 +3040,7 @@ namespace CPF public void Sort(IComparer comparison) { - //Array.Sort(_items, 0, Count, comparison); - InsertSort(_items, Count, comparison); - } - - //插入排序法 - void InsertSort(T[] array, int count, IComparer comparison) - { - //for循环:i作为指针,进行从左到右扫描数据的工作 - //指针i从1开始扫描,因为i=0时指针左侧无元素 - for (int i = 1; i < count; i++) - { - //temp作为指针键值 - var temp = array[i]; - - //新建变量j,从i开始向左扫描已经有序的元素,并与temp比较 - //若temp小于扫描元素,则将j指针元素向右移位腾出空间 - int j = i; - while (j > 0 && comparison.Compare(array[j - 1], temp) > 0)//array[j - 1] > temp - { - array[j] = array[j - 1]; - j--; - } - //循环完成后将temp放在j指针位置,完成本次插入 - array[j] = temp; - } - + Array.Sort(_items, 0, Count, comparison); } } diff --git a/CPF/Design/CommandMessage.cs b/CPF/Design/CommandMessage.cs index 8a0e1c0..00fcf75 100644 --- a/CPF/Design/CommandMessage.cs +++ b/CPF/Design/CommandMessage.cs @@ -30,17 +30,9 @@ namespace CPF.Design } public static CommandMessage DeserializeWithString(string json) { - var t = typeof(T); - try - { - var obj = JsonSerializer.ToObject>(json); - return obj; - } - catch (Exception e) - { - System.Diagnostics.Debug.WriteLine("JSON异常:" + json + " \n\n" + t.Name + " " + e); - } - return default; + var obj = JsonSerializer.ToObject>(json); + return obj; + //return default; } /// diff --git a/CPF/Design/DesignPlatform.cs b/CPF/Design/DesignPlatform.cs index dbe88d6..3e2afca 100644 --- a/CPF/Design/DesignPlatform.cs +++ b/CPF/Design/DesignPlatform.cs @@ -45,7 +45,7 @@ namespace CPF.Design } Screen[] screens = new Screen[] { new Screen(new Rect(0, 0, 1920, 1080), new Rect(0, 0, 1920, 1080), true) }; -#if NET40 +#if Net4 public override IList GetAllScreen() { return screens; diff --git a/CPF/Documents/Block.cs b/CPF/Documents/Block.cs index 58b315d..77f2b04 100644 --- a/CPF/Documents/Block.cs +++ b/CPF/Documents/Block.cs @@ -211,7 +211,7 @@ namespace CPF.Documents /// /// 布局好的行 /// -#if NET40 +#if Net4 public IList Lines { get { return lines; } diff --git a/CPF/Documents/IDocumentContainer.cs b/CPF/Documents/IDocumentContainer.cs index 93754ef..2f23e6a 100644 --- a/CPF/Documents/IDocumentContainer.cs +++ b/CPF/Documents/IDocumentContainer.cs @@ -17,7 +17,7 @@ namespace CPF.Documents /// /// 布局好的行 /// -#if NET40 +#if Net4 IList Lines { get; } #else IReadOnlyList Lines { get; } diff --git a/CPF/Drawing/SolidColorBrush.cs b/CPF/Drawing/SolidColorBrush.cs index e829fdb..e4536ef 100644 --- a/CPF/Drawing/SolidColorBrush.cs +++ b/CPF/Drawing/SolidColorBrush.cs @@ -35,30 +35,32 @@ namespace CPF.Drawing return Color.ToString(); } - //protected override void Disposing() - //{ - // //usings.Remove(this); - // disposes.Add(this); - //} + protected override void Disposing() + { + //usings.Remove(this); + disposes.Add(this); + } - internal static SolidColorBrush Create(Color color) + internal static SolidColorBrush Creaate(Color color) { SolidColorBrush sb; - //if (disposes.Count == 0) - //{ - sb = new SolidColorBrush(color); - //} - //else - //{ - // sb = disposes[disposes.Count - 1]; - // disposes.RemoveAt(disposes.Count - 1); - // sb.Color = color; - // sb.IsDisposed = false; - //} + if (disposes.Count == 0) + { + sb = new SolidColorBrush(color); + } + else + { + sb = disposes[disposes.Count - 1]; + disposes.RemoveAt(disposes.Count - 1); + sb.Color = color; + sb.IsDisposed = false; + } + //usings.Add(sb); return sb; } - //static List disposes = new List(); + static List disposes = new List(); + //static HashSet usings = new HashSet(); } } diff --git a/CPF/Json/Attribute/AliasAttribute.cs b/CPF/Json/Attribute/AliasAttribute.cs new file mode 100644 index 0000000..ed45096 --- /dev/null +++ b/CPF/Json/Attribute/AliasAttribute.cs @@ -0,0 +1,22 @@ +using System; + +namespace CPF.Json +{ + /// + /// 别名,标记于字段或属性上的特性 + /// Alias,Characteristics marked on fields or property + /// + [AttributeUsage(AttributeTargets.Field | AttributeTargets.Property)] + public class AliasAttribute : Attribute + { + internal string _name { get; set; } + /// + /// Structural aliases + /// + /// + public AliasAttribute(string name) + { + _name = name; + } + } +} diff --git a/CPF/Json/Attribute/IgnoreAttribute.cs b/CPF/Json/Attribute/IgnoreAttribute.cs new file mode 100644 index 0000000..0ded4ff --- /dev/null +++ b/CPF/Json/Attribute/IgnoreAttribute.cs @@ -0,0 +1,13 @@ +using System; + +namespace CPF.Json +{ + /// + /// 被标记的元素,在序列化或反序列化时时将被忽略 + /// Marked elements are ignored when serialized or deserialized + /// + [AttributeUsage(AttributeTargets.Field | AttributeTargets.Property)] + public class IgnoreKeyAttribute : Attribute + { + } +} diff --git a/CPF/Json/Attribute/IgnoreDefaultValueAttribute.cs b/CPF/Json/Attribute/IgnoreDefaultValueAttribute.cs new file mode 100644 index 0000000..643f249 --- /dev/null +++ b/CPF/Json/Attribute/IgnoreDefaultValueAttribute.cs @@ -0,0 +1,14 @@ +using System; + +namespace CPF.Json +{ + /// + /// 当被标记元素的值为默认值时,序列化时将忽略其元素 + /// When the value of the tagged element is the default, its element is ignored when serialized + /// + [AttributeUsage(AttributeTargets.Field | AttributeTargets.Property | AttributeTargets.Class | + AttributeTargets.Struct)] + public class IgnoreDefaultValueAttribute : Attribute + { + } +} \ No newline at end of file diff --git a/CPF/Json/Attribute/JsonDeserializeCtorAttribute.cs b/CPF/Json/Attribute/JsonDeserializeCtorAttribute.cs new file mode 100644 index 0000000..47ad74c --- /dev/null +++ b/CPF/Json/Attribute/JsonDeserializeCtorAttribute.cs @@ -0,0 +1,24 @@ +using System; + +namespace CPF.Json +{ + /// + /// 对Model进行Json反序列化时指定一个构造函数 + /// Specify a constructor for Json deserialization of Model + /// + [AttributeUsage(AttributeTargets.Constructor)] + public class JsonDeserializeCtorAttribute : Attribute + { + internal object[] _args; + + /// + /// 反序列化时的指定构造函数以及参数,args必须和构造函数参数匹配 + /// Deserializing the specified constructor and parameters, args must match the constructor parameters + /// + /// 该构造函数的参数,The parameters of the constructor + public JsonDeserializeCtorAttribute(params object[] args) + { + _args = args; + } + } +} diff --git a/CPF/Json/Attribute/JsonOnlyIncludeAttribute.cs b/CPF/Json/Attribute/JsonOnlyIncludeAttribute.cs new file mode 100644 index 0000000..41afce0 --- /dev/null +++ b/CPF/Json/Attribute/JsonOnlyIncludeAttribute.cs @@ -0,0 +1,13 @@ +using System; + +namespace CPF.Json +{ + /// + /// 序列化仅包含此元素,和Ignore相反 + /// Serialization contains only this element, as opposed to Ignore + /// + [AttributeUsage(AttributeTargets.Field | AttributeTargets.Property)] + public class JsonOnlyIncludeAttribute : Attribute + { + } +} diff --git a/CPF/Json/Attribute/JsonOrderAttribute.cs b/CPF/Json/Attribute/JsonOrderAttribute.cs new file mode 100644 index 0000000..81b1c8c --- /dev/null +++ b/CPF/Json/Attribute/JsonOrderAttribute.cs @@ -0,0 +1,22 @@ +using System; + +namespace CPF.Json +{ + /// + /// 元素排序,标记于字段或属性上的特性 + /// Element sort, a feature marked on a field or property + /// + [AttributeUsage(AttributeTargets.Field | AttributeTargets.Property)] + public class JsonOrderAttribute: Attribute + { + internal ushort _orderNum { get; set; } + /// + /// JsonOrder + /// + /// Order number + public JsonOrderAttribute(ushort orderNum) + { + _orderNum = orderNum; + } + } +} diff --git a/CPF/Json/Attribute/ValueFormatAttribute.cs b/CPF/Json/Attribute/ValueFormatAttribute.cs new file mode 100644 index 0000000..48a1ac2 --- /dev/null +++ b/CPF/Json/Attribute/ValueFormatAttribute.cs @@ -0,0 +1,51 @@ +using System; +using System.Reflection; + +namespace CPF.Json +{ + /// + /// 对Model的值格式化器特性,可标注于字段,属性,结构或类上,(字段/属性) 优先级大于 (结构/类) + /// Value formatter features of Model can be labeled on fields, properties, structures or classes with priority of + /// (fields/properties) over (structures/classes) + /// + [AttributeUsage(AttributeTargets.Field | AttributeTargets.Property | AttributeTargets.Class | + AttributeTargets.Struct)] + public abstract class ValueFormatAttribute : Attribute + { + #region pregenerated metas + internal static MethodInfo _WriteValueFormat = typeof(ValueFormatAttribute).GetMethod(nameof(WriteValueFormat)); + internal static MethodInfo _ReadValueFormat = typeof(ValueFormatAttribute).GetMethod(nameof(ReadValueFormat)); + #endregion + + /// + /// 序列化时 - Model的Value的格式化器 + /// Serialization time - Value formatter for Model + /// + /// 需要被格式化的源元素数据,Source element data that needs to be formatted + /// 值的类型,The type of the value + /// 用于提供一些配置选项,Used to provide some configuration options + /// 决定最终是否进行值格式化,Determines whether the value is ultimately formatted + /// 格式化后的结果,Formatted results + public virtual string WriteValueFormat(object value,Type type, JsonSerializerHandler handler, out bool isValueFormat) + { + isValueFormat = false; + return null; + } + + /// + /// 反序列化时 - Model的Value的格式化器 + /// When deserializing - Value formatter for Model + /// + /// 从Json字符串中读取的匹配字符串,Matched strings read from Json strings + /// 值的类型,The type of the value + /// 用于提供一些配置选项,Used to provide some configuration options + /// 决定最终是否进行值格式化,Determines whether the value is ultimately formatted + /// 格式化后的结果,Formatted results + public virtual object ReadValueFormat(string value,Type type, JsonDeserializeHandler handler, out bool isValueFormat) + { + isValueFormat = false; + return null; + } + + } +} diff --git a/CPF/Json/Exception/JsonDeserializationTypeResolutionException.cs b/CPF/Json/Exception/JsonDeserializationTypeResolutionException.cs new file mode 100644 index 0000000..5058194 --- /dev/null +++ b/CPF/Json/Exception/JsonDeserializationTypeResolutionException.cs @@ -0,0 +1,53 @@ +using CPF.Json.Deserialize; +using System; +using System.Reflection; + +namespace CPF.Json +{ + /// + /// 类型解析错误 + /// Json Deserialization TypeResolution Exception + /// + public class JsonDeserializationTypeResolutionException : Exception + { + #region pregenerated metas + internal static ConstructorInfo _JsonDeserializationTypeResolutionExceptionMsgCtor = + typeof(JsonDeserializationTypeResolutionException).GetConstructor( + BindingFlags.NonPublic | BindingFlags.Instance, null, new[] { typeof(string) }, null); + + internal static ConstructorInfo _JsonDeserializationTypeResolutionExceptionCtor = + typeof(JsonDeserializationTypeResolutionException).GetConstructor( + BindingFlags.NonPublic | BindingFlags.Instance, null, new[] { typeof(JsonReader), typeof(Type) }, null); + #endregion + + + internal JsonDeserializationTypeResolutionException() : base("Json deserialization type parsing error") + { + } + + internal JsonDeserializationTypeResolutionException(string msg) : base( + $"Json deserialization type parsing error : {msg}") + { + } + + internal JsonDeserializationTypeResolutionException(Type t) : base( + $"Json deserialization {t.Name} type parsing error") + { + } + + internal JsonDeserializationTypeResolutionException(JsonReader reader, Type t) : base( + $"Json deserialization {t.Name} type parsing error ,An error occurred on symbol {reader.Length - reader.Remaining-1} , it's { reader[reader.Length - reader.Remaining-1]}") + { + } + + internal JsonDeserializationTypeResolutionException(JsonReader reader, Type t, string msg) : base( + $"Json deserialization {t.Name} type parsing error ,An error occurred on symbol {reader.Length - reader.Remaining-1} , {msg}") + { + } + + internal JsonDeserializationTypeResolutionException(Type t, string msg) : base( + $"Json deserialization {t.Name} type parsing error , {msg}") + { + } + } +} diff --git a/CPF/Json/Exception/JsonNoSupportedDeserializeTypeException.cs b/CPF/Json/Exception/JsonNoSupportedDeserializeTypeException.cs new file mode 100644 index 0000000..8a524dc --- /dev/null +++ b/CPF/Json/Exception/JsonNoSupportedDeserializeTypeException.cs @@ -0,0 +1,26 @@ +using System; + +namespace CPF.Json +{ + /// + /// 不受支持的解析类型 + /// Unsupported parse type + /// + public class JsonNoSupportedDeserializeTypeException : Exception + { + internal JsonNoSupportedDeserializeTypeException(string msg) : base("Json Deserialize Unsupported type : " + msg) + { + + } + + internal JsonNoSupportedDeserializeTypeException(Type t) : base("Json Deserialize Unsupported type : " + t.Name) + { + + } + + internal JsonNoSupportedDeserializeTypeException(Type t, string msg) : base("Json Deserialize Unsupported type : " + t.Name + " , " + msg) + { + + } + } +} diff --git a/CPF/Json/Exception/JsonWrongCharacterException.cs b/CPF/Json/Exception/JsonWrongCharacterException.cs new file mode 100644 index 0000000..049e4f6 --- /dev/null +++ b/CPF/Json/Exception/JsonWrongCharacterException.cs @@ -0,0 +1,68 @@ +using CPF.Json.Deserialize; +using System; +using System.Reflection; + +namespace CPF.Json +{ + /// + /// 错误的json字符 + /// Json Wrong Character + /// + public class JsonWrongCharacterException : Exception + { + #region pregenerated metas + internal static ConstructorInfo _JsonWrongCharacterExceptionCtor = + typeof(JsonWrongCharacterException).GetConstructor(BindingFlags.NonPublic | BindingFlags.Instance, null, + new[] { typeof(JsonReader) }, null); + #endregion + + internal JsonWrongCharacterException() : base("Incorrect JSON format") + { + } + + internal JsonWrongCharacterException(string msg) : base("Incorrect JSON format : " + msg) + { + + } + + internal JsonWrongCharacterException(int index) : base( + $"Incorrect JSON format : An error occurred on symbol {index} ") + { + + } + + internal JsonWrongCharacterException(int index, string correctString) : base( + $"Incorrect JSON format : An error occurred on symbol {index} , {correctString}") + { + + } + + internal JsonWrongCharacterException(int index, char correctChar, char errorChar) : base( + $"Incorrect JSON format : An error occurred on symbol {index} , It should be {correctChar}, but it's actually {errorChar}") + { + + } + + internal JsonWrongCharacterException(JsonReader reader) : this( + reader.Length - reader.Remaining) + { + + } + + + internal JsonWrongCharacterException( JsonReader reader, string correctString) : this( + reader.Length - reader.Remaining, correctString) + { + + } + + + internal JsonWrongCharacterException(JsonReader reader, char correctChar) : this( + reader.Length - reader.Remaining, correctChar, + reader[reader.Length - reader.Remaining]) + { + + } + + } +} diff --git a/CPF/Json/Formatter.cs b/CPF/Json/Formatter.cs deleted file mode 100644 index 23a46b7..0000000 --- a/CPF/Json/Formatter.cs +++ /dev/null @@ -1,73 +0,0 @@ -using System.Text; - -namespace CPF.Json -{ - internal static class Formatter - { - public static string Indent = " "; - - public static void AppendIndent(StringBuilder sb, int count) - { - for (; count > 0; --count) sb.Append(Indent); - } - - public static string PrettyPrint(string input) - { - var output = new StringBuilder(); - int depth = 0; - int len = input.Length; - char[] chars = input.ToCharArray(); - for (int i = 0; i < len; ++i) - { - char ch = chars[i]; - - if (ch == '\"') // found string span - { - bool str = true; - while (str) - { - output.Append(ch); - ch = chars[++i]; - if (ch == '\\') - { - output.Append(ch); - ch = chars[++i]; - } - else if (ch == '\"') - str = false; - } - } - - switch (ch) - { - case '{': - case '[': - output.Append(ch); - output.AppendLine(); - AppendIndent(output, ++depth); - break; - case '}': - case ']': - output.AppendLine(); - AppendIndent(output, --depth); - output.Append(ch); - break; - case ',': - output.Append(ch); - output.AppendLine(); - AppendIndent(output, depth); - break; - case ':': - output.Append(" : "); - break; - default: - if (!char.IsWhiteSpace(ch)) - output.Append(ch); - break; - } - } - - return output.ToString(); - } - } -} \ No newline at end of file diff --git a/CPF/Json/Formatter/Deserializer/Default/BaseType.cs b/CPF/Json/Formatter/Deserializer/Default/BaseType.cs new file mode 100644 index 0000000..99f6906 --- /dev/null +++ b/CPF/Json/Formatter/Deserializer/Default/BaseType.cs @@ -0,0 +1,103 @@ +using System; +using System.Runtime.CompilerServices; + +namespace CPF.Json.Deserialize +{ + internal class BaseTypeResolve: DefaultJsonResolve + { + [FuncLable(FuncType.BaseType)] +#if !Net4 + [MethodImpl(MethodImplOptions.AggressiveInlining)] +#endif + internal static Exception ReadException(JsonReader reader, JsonDeserializeHandler handler) + { + if (reader.ReadNullOrObjLeft()) + return null; + if (reader.ReadBoolObjRight()) + return new Exception(); + + string source = null, message = null, helpLink = null; + + int i = 1; + char c = ' '; + while (i-- > 0) + { + reader.ReadQuotes(); + switch (handler.Option.JsonCharacterReadState) + { + case JsonCharacterReadStateEnum.None: + c = reader.GetChar(); + break; + case JsonCharacterReadStateEnum.InitialUpper: + c = char.ToUpper(reader.GetChar()); + break; + case JsonCharacterReadStateEnum.InitialLower: + c = char.ToLower(reader.GetChar()); + break; + } + switch (c) + { + case 'S': + c = reader.GetChar(); + if (c == 'o' && reader.StrCompair("urce\"")) + { + reader.ReadColon(); + source = PrimitiveResolve.ReadEscapeString(reader, handler); + } + else if (c == 't' && reader.StrCompair("ackTrace\"")) + { + //只读 + reader.ReadColon(); + PrimitiveResolve.ReadEscapeString(reader, handler); + } + else + throw new Exception(); + break; + case 'M': + { + if (reader.StrCompair("essage\"")) + { + reader.ReadColon(); + message = PrimitiveResolve.ReadEscapeString(reader, handler); + } + else + throw new Exception(); + break; + } + case 'H': + { + if ( reader.StrCompair("elpLink\"")) + { + reader.ReadColon(); + helpLink = PrimitiveResolve.ReadEscapeString(reader, handler); + } + else + throw new Exception(); + break; + } + default: + throw new Exception(); + } + if (reader.ReadBoolComma()) + i++; + } + + var exception = message != null ? new Exception(message) : new Exception(); + + exception.Source = source; + exception.HelpLink = helpLink; + + return exception; + } + + [FuncLable(FuncType.BaseType)] +#if !Net4 + [MethodImpl(MethodImplOptions.AggressiveInlining)] +#endif + internal static Type ReadType(JsonReader reader, JsonDeserializeHandler handler) + { + var typeName = PrimitiveResolve.ReadEscapeString(reader, handler); + return typeName != null ? Type.GetType(typeName) : null; + } + } +} diff --git a/CPF/Json/Formatter/Deserializer/Default/DateTime.cs b/CPF/Json/Formatter/Deserializer/Default/DateTime.cs new file mode 100644 index 0000000..4576fff --- /dev/null +++ b/CPF/Json/Formatter/Deserializer/Default/DateTime.cs @@ -0,0 +1,1251 @@ +using System; +using System.Runtime.CompilerServices; + +namespace CPF.Json.Deserialize +{ + internal class DateTimeResolve : DefaultJsonResolve + { + [FuncLable(FuncType.SameType)] +#if !Net4 + [MethodImpl(MethodImplOptions.AggressiveInlining)] +#endif + internal unsafe static DateTime ReadDateTime(JsonReader reader, JsonDeserializeHandler handler) + { + reader.ReadQuotes(); + char* ip = reader.Pointer; + char c = ip[0]; + if (c >= '0' && c <= '9') + { + //https://tools.ietf.org/html/rfc3339 + //http://en.wikipedia.org/wiki/ISO_8601 + //\"2019-02-11T18:42:04.0068385Z\" + //\"2019-02-11T18:42:04.0068385+08:00\" + return ReadISO8601Date(reader); + } + else if (c == '\\') + { + // "\/Date(628318530718)\/" + return ReadMicrosoftDate(reader, handler); + } + else + { + //Mon, 11 Feb 2019 18:39:32 GMT + return ReadRFC1123DateTime(reader); + } + + } +#if !Net4 + [MethodImpl(MethodImplOptions.AggressiveInlining)] +#endif + static unsafe DateTime ReadMicrosoftDate(JsonReader reader, JsonDeserializeHandler handler) + { + if (!reader.StrCompair("\\/Date(")) + goto Throw; + + long l = PrimitiveResolve.ReadLong(reader, handler); + DateTime dt = new DateTime(l * 10000L + 621355968000000000L); + + if (reader.StrCompair(")\\/\"")) + return dt; + Throw: + throw new JsonDeserializationTypeResolutionException( reader, typeof(DateTime), "Unresolvable Date"); + } + +#if !Net4 + [MethodImpl(MethodImplOptions.AggressiveInlining)] +#endif + static unsafe DateTime ReadISO8601Date(JsonReader reader) + { + // ISO8601 / RFC3339 (the internet "profile"* of ISO8601) is a plague + // See: http://en.wikipedia.org/wiki/ISO_8601 & + // http://tools.ietf.org/html/rfc3339 + // *is bullshit + + // Here are the possible formats for dates + // YYYY-MM-DD + // YYYY-MM + // YYYY-DDD (ordinal date) + // YYYY-Www (week date, the W is a literal) + // YYYY-Www-D + // YYYYMMDD + // YYYYWww + // YYYYWwwD + // YYYYDDD + + // Here are the possible formats for times + // hh + // hh:mm + // hhmm + // hh:mm:ss + // hhmmss + // hh,fff* + // hh:mm,fff* + // hhmm,fff* + // hh:mm:ss,fff* + // hhmmss,fff* + // hh.fff* + // hh:mm.fff* + // hhmm.fff* + // hh:mm:ss.fff* + // hhmmss.fff* + // * arbitrarily many (technically an "agreed upon" number, I'm agreeing on 7 because that's out to a Tick) + + // Here are the possible formats for timezones + // Z + // +hh + // +hh:mm + // +hhmm + // -hh + // -hh:mm + // -hhmm + + // they are concatenated to form a full instant, with T as a separator between date & time + // i.e. T