diff --git a/CPF.Razor/CPF.Razor.csproj b/CPF.Razor/CPF.Razor.csproj index 449f4b6..adbf54c 100644 --- a/CPF.Razor/CPF.Razor.csproj +++ b/CPF.Razor/CPF.Razor.csproj @@ -1,7 +1,7 @@  - netstandard2.0 + net8.0 9.0 diff --git a/CPF/Json/Attribute/AliasAttribute.cs b/CPF/Json/Attribute/AliasAttribute.cs deleted file mode 100644 index ed45096..0000000 --- a/CPF/Json/Attribute/AliasAttribute.cs +++ /dev/null @@ -1,22 +0,0 @@ -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 deleted file mode 100644 index 0ded4ff..0000000 --- a/CPF/Json/Attribute/IgnoreAttribute.cs +++ /dev/null @@ -1,13 +0,0 @@ -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 deleted file mode 100644 index 643f249..0000000 --- a/CPF/Json/Attribute/IgnoreDefaultValueAttribute.cs +++ /dev/null @@ -1,14 +0,0 @@ -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 deleted file mode 100644 index 47ad74c..0000000 --- a/CPF/Json/Attribute/JsonDeserializeCtorAttribute.cs +++ /dev/null @@ -1,24 +0,0 @@ -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 deleted file mode 100644 index 41afce0..0000000 --- a/CPF/Json/Attribute/JsonOnlyIncludeAttribute.cs +++ /dev/null @@ -1,13 +0,0 @@ -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 deleted file mode 100644 index 81b1c8c..0000000 --- a/CPF/Json/Attribute/JsonOrderAttribute.cs +++ /dev/null @@ -1,22 +0,0 @@ -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 deleted file mode 100644 index 48a1ac2..0000000 --- a/CPF/Json/Attribute/ValueFormatAttribute.cs +++ /dev/null @@ -1,51 +0,0 @@ -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 deleted file mode 100644 index 5058194..0000000 --- a/CPF/Json/Exception/JsonDeserializationTypeResolutionException.cs +++ /dev/null @@ -1,53 +0,0 @@ -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 deleted file mode 100644 index 8a524dc..0000000 --- a/CPF/Json/Exception/JsonNoSupportedDeserializeTypeException.cs +++ /dev/null @@ -1,26 +0,0 @@ -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 deleted file mode 100644 index 049e4f6..0000000 --- a/CPF/Json/Exception/JsonWrongCharacterException.cs +++ /dev/null @@ -1,68 +0,0 @@ -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 new file mode 100644 index 0000000..23a46b7 --- /dev/null +++ b/CPF/Json/Formatter.cs @@ -0,0 +1,73 @@ +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 deleted file mode 100644 index 99f6906..0000000 --- a/CPF/Json/Formatter/Deserializer/Default/BaseType.cs +++ /dev/null @@ -1,103 +0,0 @@ -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 deleted file mode 100644 index 4576fff..0000000 --- a/CPF/Json/Formatter/Deserializer/Default/DateTime.cs +++ /dev/null @@ -1,1251 +0,0 @@ -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