├── Swifter.Core ├── Swifter.Core.snk ├── Tools │ ├── Type │ │ ├── StructBox.cs │ │ ├── StaticsBaseBlock.cs │ │ ├── ReferenceComparer.cs │ │ ├── IGenericInvoker.cs │ │ ├── EEClass.cs │ │ ├── MethodTable.cs │ │ ├── FieldDesc.cs │ │ ├── CloneHelper.cs │ │ └── OverlappedValue.cs │ ├── Convert │ │ ├── EqualsConvert.cs │ │ ├── BaseConvert.cs │ │ ├── ToStringConvert.cs │ │ ├── AssignableConvert.cs │ │ ├── StructToNullableConvert.cs │ │ ├── NullableToStructConvert.cs │ │ ├── ForceConvert.cs │ │ ├── FromDBNullConvert.cs │ │ ├── ToDBNullConvert.cs │ │ ├── ValueToNullableConvert.cs │ │ ├── NullableToValueConvert.cs │ │ ├── ParseEnum.cs │ │ ├── IConverterFactory.cs │ │ ├── IXConvert.cs │ │ ├── ConvertAdd.cs │ │ ├── BasicConvert.Overload.tt │ │ └── ConvertMethodComparer.cs │ ├── Number │ │ ├── ThreeChar.cs │ │ ├── GuidStruct.cs │ │ ├── ParseCode.cs │ │ └── DecimalStruct.cs │ ├── Emit │ │ ├── SingleGroup.cs │ │ ├── BaseGroup.cs │ │ ├── IHashComparer.cs │ │ ├── IDifferenceComparer.cs │ │ ├── LengthGroup.cs │ │ └── CaseInfo.cs │ ├── Method │ │ └── Jmp.cs │ ├── String │ │ └── Utf8Byte.cs │ ├── Storage │ │ ├── THashAlgorithmInstances.cs │ │ ├── HGlobalCacheExtensions.Core.cs │ │ └── HGlobalCache.Core.cs │ └── Task │ │ └── TaskHelper.cs ├── Properties │ └── PublishProfiles │ │ ├── FolderProfile.pubxml.user │ │ └── FolderProfile.pubxml ├── VersionDifferences │ ├── ExtensionAttribute.cs │ ├── DynamicAttribute.cs │ ├── IgnoresAccessChecksToAttribute.cs │ └── BinaryPrimitives.cs ├── Formatters │ ├── IFormatterReader.cs │ ├── IFormatterWriter.cs │ ├── ITextFormatter.Core.cs │ ├── IBinaryFormatter.Core.cs │ ├── FormatterHelper.Core.cs │ └── FormatterHelper.Async.cs ├── Swifter.Core.csproj.user ├── Reflection │ ├── IXFieldRW.cs │ ├── Property │ │ └── Delegate.cs │ ├── XInterfaceAttributedFieldRW.cs │ ├── ThrowHelpers.cs │ └── SerializationBox.T.cs └── RW │ ├── ArrayRW │ ├── IArrayCollectionRW.cs │ ├── ArrayInterfaceMaper.cs │ ├── ArrayInterface.cs │ └── MultiDimArrayInterface.cs │ ├── ITargetedBind.cs │ ├── IValueRW.cs │ ├── Basic │ ├── ByteInterface.cs │ ├── CharInterface.cs │ ├── Int32Interface.cs │ ├── Int64Interface.cs │ ├── Int16Interface.cs │ ├── SByteInterface.cs │ ├── UInt32Interface.cs │ ├── BooleanInterface.cs │ ├── DoubleInterface.cs │ ├── SingleInterface.cs │ ├── StringInterface.cs │ ├── UInt16Interface.cs │ ├── UInt64Interface.cs │ ├── DecimalInterface.cs │ ├── DateTimeInterface.cs │ ├── NullableInterface.cs │ ├── DbNullInterface.cs │ ├── UriInterface.cs │ ├── ObjectInterface.cs │ ├── IntPtrInterface.cs │ ├── VersionInterface.cs │ ├── TimeSpanInterface.cs │ ├── DateTimeOffsetInterface.cs │ ├── EnumInterface.cs │ └── AssemblyInterface.cs │ ├── FastObjectRW │ ├── IFastObjectRWCreater.cs │ ├── ErrorFastObjectRWCreater.cs │ └── NonPublicFastObjectCreater.cs │ ├── RWBoolean.cs │ ├── IValueFilter.cs │ ├── IValueInterfaceMaper.cs │ ├── Data │ ├── DataTableRWOptions.cs │ ├── DbDataReaderInterface.cs │ ├── DataRowInterface.cs │ ├── DataSetInterface.cs │ ├── DataTableInterface.cs │ └── DataInterfaceMaper.cs │ ├── RWFieldAccess.cs │ ├── IValueInterface.cs │ ├── ValueFilterInfo.cs │ ├── Collection │ ├── EnumeratorInterface.cs │ ├── EnumerableInterface.cs │ ├── Generic │ │ ├── EnumeratorInterface.cs │ │ ├── CollectionInterface.cs │ │ ├── DictionaryInterface.cs │ │ ├── EnumeratorReader.cs │ │ └── ListInterface.cs │ ├── CollectionInterface.cs │ ├── DictionaryInterface.cs │ ├── ListInterface.cs │ └── EnumeratorReader.cs │ ├── SetValueFormatInterface.cs │ ├── IDataRW.cs │ ├── Helper │ ├── AsWriteAllReader.cs │ ├── AsReadAllWriter.cs │ └── DefaultValueReader.cs │ └── IDataReader.cs ├── Swifter.Data ├── Swifter.Data.snk ├── Sql │ ├── ITable.cs │ ├── IValue.cs │ ├── Select │ │ ├── Joins.cs │ │ ├── GroupBies.cs │ │ ├── OrderBies.cs │ │ ├── SelectColumns.cs │ │ ├── JoinDirections.cs │ │ ├── OrderBy.cs │ │ └── Join.cs │ ├── Value │ │ ├── AssignValues.cs │ │ ├── VariableValue.cs │ │ ├── ConstantValue.cs │ │ └── AssignValue.cs │ ├── Function │ │ ├── Aggregate │ │ │ ├── AvgFunction.cs │ │ │ ├── MaxFunction.cs │ │ │ ├── MinFunction.cs │ │ │ ├── SumFunction.cs │ │ │ ├── CountFunction.cs │ │ │ └── AggregateFunction.cs │ │ ├── String │ │ │ ├── LowerFunction.cs │ │ │ ├── UpperFunction.cs │ │ │ └── ConcatFunction.cs │ │ ├── Number │ │ │ ├── ModFunction.cs │ │ │ ├── AddFunction.cs │ │ │ ├── DivideFunction.cs │ │ │ ├── MultiplyFunction.cs │ │ │ └── SubtractFunction.cs │ │ ├── IfNullFunction.cs │ │ ├── UnaryFunction.cs │ │ └── BinaryFunction.cs │ ├── SqlBuilderFactory.cs │ ├── DeleteStatement.cs │ ├── Table.cs │ ├── UpdateStatement.cs │ ├── InsertStatement.cs │ ├── Column.cs │ ├── Condition │ │ └── Conditions.cs │ ├── NativeStatement.cs │ ├── Case.cs │ └── SqlBuilderParameters.cs ├── ConditionTypes.cs ├── Swifter.Data.csproj.user ├── SqlServer │ ├── SqlBuilderFactory.cs │ └── MicrosoftSqlBuilderFactory.cs ├── DatabaseEventHandler.cs ├── MySql │ └── SqlBuilderFactory.cs ├── DbRowsFlags.cs ├── OrderByDirections.cs ├── Properties │ └── PublishProfiles │ │ └── FolderProfile.pubxml └── DbRowObjectMap.cs ├── Swifter.Json ├── Swifter.Json.snk ├── Properties │ └── PublishProfiles │ │ ├── FolderProfile.pubxml.user │ │ └── FolderProfile.pubxml ├── JsonArrayAppendingInfo.cs ├── Swifter.Json.csproj.user ├── JsonOutOfDepthException.cs ├── JsonDeserializeException.cs ├── JsonLoopReferencingException.cs ├── JsonSerializeModes.cs ├── JsonToken.cs └── JsonFilteringEventArgs.cs ├── Swifter.Debug ├── Swifter.Debug.pfx ├── Program.cs ├── MyConfig.cs ├── Swifter.Debug.csproj └── Reflection.cs ├── Swifter.MessagePack ├── Swifter.MessagePack.snk ├── MessagePackExtensionTypeCode.cs ├── Properties │ └── PublishProfiles │ │ ├── FolderProfile.pubxml.user │ │ └── FolderProfile.pubxml ├── MessagePackDeserializeModes.cs ├── Swifter.MessagePack.csproj.user ├── MessagePackSerializeModes.cs ├── MessagePackOutOfDepthException.cs ├── MessagePackLoopReferencingException.cs ├── MessagePackDeserializeException.cs ├── MessagePackFilteringEventArgs.cs └── IMessagePackWriter.cs ├── Swifter.Underlying ├── Swifter.Underlying.snk ├── net20 │ ├── Swifter.Underlying.dll │ └── Swifter.Underlying.il ├── netcoreapp2.0 │ ├── Swifter.Underlying.dll │ └── Swifter.Underlying.il ├── netstandard1.0 │ ├── Swifter.Underlying.dll │ └── Swifter.Underlying.il └── bat.txt ├── Swifter.FSharpExtensions ├── Swifter.FSharpExtensions.snk ├── Properties │ └── PublishProfiles │ │ ├── FolderProfile.pubxml.user │ │ └── FolderProfile.pubxml ├── ExtensionLoader.cs ├── Swifter.FSharpExtensions.csproj.user ├── Swifter.FSharpExtensions.csproj ├── FSharpUnionInterface.cs └── FSharpListInterface.cs ├── Swifter.Test.WPF ├── IncorrectException.cs ├── Tests │ ├── ITest.cs │ ├── StringTest.cs │ ├── DecimalArray.cs │ ├── TwoDimArray.cs │ ├── ThreeDimArray.cs │ ├── Int64Array.cs │ ├── DoubleArray.cs │ ├── SingleArray.cs │ ├── PolymorphismTest.cs │ ├── DeviceModel.cs │ ├── Devices.cs │ ├── CatalogModel.cs │ ├── BaseTest.cs │ ├── DevicesDataTable.cs │ ├── Int32Array.cs │ └── DeviceDictionary.cs ├── StopwatchExtensions.cs ├── Result.cs ├── App.xaml.cs ├── App.xaml ├── Serializers │ ├── JilSerializer.cs │ ├── FastJSONSerializer.cs │ ├── Utf8JsonSerializer.cs │ ├── KoobooJsonSerializer.cs │ ├── LitJsonSerializer.cs │ ├── NetJsonSerializer.cs │ ├── AutoCSerJsonSerializer.cs │ ├── SpanJsonSerializer.cs │ ├── SystemTextJsonSerializer.cs │ ├── NewtonsoftJsonSerializer.cs │ ├── NeueccMessagePackSerializer.cs │ ├── ServiceStackSerializer.cs │ ├── SwifterJsonSerializer.cs │ ├── SwifterMessagePackSerializer.cs │ └── ISerializer.cs ├── Swifter.Test.WPF.csproj.user ├── AssemblyInfo.cs ├── Models │ ├── Polymorphism.cs │ └── Device.cs ├── ExceptionResult.cs └── Swifter.Test.WPF.csproj ├── Swifter.Extensions.AspNetCore ├── Swifter.Extensions.AspNetCore.snk ├── SwifterExtensions.Fw.cs ├── Swifter.Extensions.AspNetCore.csproj.user ├── SwifterExtensions.cs ├── Properties │ └── launchSettings.json └── SwifterJsonResult.cs ├── Swifter.Test ├── LogTypes.cs ├── TestStruct.cs ├── UnsafeClass.cs ├── Resources │ └── valueType.json ├── Polymorphism.cs ├── CommonData.cs ├── BasicTypes.cs ├── Program.cs └── Helper.cs ├── Swifter.Test.NUnit ├── Run.cs └── Swifter.Test.NUnit.csproj ├── Swifter.FSharpTest ├── Swifter.FSharpTest.fsproj └── Program.fs └── LICENSE /Swifter.Core/Swifter.Core.snk: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Dogwei/Swifter.MessagePack/HEAD/Swifter.Core/Swifter.Core.snk -------------------------------------------------------------------------------- /Swifter.Data/Swifter.Data.snk: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Dogwei/Swifter.MessagePack/HEAD/Swifter.Data/Swifter.Data.snk -------------------------------------------------------------------------------- /Swifter.Json/Swifter.Json.snk: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Dogwei/Swifter.MessagePack/HEAD/Swifter.Json/Swifter.Json.snk -------------------------------------------------------------------------------- /Swifter.Debug/Swifter.Debug.pfx: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Dogwei/Swifter.MessagePack/HEAD/Swifter.Debug/Swifter.Debug.pfx -------------------------------------------------------------------------------- /Swifter.MessagePack/Swifter.MessagePack.snk: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Dogwei/Swifter.MessagePack/HEAD/Swifter.MessagePack/Swifter.MessagePack.snk -------------------------------------------------------------------------------- /Swifter.Underlying/Swifter.Underlying.snk: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Dogwei/Swifter.MessagePack/HEAD/Swifter.Underlying/Swifter.Underlying.snk -------------------------------------------------------------------------------- /Swifter.Core/Tools/Type/StructBox.cs: -------------------------------------------------------------------------------- 1 | namespace Swifter.Tools 2 | { 3 | internal class StructBox 4 | { 5 | public T Value; 6 | } 7 | } -------------------------------------------------------------------------------- /Swifter.Underlying/net20/Swifter.Underlying.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Dogwei/Swifter.MessagePack/HEAD/Swifter.Underlying/net20/Swifter.Underlying.dll -------------------------------------------------------------------------------- /Swifter.FSharpExtensions/Swifter.FSharpExtensions.snk: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Dogwei/Swifter.MessagePack/HEAD/Swifter.FSharpExtensions/Swifter.FSharpExtensions.snk -------------------------------------------------------------------------------- /Swifter.Underlying/netcoreapp2.0/Swifter.Underlying.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Dogwei/Swifter.MessagePack/HEAD/Swifter.Underlying/netcoreapp2.0/Swifter.Underlying.dll -------------------------------------------------------------------------------- /Swifter.Underlying/netstandard1.0/Swifter.Underlying.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Dogwei/Swifter.MessagePack/HEAD/Swifter.Underlying/netstandard1.0/Swifter.Underlying.dll -------------------------------------------------------------------------------- /Swifter.Data/Sql/ITable.cs: -------------------------------------------------------------------------------- 1 | namespace Swifter.Data.Sql 2 | { 3 | /// 4 | /// 表示一个表 5 | /// 6 | public interface ITable 7 | { 8 | } 9 | } -------------------------------------------------------------------------------- /Swifter.Data/Sql/IValue.cs: -------------------------------------------------------------------------------- 1 | namespace Swifter.Data.Sql 2 | { 3 | /// 4 | /// 表示一个值 5 | /// 6 | public interface IValue 7 | { 8 | } 9 | } -------------------------------------------------------------------------------- /Swifter.Test.WPF/IncorrectException.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | namespace Swifter.Test.WPF 4 | { 5 | public sealed class IncorrectException : Exception 6 | { 7 | 8 | } 9 | } -------------------------------------------------------------------------------- /Swifter.Extensions.AspNetCore/Swifter.Extensions.AspNetCore.snk: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Dogwei/Swifter.MessagePack/HEAD/Swifter.Extensions.AspNetCore/Swifter.Extensions.AspNetCore.snk -------------------------------------------------------------------------------- /Swifter.Debug/Program.cs: -------------------------------------------------------------------------------- 1 | namespace Swifter.Debug 2 | { 3 | public sealed class Program 4 | { 5 | 6 | public static void Main() 7 | { 8 | } 9 | } 10 | } -------------------------------------------------------------------------------- /Swifter.Test/LogTypes.cs: -------------------------------------------------------------------------------- 1 | namespace Swifter.Test 2 | { 3 | public enum LogTypes 4 | { 5 | OnlyFirst = 1, 6 | OnlyTheNext = 2, 7 | All = OnlyFirst | OnlyTheNext 8 | } 9 | } -------------------------------------------------------------------------------- /Swifter.Core/Tools/Convert/EqualsConvert.cs: -------------------------------------------------------------------------------- 1 | namespace Swifter.Tools 2 | { 3 | internal sealed class EqualsConvert : IXConverter 4 | { 5 | public T Convert(T value) => value; 6 | } 7 | } -------------------------------------------------------------------------------- /Swifter.Core/Tools/Type/StaticsBaseBlock.cs: -------------------------------------------------------------------------------- 1 | namespace Swifter.Tools 2 | { 3 | enum StaticsBaseBlock 4 | { 5 | GC = 1, 6 | NonGC = 0, 7 | ThreadGC = 3, 8 | ThreadNonGC = 2 9 | } 10 | } -------------------------------------------------------------------------------- /Swifter.Core/Tools/Convert/BaseConvert.cs: -------------------------------------------------------------------------------- 1 | namespace Swifter.Tools 2 | { 3 | internal sealed class BaseConvert : IXConverter where T : TBase 4 | { 5 | public T Convert(TBase value) => (T)value; 6 | } 7 | } -------------------------------------------------------------------------------- /Swifter.Core/Tools/Convert/ToStringConvert.cs: -------------------------------------------------------------------------------- 1 | namespace Swifter.Tools 2 | { 3 | internal sealed class ToStringConvert : IXConverter 4 | { 5 | public string Convert(T value) => value?.ToString(); 6 | } 7 | } -------------------------------------------------------------------------------- /Swifter.Test.NUnit/Run.cs: -------------------------------------------------------------------------------- 1 | using NUnit.Framework.Api; 2 | using System; 3 | using System.Collections.Generic; 4 | using System.Text; 5 | 6 | namespace Swifter.Test 7 | { 8 | public static class Run 9 | { 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /Swifter.Test.WPF/Tests/ITest.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | namespace Swifter.Test.WPF.Tests 4 | { 5 | public interface ITest 6 | { 7 | string TestName { get; } 8 | Type ObjectType { get; } 9 | } 10 | 11 | } -------------------------------------------------------------------------------- /Swifter.Core/Tools/Convert/AssignableConvert.cs: -------------------------------------------------------------------------------- 1 | namespace Swifter.Tools 2 | { 3 | internal sealed class AssignableConvert : IXConverter where T : TBase 4 | { 5 | public TBase Convert(T value) => value; 6 | } 7 | } -------------------------------------------------------------------------------- /Swifter.Core/Tools/Convert/StructToNullableConvert.cs: -------------------------------------------------------------------------------- 1 | namespace Swifter.Tools 2 | { 3 | internal sealed class StructToNullableConvert : IXConverter where T : struct 4 | { 5 | public T? Convert(T value) => value; 6 | } 7 | } -------------------------------------------------------------------------------- /Swifter.Underlying/bat.txt: -------------------------------------------------------------------------------- 1 | ilmerge /t:library /v4 /xmlDocs /out:Swifter.Merged.dll Swifter.Json.dll Swifter.Core.dll Swifter.Unsafe.dll 2 | ilasm /dll /optimize /output:Swifter.Underlying.dll Swifter.Underlying.il /key:../Swifter.Underlying.snk /mdv:v2.0 -------------------------------------------------------------------------------- /Swifter.Core/Tools/Convert/NullableToStructConvert.cs: -------------------------------------------------------------------------------- 1 | namespace Swifter.Tools 2 | { 3 | internal sealed class NullableToStructConvert : IXConverter where T : struct 4 | { 5 | public T Convert(T? value) => value.Value; 6 | } 7 | } -------------------------------------------------------------------------------- /Swifter.MessagePack/MessagePackExtensionTypeCode.cs: -------------------------------------------------------------------------------- 1 | namespace Swifter.MessagePack 2 | { 3 | static class MessagePackExtensionCode 4 | { 5 | public const sbyte Timestamp = -1; 6 | 7 | public const sbyte Reference = -10; 8 | } 9 | } -------------------------------------------------------------------------------- /Swifter.Data/Sql/Select/Joins.cs: -------------------------------------------------------------------------------- 1 | using System.Collections.Generic; 2 | 3 | namespace Swifter.Data.Sql 4 | { 5 | /// 6 | /// 表连接集合 7 | /// 8 | public sealed class Joins : List 9 | { 10 | 11 | } 12 | } -------------------------------------------------------------------------------- /Swifter.Data/Sql/Select/GroupBies.cs: -------------------------------------------------------------------------------- 1 | using System.Collections.Generic; 2 | 3 | namespace Swifter.Data.Sql 4 | { 5 | /// 6 | /// 分组列集合。 7 | /// 8 | public sealed class GroupBies : List 9 | { 10 | 11 | } 12 | } -------------------------------------------------------------------------------- /Swifter.Data/Sql/Select/OrderBies.cs: -------------------------------------------------------------------------------- 1 | using System.Collections.Generic; 2 | 3 | namespace Swifter.Data.Sql 4 | { 5 | /// 6 | /// 排序集合。 7 | /// 8 | public sealed class OrderBies : List 9 | { 10 | 11 | } 12 | } -------------------------------------------------------------------------------- /Swifter.Data/Sql/Value/AssignValues.cs: -------------------------------------------------------------------------------- 1 | using System.Collections.Generic; 2 | 3 | namespace Swifter.Data.Sql 4 | { 5 | /// 6 | /// 赋值集合 7 | /// 8 | public sealed class AssignValues : List 9 | { 10 | } 11 | } -------------------------------------------------------------------------------- /Swifter.Test/TestStruct.cs: -------------------------------------------------------------------------------- 1 | namespace Swifter.Test 2 | { 3 | public struct TestStruct 4 | { 5 | public string Name { get; set; } 6 | 7 | public int? Nullable { get; set; } 8 | 9 | public int Count { get; set; } 10 | } 11 | } -------------------------------------------------------------------------------- /Swifter.Core/Properties/PublishProfiles/FolderProfile.pubxml.user: -------------------------------------------------------------------------------- 1 | 2 | 5 | 6 | -------------------------------------------------------------------------------- /Swifter.Json/Properties/PublishProfiles/FolderProfile.pubxml.user: -------------------------------------------------------------------------------- 1 | 2 | 5 | 6 | -------------------------------------------------------------------------------- /Swifter.Underlying/netcoreapp2.0/Swifter.Underlying.il: -------------------------------------------------------------------------------- 1 | #define netcoreapp 2 | #define CORE_ASSEMBLY "System.Runtime" 3 | 4 | 5 | #define IS_READ_ONLY_ATTRIBUTE "[CORE_ASSEMBLY]System.Runtime.CompilerServices.IsReadOnlyAttribute" 6 | 7 | 8 | #include "../Swifter.Underlying.il" -------------------------------------------------------------------------------- /Swifter.Core/Tools/Convert/ForceConvert.cs: -------------------------------------------------------------------------------- 1 | namespace Swifter.Tools 2 | { 3 | internal sealed class ForceConvert : IXConverter 4 | { 5 | public TDestination Convert(TSource value) => (TDestination)(object)value; 6 | } 7 | } -------------------------------------------------------------------------------- /Swifter.Data/Sql/Select/SelectColumns.cs: -------------------------------------------------------------------------------- 1 | using System.Collections.Generic; 2 | 3 | namespace Swifter.Data.Sql 4 | { 5 | /// 6 | /// 查询列的集合。 7 | /// 8 | public sealed class SelectColumns : List 9 | { 10 | 11 | } 12 | } -------------------------------------------------------------------------------- /Swifter.MessagePack/Properties/PublishProfiles/FolderProfile.pubxml.user: -------------------------------------------------------------------------------- 1 | 2 | 5 | 6 | -------------------------------------------------------------------------------- /Swifter.FSharpExtensions/Properties/PublishProfiles/FolderProfile.pubxml.user: -------------------------------------------------------------------------------- 1 | 2 | 5 | 6 | -------------------------------------------------------------------------------- /Swifter.Core/VersionDifferences/ExtensionAttribute.cs: -------------------------------------------------------------------------------- 1 | #if NET20 2 | 3 | namespace System.Runtime.CompilerServices 4 | { 5 | /// 6 | /// 扩展方法必要的特性。 7 | /// 8 | public class ExtensionAttribute : Attribute 9 | { 10 | } 11 | } 12 | 13 | #endif -------------------------------------------------------------------------------- /Swifter.Test.WPF/Tests/StringTest.cs: -------------------------------------------------------------------------------- 1 | namespace Swifter.Test.WPF.Tests 2 | { 3 | public class StringTest : BaseTest 4 | { 5 | public override string GetObject() 6 | { 7 | return new RandomValueReader(1218).ReadString(); 8 | } 9 | } 10 | 11 | } -------------------------------------------------------------------------------- /Swifter.Core/Formatters/IFormatterReader.cs: -------------------------------------------------------------------------------- 1 | 2 | using Swifter.RW; 3 | 4 | namespace Swifter.Formatters 5 | { 6 | /// 7 | /// 表示格式化读取器,继承此接口以得到格式化强大的扩展功能。 8 | /// 9 | public interface IFormatterReader: IValueReader, ITargetedBind 10 | { 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /Swifter.Core/Formatters/IFormatterWriter.cs: -------------------------------------------------------------------------------- 1 | using Swifter.RW; 2 | 3 | 4 | namespace Swifter.Formatters 5 | { 6 | /// 7 | /// 表示格式化写入器,继承此接口以得到格式化强大的扩展功能。 8 | /// 9 | public interface IFormatterWriter: IValueWriter, ITargetedBind 10 | { 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /Swifter.Extensions.AspNetCore/SwifterExtensions.Fw.cs: -------------------------------------------------------------------------------- 1 | 2 | #if NETFRAMEWORK 3 | 4 | using Swifter.Json; 5 | using System; 6 | using System.Text; 7 | using System.Web.Mvc; 8 | 9 | using static SwifterExtensions; 10 | 11 | public static partial class SwifterExtensions 12 | { 13 | } 14 | 15 | #endif -------------------------------------------------------------------------------- /Swifter.Json/JsonArrayAppendingInfo.cs: -------------------------------------------------------------------------------- 1 | using Swifter.Tools; 2 | 3 | namespace Swifter.Json 4 | { 5 | static class JsonArrayAppendingInfo 6 | { 7 | public static ArrayAppendingInfo AppendingInfo = new ArrayAppendingInfo { MostClosestMeanCommonlyUsedLength = 3 }; 8 | } 9 | } 10 | -------------------------------------------------------------------------------- /Swifter.Core/Tools/Convert/FromDBNullConvert.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | namespace Swifter.Tools 4 | { 5 | internal sealed class FromDBNullConvert : IXConverter 6 | { 7 | public T Convert(DBNull value) 8 | { 9 | return default; 10 | } 11 | } 12 | } -------------------------------------------------------------------------------- /Swifter.Test/UnsafeClass.cs: -------------------------------------------------------------------------------- 1 | namespace Swifter.Test 2 | { 3 | unsafe class UnsafeClass 4 | { 5 | public string Name { get; set; } 6 | 7 | public int Count { get; set; } 8 | 9 | public void* Pointer { get; set; } 10 | 11 | public void* Address { get; set; } 12 | } 13 | } -------------------------------------------------------------------------------- /Swifter.Core/Tools/Convert/ToDBNullConvert.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | namespace Swifter.Tools 4 | { 5 | internal sealed class ToDBNullConvert : IXConverter 6 | { 7 | public DBNull Convert(T value) => value is null ? DBNull.Value : throw new InvalidOperationException("Unable convert a value to DBNull."); 8 | } 9 | } -------------------------------------------------------------------------------- /Swifter.Test.WPF/Tests/DecimalArray.cs: -------------------------------------------------------------------------------- 1 | using Swifter.RW; 2 | 3 | namespace Swifter.Test.WPF.Tests 4 | { 5 | public class DecimalArray : BaseTest 6 | { 7 | public override decimal[] GetObject() 8 | { 9 | return new RandomValueReader(1812).ReadArray(); 10 | } 11 | } 12 | 13 | } -------------------------------------------------------------------------------- /Swifter.Test.WPF/StopwatchExtensions.cs: -------------------------------------------------------------------------------- 1 | using System.Diagnostics; 2 | 3 | namespace Swifter.Test.WPF 4 | { 5 | public static class StopwatchExtensions 6 | { 7 | public static double ElapsedNanoseconds(this Stopwatch stopwatch) 8 | { 9 | return stopwatch.ElapsedTicks * 100.0; 10 | } 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /Swifter.Test.WPF/Tests/TwoDimArray.cs: -------------------------------------------------------------------------------- 1 | using Swifter.RW; 2 | 3 | namespace Swifter.Test.WPF.Tests 4 | { 5 | public class TwoDimArray : BaseTest 6 | { 7 | public override int[,] GetObject() 8 | { 9 | return ValueInterface.ReadValue(new RandomValueReader(1218)); 10 | } 11 | } 12 | 13 | } -------------------------------------------------------------------------------- /Swifter.Test.WPF/Tests/ThreeDimArray.cs: -------------------------------------------------------------------------------- 1 | using Swifter.RW; 2 | 3 | namespace Swifter.Test.WPF.Tests 4 | { 5 | public class ThreeDimArray : BaseTest 6 | { 7 | public override int[,,] GetObject() 8 | { 9 | return ValueInterface.ReadValue(new RandomValueReader(1218)); 10 | } 11 | } 12 | 13 | } -------------------------------------------------------------------------------- /Swifter.Data/ConditionTypes.cs: -------------------------------------------------------------------------------- 1 | namespace Swifter.Data 2 | { 3 | /// 4 | /// T-SQL 条件连接符 5 | /// 6 | public enum ConditionTypes 7 | { 8 | /// 9 | /// AND 10 | /// 11 | And, 12 | /// 13 | /// OR 14 | /// 15 | Or 16 | } 17 | } -------------------------------------------------------------------------------- /Swifter.Test.WPF/Tests/Int64Array.cs: -------------------------------------------------------------------------------- 1 | using System.Data; 2 | using System.Linq; 3 | 4 | namespace Swifter.Test.WPF.Tests 5 | { 6 | public class Int64Array : BaseTest 7 | { 8 | public override long[] GetObject() 9 | { 10 | return Enumerable.Range(9999, 99999).Select(i=>(long)i).ToArray(); 11 | } 12 | } 13 | 14 | } -------------------------------------------------------------------------------- /Swifter.Core/Swifter.Core.csproj.user: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | <_LastSelectedProfileId>C:\Users\X\source\Repos\Swifter.Privete\Swifter.Core\Properties\PublishProfiles\FolderProfile.pubxml 5 | 6 | -------------------------------------------------------------------------------- /Swifter.Data/Swifter.Data.csproj.user: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | <_LastSelectedProfileId>C:\Users\X\source\Repos\Swifter.Privete\Swifter.Data\Properties\PublishProfiles\FolderProfile.pubxml 5 | 6 | -------------------------------------------------------------------------------- /Swifter.Json/Swifter.Json.csproj.user: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | <_LastSelectedProfileId>C:\Users\X\source\Repos\Swifter.Privete\Swifter.Json\Properties\PublishProfiles\FolderProfile.pubxml 5 | 6 | -------------------------------------------------------------------------------- /Swifter.MessagePack/MessagePackDeserializeModes.cs: -------------------------------------------------------------------------------- 1 | using System.Collections.Generic; 2 | 3 | namespace Swifter.MessagePack 4 | { 5 | static class MessagePackDeserializeModes 6 | { 7 | public struct StandardMode { } 8 | 9 | public struct ReferenceMode 10 | { 11 | public Dictionary References; 12 | } 13 | } 14 | } -------------------------------------------------------------------------------- /Swifter.Data/SqlServer/SqlBuilderFactory.cs: -------------------------------------------------------------------------------- 1 | namespace Swifter.Data.SqlServer 2 | { 3 | sealed class SqlBuilderFactory : Sql.SqlBuilderFactory 4 | { 5 | public override string ProviderName => "System.Data.SqlClient"; 6 | 7 | public override Sql.SqlBuilder CreateSqlBuilder() 8 | { 9 | return new SqlBuilder(); 10 | } 11 | } 12 | } -------------------------------------------------------------------------------- /Swifter.Core/Tools/Number/ThreeChar.cs: -------------------------------------------------------------------------------- 1 | 2 | #pragma warning disable 0649 3 | 4 | using System.Runtime.InteropServices; 5 | 6 | namespace Swifter.Tools 7 | { 8 | [StructLayout(LayoutKind.Sequential, Size = sizeof(char) * 3)] 9 | internal struct ThreeChar 10 | { 11 | public char char1; 12 | public char char2; 13 | public char char3; 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /Swifter.Data/DatabaseEventHandler.cs: -------------------------------------------------------------------------------- 1 | namespace Swifter.Data 2 | { 3 | /// 4 | /// Database 的事件委托。 5 | /// 6 | /// 事件参数类型 7 | /// 事件触发者 8 | /// 事件参数 9 | public delegate void DatabaseEventHandler(Database sender, TEventArgs args); 10 | 11 | } 12 | -------------------------------------------------------------------------------- /Swifter.Extensions.AspNetCore/Swifter.Extensions.AspNetCore.csproj.user: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | IIS Express 5 | FolderProfile 6 | 7 | -------------------------------------------------------------------------------- /Swifter.MessagePack/Swifter.MessagePack.csproj.user: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | <_LastSelectedProfileId>C:\Users\X\source\Repos\Swifter.Privete\Swifter.MessagePack\Properties\PublishProfiles\FolderProfile.pubxml 5 | 6 | -------------------------------------------------------------------------------- /Swifter.Test.WPF/Tests/DoubleArray.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Data; 3 | using System.Linq; 4 | 5 | namespace Swifter.Test.WPF.Tests 6 | { 7 | public class DoubleArray : BaseTest 8 | { 9 | public override double[] GetObject() 10 | { 11 | return Enumerable.Range(0, 99999).Select(i => Math.Pow(i, 12)).ToArray(); 12 | } 13 | } 14 | 15 | } -------------------------------------------------------------------------------- /Swifter.Data/SqlServer/MicrosoftSqlBuilderFactory.cs: -------------------------------------------------------------------------------- 1 | namespace Swifter.Data.SqlServer 2 | { 3 | sealed class MicrosoftSqlBuilderFactory : Sql.SqlBuilderFactory 4 | { 5 | public override string ProviderName => "Microsoft.Data.SqlClient"; 6 | 7 | public override Sql.SqlBuilder CreateSqlBuilder() 8 | { 9 | return new SqlBuilder(); 10 | } 11 | } 12 | } -------------------------------------------------------------------------------- /Swifter.MessagePack/MessagePackSerializeModes.cs: -------------------------------------------------------------------------------- 1 | using Swifter.Tools; 2 | using System.Collections.Generic; 3 | 4 | namespace Swifter.MessagePack 5 | { 6 | static class MessagePackSerializeModes 7 | { 8 | public struct StandardMode { } 9 | 10 | public struct ReferenceMode 11 | { 12 | public Dictionary References; 13 | } 14 | } 15 | } -------------------------------------------------------------------------------- /Swifter.Test.WPF/Tests/SingleArray.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Data; 3 | using System.Linq; 4 | 5 | namespace Swifter.Test.WPF.Tests 6 | { 7 | public class SingleArray : BaseTest 8 | { 9 | public override float[] GetObject() 10 | { 11 | return Enumerable.Range(0, 1630).Select(i => (float)Math.Pow(i, 12)).ToArray(); 12 | } 13 | } 14 | 15 | } -------------------------------------------------------------------------------- /Swifter.Data/MySql/SqlBuilderFactory.cs: -------------------------------------------------------------------------------- 1 | using Swifter.Data.Sql; 2 | 3 | namespace Swifter.Data.MySql 4 | { 5 | sealed class SqlBuilderFactory : Sql.SqlBuilderFactory 6 | { 7 | public override string ProviderName => "MySql.Data.MySqlClient"; 8 | 9 | public override Sql.SqlBuilder CreateSqlBuilder() 10 | { 11 | return new SqlBuilder(); 12 | } 13 | } 14 | } -------------------------------------------------------------------------------- /Swifter.FSharpExtensions/ExtensionLoader.cs: -------------------------------------------------------------------------------- 1 | 2 | using Swifter.FSharpExtensions; 3 | using Swifter.RW; 4 | 5 | namespace Swifter 6 | { 7 | /// 8 | /// FSharp 扩展加载器。 9 | /// 10 | static class ExtensionLoader 11 | { 12 | public static void Load() 13 | { 14 | ValueInterface.AddMaper(new FSharpInterfaceMaper()); 15 | } 16 | } 17 | } -------------------------------------------------------------------------------- /Swifter.FSharpExtensions/Swifter.FSharpExtensions.csproj.user: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | <_LastSelectedProfileId>C:\Users\X\source\Repos\Swifter.Privete\Swifter.FSharpExtensions\Properties\PublishProfiles\FolderProfile.pubxml 5 | 6 | -------------------------------------------------------------------------------- /Swifter.Test.WPF/Tests/PolymorphismTest.cs: -------------------------------------------------------------------------------- 1 | using Swifter.RW; 2 | using Swifter.Test.WPF.Models.Polymorphism; 3 | 4 | namespace Swifter.Test.WPF.Tests 5 | { 6 | public class PolymorphismTest : BaseTest 7 | { 8 | public override Polymorphism GetObject() 9 | { 10 | return new RandomValueReader(1218).FastReadObject(); 11 | } 12 | } 13 | 14 | } -------------------------------------------------------------------------------- /Swifter.Test/Resources/valueType.json: -------------------------------------------------------------------------------- 1 | { 2 | "Byte": 123, 3 | "SByte": -123, 4 | "Int16": -12345, 5 | "UInt16": 12345, 6 | "Int32": -123456789, 7 | "UInt32": 123456789, 8 | "Int64": -123456789123456789, 9 | "UInt64": 123456789123456789, 10 | "Single": 12.3456789e20, 11 | "Double": 12.3456789e200, 12 | "Decimal": 123456789123456789.123456789, 13 | "Guid": "E8E25451-EB0A-499F-8BBD-58309F923A53" 14 | } -------------------------------------------------------------------------------- /Swifter.Core/Reflection/IXFieldRW.cs: -------------------------------------------------------------------------------- 1 | 2 | using Swifter.RW; 3 | 4 | 5 | namespace Swifter.Reflection 6 | { 7 | interface IXFieldRW : IObjectField 8 | { 9 | void OnReadValue(object obj, IValueWriter valueWriter); 10 | 11 | void OnWriteValue(object obj, IValueReader valueReader); 12 | 13 | T ReadValue(object obj); 14 | 15 | void WriteValue(object obj, T value); 16 | } 17 | } -------------------------------------------------------------------------------- /Swifter.Test.WPF/Result.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | namespace Swifter.Test.WPF 4 | { 5 | public class Result 6 | { 7 | public readonly double avg; 8 | 9 | public Result(double avg) 10 | { 11 | this.avg = avg; 12 | } 13 | 14 | public override string ToString() 15 | { 16 | return $"{Math.Round(avg / 1000, 2)} us"; 17 | } 18 | } 19 | } -------------------------------------------------------------------------------- /Swifter.Core/Tools/Emit/SingleGroup.cs: -------------------------------------------------------------------------------- 1 | namespace Swifter.Tools 2 | { 3 | internal class SingleGroup : BaseGroup 4 | { 5 | public SingleGroup(CaseInfo value, IDifferenceComparer comparer) : base(comparer, 1) 6 | { 7 | Value = value; 8 | } 9 | 10 | public CaseInfo Value { get; private set; } 11 | 12 | public override int GetDepth() => 0; 13 | } 14 | } -------------------------------------------------------------------------------- /Swifter.Test.WPF/App.xaml.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Configuration; 4 | using System.Data; 5 | using System.Linq; 6 | using System.Threading.Tasks; 7 | using System.Windows; 8 | 9 | namespace Swifter.Test.WPF 10 | { 11 | /// 12 | /// Interaction logic for App.xaml 13 | /// 14 | public partial class App : Application 15 | { 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /Swifter.Test/Polymorphism.cs: -------------------------------------------------------------------------------- 1 | namespace Swifter.Test 2 | { 3 | 4 | public class Root 5 | { 6 | public int Count { get; set; } 7 | 8 | public int Id { get; set; } 9 | } 10 | 11 | public class Base : Root 12 | { 13 | public string Name { get; set; } 14 | } 15 | 16 | public class Polymorphism : Base 17 | { 18 | public new int Id { get; set; } 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /Swifter.Test.WPF/App.xaml: -------------------------------------------------------------------------------- 1 | 6 | 7 | 8 | 9 | 10 | -------------------------------------------------------------------------------- /Swifter.Core/RW/ArrayRW/IArrayCollectionRW.cs: -------------------------------------------------------------------------------- 1 | using Swifter.Tools; 2 | 3 | namespace Swifter.RW 4 | { 5 | /// 6 | /// 标识数组读写器的接口。 7 | /// 8 | public interface IArrayCollectionRW 9 | { 10 | /// 11 | /// 执行元素类型。 12 | /// 13 | /// 泛型执行器 14 | void InvokeElementType(IGenericInvoker invoker); 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /Swifter.Core/RW/ITargetedBind.cs: -------------------------------------------------------------------------------- 1 | namespace Swifter.RW 2 | { 3 | /// 4 | /// 表示支持针对性接口的对象。 5 | /// 6 | public interface ITargetedBind 7 | { 8 | /// 9 | /// 获取针对目标的 Id。 10 | /// 11 | long TargetedId { get; } 12 | 13 | /// 14 | /// 分配针对目标的 Id。 15 | /// 16 | void MakeTargetedId(); 17 | } 18 | } -------------------------------------------------------------------------------- /Swifter.Core/RW/IValueRW.cs: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | namespace Swifter.RW 5 | { 6 | /// 7 | /// 基础类型的值读写器 8 | /// 9 | public interface IValueRW : IValueReader, IValueWriter 10 | { 11 | } 12 | 13 | /// 14 | /// 自定义类型的值读写器 15 | /// 16 | /// 17 | public interface IValueRW :IValueReader, IValueWriter 18 | { 19 | } 20 | } -------------------------------------------------------------------------------- /Swifter.Test.WPF/Tests/DeviceModel.cs: -------------------------------------------------------------------------------- 1 | using Swifter.RW; 2 | using Swifter.Test.WPF.Models; 3 | 4 | namespace Swifter.Test.WPF.Tests 5 | { 6 | public class DeviceModel : BaseTest 7 | { 8 | public override string TestName => "Model"; 9 | 10 | public override Device GetObject() 11 | { 12 | return new RandomValueReader(1218).FastReadObject(); 13 | } 14 | } 15 | 16 | } -------------------------------------------------------------------------------- /Swifter.Core/Tools/Method/Jmp.cs: -------------------------------------------------------------------------------- 1 | using System.Runtime.InteropServices; 2 | 3 | namespace Swifter.Tools 4 | { 5 | [StructLayout(LayoutKind.Sequential, Pack = 1)] 6 | readonly struct Jmp 7 | { 8 | public readonly byte Command; 9 | public readonly int Offset; 10 | 11 | public unsafe Jmp(int offset) 12 | { 13 | Command = 0xe9; 14 | Offset = offset; 15 | } 16 | } 17 | } -------------------------------------------------------------------------------- /Swifter.Data/Sql/Function/Aggregate/AvgFunction.cs: -------------------------------------------------------------------------------- 1 | namespace Swifter.Data.Sql 2 | { 3 | /// 4 | /// Avg 聚合函数信息。 5 | /// 6 | public sealed class AvgFunction : AggregateFunction 7 | { 8 | /// 9 | /// 构建 Avg 聚合函数信息 10 | /// 11 | /// 聚合值 12 | public AvgFunction(IValue value) : base(value) 13 | { 14 | } 15 | } 16 | } -------------------------------------------------------------------------------- /Swifter.Data/Sql/Function/Aggregate/MaxFunction.cs: -------------------------------------------------------------------------------- 1 | namespace Swifter.Data.Sql 2 | { 3 | /// 4 | /// Max 聚合函数信息。 5 | /// 6 | public sealed class MaxFunction : AggregateFunction 7 | { 8 | /// 9 | /// 构建 Max 聚合函数信息 10 | /// 11 | /// 聚合值 12 | public MaxFunction(IValue value) : base(value) 13 | { 14 | } 15 | } 16 | } -------------------------------------------------------------------------------- /Swifter.Data/Sql/Function/Aggregate/MinFunction.cs: -------------------------------------------------------------------------------- 1 | namespace Swifter.Data.Sql 2 | { 3 | /// 4 | /// Min 聚合函数信息。 5 | /// 6 | public sealed class MinFunction : AggregateFunction 7 | { 8 | /// 9 | /// 构建 Min 聚合函数信息 10 | /// 11 | /// 聚合值 12 | public MinFunction(IValue value) : base(value) 13 | { 14 | } 15 | } 16 | } -------------------------------------------------------------------------------- /Swifter.Data/Sql/Function/Aggregate/SumFunction.cs: -------------------------------------------------------------------------------- 1 | namespace Swifter.Data.Sql 2 | { 3 | /// 4 | /// Sum 聚合函数信息。 5 | /// 6 | public sealed class SumFunction : AggregateFunction 7 | { 8 | /// 9 | /// 构建 Sum 聚合函数信息 10 | /// 11 | /// 聚合值 12 | public SumFunction(IValue value) : base(value) 13 | { 14 | } 15 | } 16 | } -------------------------------------------------------------------------------- /Swifter.Data/Sql/Function/String/LowerFunction.cs: -------------------------------------------------------------------------------- 1 | namespace Swifter.Data.Sql 2 | { 3 | /// 4 | /// 字符串 Lower 函数。 5 | /// 6 | public sealed class LowerFunction : UnaryFunction 7 | { 8 | /// 9 | /// 构建 Lower 函数信息。 10 | /// 11 | /// 参数 12 | public LowerFunction(IValue value) : base(value) 13 | { 14 | } 15 | } 16 | } -------------------------------------------------------------------------------- /Swifter.Data/Sql/Function/String/UpperFunction.cs: -------------------------------------------------------------------------------- 1 | namespace Swifter.Data.Sql 2 | { 3 | /// 4 | /// 字符串 Upper 函数。 5 | /// 6 | public sealed class UpperFunction : UnaryFunction 7 | { 8 | /// 9 | /// 构建 Upper 函数信息。 10 | /// 11 | /// 参数 12 | public UpperFunction(IValue value) : base(value) 13 | { 14 | } 15 | } 16 | } -------------------------------------------------------------------------------- /Swifter.Core/RW/Basic/ByteInterface.cs: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | namespace Swifter.RW 5 | { 6 | internal sealed class ByteInterface : IValueInterface 7 | { 8 | public byte ReadValue(IValueReader valueReader) 9 | { 10 | return valueReader.ReadByte(); 11 | } 12 | 13 | public void WriteValue(IValueWriter valueWriter, byte value) 14 | { 15 | valueWriter.WriteByte(value); 16 | } 17 | } 18 | } -------------------------------------------------------------------------------- /Swifter.Core/RW/Basic/CharInterface.cs: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | namespace Swifter.RW 5 | { 6 | internal sealed class CharInterface : IValueInterface 7 | { 8 | public char ReadValue(IValueReader valueReader) 9 | { 10 | return valueReader.ReadChar(); 11 | } 12 | 13 | public void WriteValue(IValueWriter valueWriter, char value) 14 | { 15 | valueWriter.WriteChar(value); 16 | } 17 | } 18 | } -------------------------------------------------------------------------------- /Swifter.Core/RW/FastObjectRW/IFastObjectRWCreater.cs: -------------------------------------------------------------------------------- 1 | namespace Swifter.RW 2 | { 3 | /// 4 | /// FastObjectRW 创建接口。 5 | /// 此接口由 Emit 实现。 6 | /// 7 | /// 8 | public interface IFastObjectRWCreater 9 | { 10 | /// 11 | /// 创建该类型的对象读写器。 12 | /// 13 | /// 返回该类型 14 | FastObjectRW Create(); 15 | } 16 | } -------------------------------------------------------------------------------- /Swifter.Data/DbRowsFlags.cs: -------------------------------------------------------------------------------- 1 | namespace Swifter.Data 2 | { 3 | /// 4 | /// 数据行集合标识符。 5 | /// 6 | public enum DbRowsFlags : byte 7 | { 8 | /// 9 | /// 表示此数据行集合中的每一行,在 OnReadAll 时都跳过 Null 值。 10 | /// 11 | SkipNull = 1, 12 | /// 13 | /// 表示此数据行集合中的每一行,在 OnReadAll 时都跳过 Default 值。 14 | /// 15 | SkipDefault = 2 16 | } 17 | } -------------------------------------------------------------------------------- /Swifter.Core/RW/Basic/Int32Interface.cs: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | namespace Swifter.RW 5 | { 6 | internal sealed class Int32Interface : IValueInterface 7 | { 8 | public int ReadValue(IValueReader valueReader) 9 | { 10 | return valueReader.ReadInt32(); 11 | } 12 | 13 | public void WriteValue(IValueWriter valueWriter, int value) 14 | { 15 | valueWriter.WriteInt32(value); 16 | } 17 | } 18 | } -------------------------------------------------------------------------------- /Swifter.Core/RW/Basic/Int64Interface.cs: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | namespace Swifter.RW 5 | { 6 | internal sealed class Int64Interface : IValueInterface 7 | { 8 | public long ReadValue(IValueReader valueReader) 9 | { 10 | return valueReader.ReadInt64(); 11 | } 12 | 13 | public void WriteValue(IValueWriter valueWriter, long value) 14 | { 15 | valueWriter.WriteInt64(value); 16 | } 17 | } 18 | } -------------------------------------------------------------------------------- /Swifter.Core/RW/RWBoolean.cs: -------------------------------------------------------------------------------- 1 | namespace Swifter.RW 2 | { 3 | /// 4 | /// 表示具有三个值的 Bool 配置项。 5 | /// 6 | public enum RWBoolean : byte 7 | { 8 | /// 9 | /// 未定义 10 | /// 11 | None, 12 | /// 13 | /// 是 14 | /// 15 | Yes, 16 | /// 17 | /// 否 18 | /// 19 | No 20 | } 21 | } -------------------------------------------------------------------------------- /Swifter.Data/Sql/Function/Aggregate/CountFunction.cs: -------------------------------------------------------------------------------- 1 | namespace Swifter.Data.Sql 2 | { 3 | /// 4 | /// Count 聚合函数信息。 5 | /// 6 | public sealed class CountFunction : AggregateFunction 7 | { 8 | /// 9 | /// 构建 Count 聚合函数信息 10 | /// 11 | /// 聚合值 12 | public CountFunction(IValue value) : base(value) 13 | { 14 | } 15 | } 16 | } -------------------------------------------------------------------------------- /Swifter.Json/JsonOutOfDepthException.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | namespace Swifter.Json 4 | { 5 | /// 6 | /// JSON 序列化或反序列化时结构深度超出最大深度的异常。 7 | /// 8 | public sealed class JsonOutOfDepthException : Exception 9 | { 10 | /// 11 | /// 构建实例 12 | /// 13 | public JsonOutOfDepthException() : base("Json struct depth out of the max depth.") 14 | { 15 | } 16 | } 17 | } -------------------------------------------------------------------------------- /Swifter.Core/RW/Basic/Int16Interface.cs: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | namespace Swifter.RW 5 | { 6 | internal sealed class Int16Interface : IValueInterface 7 | { 8 | public short ReadValue(IValueReader valueReader) 9 | { 10 | return valueReader.ReadInt16(); 11 | } 12 | 13 | public void WriteValue(IValueWriter valueWriter, short value) 14 | { 15 | valueWriter.WriteInt16(value); 16 | } 17 | } 18 | } -------------------------------------------------------------------------------- /Swifter.Core/RW/Basic/SByteInterface.cs: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | namespace Swifter.RW 5 | { 6 | internal sealed class SByteInterface : IValueInterface 7 | { 8 | public sbyte ReadValue(IValueReader valueReader) 9 | { 10 | return valueReader.ReadSByte(); 11 | } 12 | 13 | public void WriteValue(IValueWriter valueWriter, sbyte value) 14 | { 15 | valueWriter.WriteSByte(value); 16 | } 17 | } 18 | } -------------------------------------------------------------------------------- /Swifter.Core/RW/Basic/UInt32Interface.cs: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | namespace Swifter.RW 5 | { 6 | internal sealed class UInt32Interface : IValueInterface 7 | { 8 | public uint ReadValue(IValueReader valueReader) 9 | { 10 | return valueReader.ReadUInt32(); 11 | } 12 | 13 | public void WriteValue(IValueWriter valueWriter, uint value) 14 | { 15 | valueWriter.WriteUInt32(value); 16 | } 17 | } 18 | } -------------------------------------------------------------------------------- /Swifter.Core/RW/Basic/BooleanInterface.cs: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | namespace Swifter.RW 5 | { 6 | internal sealed class BooleanInterface : IValueInterface 7 | { 8 | public bool ReadValue(IValueReader valueReader) 9 | { 10 | return valueReader.ReadBoolean(); 11 | } 12 | 13 | public void WriteValue(IValueWriter valueWriter, bool value) 14 | { 15 | valueWriter.WriteBoolean(value); 16 | } 17 | } 18 | } -------------------------------------------------------------------------------- /Swifter.Core/RW/Basic/DoubleInterface.cs: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | namespace Swifter.RW 5 | { 6 | internal sealed class DoubleInterface : IValueInterface 7 | { 8 | public double ReadValue(IValueReader valueReader) 9 | { 10 | return valueReader.ReadDouble(); 11 | } 12 | 13 | public void WriteValue(IValueWriter valueWriter, double value) 14 | { 15 | valueWriter.WriteDouble(value); 16 | } 17 | } 18 | } -------------------------------------------------------------------------------- /Swifter.Core/RW/Basic/SingleInterface.cs: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | namespace Swifter.RW 5 | { 6 | internal sealed class SingleInterface : IValueInterface 7 | { 8 | public float ReadValue(IValueReader valueReader) 9 | { 10 | return valueReader.ReadSingle(); 11 | } 12 | 13 | public void WriteValue(IValueWriter valueWriter, float value) 14 | { 15 | valueWriter.WriteSingle(value); 16 | } 17 | } 18 | } -------------------------------------------------------------------------------- /Swifter.Core/RW/Basic/StringInterface.cs: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | namespace Swifter.RW 5 | { 6 | internal sealed class StringInterface : IValueInterface 7 | { 8 | public string ReadValue(IValueReader valueReader) 9 | { 10 | return valueReader.ReadString(); 11 | } 12 | 13 | public void WriteValue(IValueWriter valueWriter, string value) 14 | { 15 | valueWriter.WriteString(value); 16 | } 17 | } 18 | } -------------------------------------------------------------------------------- /Swifter.Core/RW/Basic/UInt16Interface.cs: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | namespace Swifter.RW 5 | { 6 | internal sealed class UInt16Interface : IValueInterface 7 | { 8 | public ushort ReadValue(IValueReader valueReader) 9 | { 10 | return valueReader.ReadUInt16(); 11 | } 12 | 13 | public void WriteValue(IValueWriter valueWriter, ushort value) 14 | { 15 | valueWriter.WriteUInt16(value); 16 | } 17 | } 18 | } -------------------------------------------------------------------------------- /Swifter.Core/RW/Basic/UInt64Interface.cs: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | namespace Swifter.RW 5 | { 6 | internal sealed class UInt64Interface : IValueInterface 7 | { 8 | public ulong ReadValue(IValueReader valueReader) 9 | { 10 | return valueReader.ReadUInt64(); 11 | } 12 | 13 | public void WriteValue(IValueWriter valueWriter, ulong value) 14 | { 15 | valueWriter.WriteUInt64(value); 16 | } 17 | } 18 | } -------------------------------------------------------------------------------- /Swifter.Data/OrderByDirections.cs: -------------------------------------------------------------------------------- 1 | namespace Swifter.Data 2 | { 3 | /// 4 | /// 排序方向。 5 | /// 6 | public enum OrderByDirections 7 | { 8 | /// 9 | /// 无方向,通常同 ASC。 10 | /// 11 | None, 12 | /// 13 | /// 升序。 14 | /// 15 | ASC, 16 | /// 17 | /// 降序。 18 | /// 19 | DESC 20 | } 21 | } -------------------------------------------------------------------------------- /Swifter.Test.WPF/Tests/Devices.cs: -------------------------------------------------------------------------------- 1 | using Swifter.RW; 2 | using Swifter.Test.WPF.Models; 3 | using System.Collections.Generic; 4 | 5 | namespace Swifter.Test.WPF.Tests 6 | { 7 | public class Devices : BaseTest> 8 | { 9 | public override string TestName => "List"; 10 | 11 | public override List GetObject() 12 | { 13 | return new RandomValueReader(1218).ReadList(); 14 | } 15 | } 16 | 17 | } -------------------------------------------------------------------------------- /Swifter.Core/Tools/Emit/BaseGroup.cs: -------------------------------------------------------------------------------- 1 | namespace Swifter.Tools 2 | { 3 | internal abstract class BaseGroup 4 | { 5 | public readonly IDifferenceComparer Comparer; 6 | 7 | public readonly int SortToken; 8 | 9 | public BaseGroup(IDifferenceComparer comparer, int sortToken) 10 | { 11 | Comparer = comparer; 12 | SortToken = sortToken; 13 | } 14 | 15 | public abstract int GetDepth(); 16 | } 17 | } -------------------------------------------------------------------------------- /Swifter.Core/RW/Basic/DecimalInterface.cs: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | namespace Swifter.RW 5 | { 6 | internal sealed class DecimalInterface : IValueInterface 7 | { 8 | public decimal ReadValue(IValueReader valueReader) 9 | { 10 | return valueReader.ReadDecimal(); 11 | } 12 | 13 | public void WriteValue(IValueWriter valueWriter, decimal value) 14 | { 15 | valueWriter.WriteDecimal(value); 16 | } 17 | } 18 | } -------------------------------------------------------------------------------- /Swifter.Test.WPF/Serializers/JilSerializer.cs: -------------------------------------------------------------------------------- 1 | namespace Swifter.Test.WPF.Serializers 2 | { 3 | public sealed class JilSerializer : BaseSerializer 4 | { 5 | public override TObject Deserialize(string symbols) 6 | { 7 | return Jil.JSON.Deserialize(symbols); 8 | } 9 | 10 | public override string Serialize(TObject obj) 11 | { 12 | return Jil.JSON.Serialize(obj); 13 | } 14 | } 15 | } -------------------------------------------------------------------------------- /Swifter.Data/Sql/Function/Number/ModFunction.cs: -------------------------------------------------------------------------------- 1 | namespace Swifter.Data.Sql 2 | { 3 | /// 4 | /// 求余函数。 5 | /// 6 | public sealed class ModFunction : BinaryFunction 7 | { 8 | /// 9 | /// 构建求余函数。 10 | /// 11 | /// 左值 12 | /// 右值 13 | public ModFunction(IValue left, IValue right) : base(left, right) 14 | { 15 | } 16 | } 17 | } -------------------------------------------------------------------------------- /Swifter.Data/Sql/Function/IfNullFunction.cs: -------------------------------------------------------------------------------- 1 | namespace Swifter.Data.Sql 2 | { 3 | /// 4 | /// 空合并函数。 5 | /// 6 | public sealed class IfNullFunction : BinaryFunction 7 | { 8 | /// 9 | /// 构建空合并函数。 10 | /// 11 | /// 左值 12 | /// 右值 13 | public IfNullFunction(IValue left, IValue right) : base(left, right) 14 | { 15 | } 16 | } 17 | } -------------------------------------------------------------------------------- /Swifter.Data/Sql/Function/Number/AddFunction.cs: -------------------------------------------------------------------------------- 1 | namespace Swifter.Data.Sql 2 | { 3 | /// 4 | /// 加法函数。 5 | /// 6 | public sealed class AddFunction : BinaryFunction 7 | { 8 | /// 9 | /// 构建加法函数信息。 10 | /// 11 | /// 值 1 12 | /// 值 2 13 | public AddFunction(IValue left, IValue right) : base(left, right) 14 | { 15 | } 16 | } 17 | } -------------------------------------------------------------------------------- /Swifter.Test.WPF/Swifter.Test.WPF.csproj.user: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | Designer 7 | 8 | 9 | 10 | 11 | Designer 12 | 13 | 14 | -------------------------------------------------------------------------------- /Swifter.Core/RW/Basic/DateTimeInterface.cs: -------------------------------------------------------------------------------- 1 | 2 | 3 | using System; 4 | 5 | namespace Swifter.RW 6 | { 7 | internal sealed class DateTimeInterface : IValueInterface 8 | { 9 | public DateTime ReadValue(IValueReader valueReader) 10 | { 11 | return valueReader.ReadDateTime(); 12 | } 13 | 14 | public void WriteValue(IValueWriter valueWriter, DateTime value) 15 | { 16 | valueWriter.WriteDateTime(value); 17 | } 18 | } 19 | } -------------------------------------------------------------------------------- /Swifter.Core/RW/IValueFilter.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | namespace Swifter.RW 4 | { 5 | /// 6 | /// 数据读取器的值筛选接口。 7 | /// 8 | /// 键类型。 9 | public interface IValueFilter 10 | { 11 | /// 12 | /// 值筛选方法。 13 | /// 14 | /// 值信息。 15 | /// 返回读取或不读取该值。 16 | bool Filter(ValueFilterInfo valueInfo); 17 | } 18 | } -------------------------------------------------------------------------------- /Swifter.Core/Tools/Convert/ValueToNullableConvert.cs: -------------------------------------------------------------------------------- 1 | namespace Swifter.Tools 2 | { 3 | internal sealed class ValueToNullableConvert : IXConverter where TDestination : struct 4 | { 5 | public TDestination? Convert(TSource value) 6 | { 7 | if (value is null) 8 | { 9 | return null; 10 | } 11 | 12 | return XConvert.Convert(value); 13 | } 14 | } 15 | } -------------------------------------------------------------------------------- /Swifter.Data/Sql/Function/Number/DivideFunction.cs: -------------------------------------------------------------------------------- 1 | namespace Swifter.Data.Sql 2 | { 3 | /// 4 | /// 除法函数。 5 | /// 6 | public sealed class DivideFunction : BinaryFunction 7 | { 8 | /// 9 | /// 构建除法函数信息。 10 | /// 11 | /// 左值 12 | /// 右值 13 | public DivideFunction(IValue left, IValue right) : base(left, right) 14 | { 15 | } 16 | } 17 | } -------------------------------------------------------------------------------- /Swifter.Data/Sql/Function/Number/MultiplyFunction.cs: -------------------------------------------------------------------------------- 1 | namespace Swifter.Data.Sql 2 | { 3 | /// 4 | /// 乘法函数。 5 | /// 6 | public sealed class MultiplyFunction : BinaryFunction 7 | { 8 | /// 9 | /// 构建乘法函数信息。 10 | /// 11 | /// 值 1 12 | /// 值 2 13 | public MultiplyFunction(IValue left, IValue right) : base(left, right) 14 | { 15 | } 16 | } 17 | } -------------------------------------------------------------------------------- /Swifter.Data/Sql/Function/Number/SubtractFunction.cs: -------------------------------------------------------------------------------- 1 | namespace Swifter.Data.Sql 2 | { 3 | /// 4 | /// 减法函数。 5 | /// 6 | public sealed class SubtractFunction : BinaryFunction 7 | { 8 | /// 9 | /// 构建减法函数信息。 10 | /// 11 | /// 左值 12 | /// 右值 13 | public SubtractFunction(IValue left, IValue right) : base(left, right) 14 | { 15 | } 16 | } 17 | } -------------------------------------------------------------------------------- /Swifter.MessagePack/MessagePackOutOfDepthException.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | namespace Swifter.MessagePack 4 | { 5 | /// 6 | /// MessagePack 序列化或反序列化时结构深度超出最大深度的异常。 7 | /// 8 | public sealed class MessagePackOutOfDepthException : Exception 9 | { 10 | /// 11 | /// 构建实例 12 | /// 13 | public MessagePackOutOfDepthException() : base("MessagePack struct depth out of the max depth.") 14 | { 15 | } 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /Swifter.Test.WPF/Tests/CatalogModel.cs: -------------------------------------------------------------------------------- 1 | using Swifter.Json; 2 | using Swifter.Test.WPF.Models; 3 | using System.IO; 4 | 5 | namespace Swifter.Test.WPF.Tests 6 | { 7 | public class CatalogModel : BaseTest 8 | { 9 | public override string TestName => "Catalog"; 10 | 11 | public override Catalog GetObject() 12 | { 13 | return JsonFormatter.DeserializeObject(File.ReadAllText(@"..\..\..\..\Swifter.Test\Resources\catalog.json")); 14 | } 15 | } 16 | 17 | } -------------------------------------------------------------------------------- /Swifter.Test.WPF/Tests/BaseTest.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | namespace Swifter.Test.WPF.Tests 4 | { 5 | public abstract class BaseTest : ITest 6 | { 7 | public virtual Type ObjectType => typeof(TObject); 8 | 9 | public virtual string TestName => GetType().Name; 10 | 11 | public abstract TObject GetObject(); 12 | 13 | public virtual bool Equals(TObject obj1, TObject obj2) 14 | { 15 | return TestHelper.Equals(obj1, obj2); 16 | } 17 | } 18 | 19 | } -------------------------------------------------------------------------------- /Swifter.Data/Sql/SqlBuilderFactory.cs: -------------------------------------------------------------------------------- 1 | namespace Swifter.Data.Sql 2 | { 3 | /// 4 | /// Sql 生成器工厂类。 5 | /// 6 | public abstract class SqlBuilderFactory 7 | { 8 | /// 9 | /// 获取供应商名称 10 | /// 11 | public abstract string ProviderName { get; } 12 | 13 | /// 14 | /// 创建 Sql 生成器。 15 | /// 16 | /// 17 | public abstract SqlBuilder CreateSqlBuilder(); 18 | } 19 | } -------------------------------------------------------------------------------- /Swifter.Extensions.AspNetCore/SwifterExtensions.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Threading.Tasks; 5 | 6 | /// 7 | /// Swifter 为 AspNet 提供的扩展方法。 8 | /// 9 | public static partial class SwifterExtensions 10 | { 11 | internal const string JSONContentType = "application/json"; 12 | 13 | internal static string GetNonEmptyString(string st1, string st2, string st3) => string.IsNullOrEmpty(st1) ? string.IsNullOrEmpty(st2) ? st3 : st2 : st1; 14 | } -------------------------------------------------------------------------------- /Swifter.Test.WPF/Tests/DevicesDataTable.cs: -------------------------------------------------------------------------------- 1 | using Swifter.RW; 2 | using Swifter.Test.WPF.Models; 3 | using System.Data; 4 | 5 | namespace Swifter.Test.WPF.Tests 6 | { 7 | public class DevicesDataTable : BaseTest 8 | { 9 | public override string TestName => "DataTable"; 10 | 11 | public override DataTable GetObject() 12 | { 13 | return ValueCopyer.ValueOf(new RandomValueReader(1218).ReadList()).ReadDataTable().IdentifyColumnTypes(); 14 | } 15 | } 16 | 17 | } -------------------------------------------------------------------------------- /Swifter.Test.WPF/Serializers/FastJSONSerializer.cs: -------------------------------------------------------------------------------- 1 | namespace Swifter.Test.WPF.Serializers 2 | { 3 | //public sealed class FastJSONSerializer : BaseSerializer 4 | //{ 5 | // public override TObject Deserialize(string symbols) 6 | // { 7 | // return fastJSON.JSON.ToObject(symbols); 8 | // } 9 | 10 | // public override string Serialize(TObject obj) 11 | // { 12 | // return fastJSON.JSON.ToJSON(obj); 13 | // } 14 | //} 15 | } 16 | -------------------------------------------------------------------------------- /Swifter.Core/Tools/Convert/NullableToValueConvert.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | namespace Swifter.Tools 4 | { 5 | internal sealed class NullableToValueConvert : IXConverter where TSource : struct 6 | { 7 | public TDestination Convert(TSource? value) 8 | { 9 | if (value == null) 10 | { 11 | return default; 12 | } 13 | 14 | return XConvert.Convert(value.Value); 15 | } 16 | } 17 | } -------------------------------------------------------------------------------- /Swifter.Test.WPF/Serializers/Utf8JsonSerializer.cs: -------------------------------------------------------------------------------- 1 | namespace Swifter.Test.WPF.Serializers 2 | { 3 | public sealed class Utf8JsonSerializer : BaseSerializer 4 | { 5 | public override TObject Deserialize(byte[] symbols) 6 | { 7 | return Utf8Json.JsonSerializer.Deserialize(symbols); 8 | } 9 | 10 | public override byte[] Serialize(TObject obj) 11 | { 12 | return Utf8Json.JsonSerializer.Serialize(obj); 13 | } 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /Swifter.Data/Sql/Value/VariableValue.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | namespace Swifter.Data.Sql 4 | { 5 | /// 6 | /// 表示一个变量值。 7 | /// 8 | public sealed class VariableValue : IValue 9 | { 10 | private readonly Func Getter; 11 | 12 | /// 13 | /// 获取该变量的当前值。 14 | /// 15 | public IValue Value => Getter(); 16 | 17 | internal VariableValue(Func getter) 18 | { 19 | Getter = getter; 20 | } 21 | } 22 | } -------------------------------------------------------------------------------- /Swifter.Test.WPF/Serializers/KoobooJsonSerializer.cs: -------------------------------------------------------------------------------- 1 | namespace Swifter.Test.WPF.Serializers 2 | { 3 | public sealed class KoobooJsonSerializer : BaseSerializer 4 | { 5 | public override TObject Deserialize(string symbols) 6 | { 7 | return Kooboo.Json.JsonSerializer.ToObject(symbols); 8 | } 9 | 10 | public override string Serialize(TObject obj) 11 | { 12 | return Kooboo.Json.JsonSerializer.ToJson(obj); 13 | } 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /Swifter.Test.WPF/Serializers/LitJsonSerializer.cs: -------------------------------------------------------------------------------- 1 | namespace Swifter.Test.WPF.Serializers 2 | { 3 | //public sealed class LitJsonSerializer : BaseSerializer 4 | //{ 5 | // public override TObject Deserialize(string symbols) 6 | // { 7 | // return LitJson.JsonMapper.ToObject(symbols); 8 | // } 9 | 10 | // public override string Serialize(TObject obj) 11 | // { 12 | // return LitJson.JsonMapper.ToJson(obj); 13 | // } 14 | //} 15 | } 16 | -------------------------------------------------------------------------------- /Swifter.Test.WPF/Serializers/NetJsonSerializer.cs: -------------------------------------------------------------------------------- 1 | namespace Swifter.Test.WPF.Serializers 2 | { 3 | //public sealed class NetJsonSerializer : BaseSerializer 4 | //{ 5 | // public override TObject Deserialize(string symbols) 6 | // { 7 | // return NetJSON.NetJSON.Deserialize(symbols); 8 | // } 9 | 10 | // public override string Serialize(TObject obj) 11 | // { 12 | // return NetJSON.NetJSON.Serialize(obj); 13 | // } 14 | //} 15 | } 16 | -------------------------------------------------------------------------------- /Swifter.Core/Properties/PublishProfiles/FolderProfile.pubxml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 6 | 7 | FileSystem 8 | Release 9 | Any CPU 10 | net20 11 | ..\publish\ 12 | 13 | -------------------------------------------------------------------------------- /Swifter.Data/Properties/PublishProfiles/FolderProfile.pubxml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 6 | 7 | FileSystem 8 | Release 9 | Any CPU 10 | net20 11 | ..\publish\ 12 | 13 | -------------------------------------------------------------------------------- /Swifter.Json/Properties/PublishProfiles/FolderProfile.pubxml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 6 | 7 | FileSystem 8 | Release 9 | Any CPU 10 | net20 11 | ..\publish\ 12 | 13 | -------------------------------------------------------------------------------- /Swifter.MessagePack/Properties/PublishProfiles/FolderProfile.pubxml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 6 | 7 | FileSystem 8 | Release 9 | Any CPU 10 | net20 11 | ..\publish\ 12 | 13 | -------------------------------------------------------------------------------- /Swifter.Test.WPF/Serializers/AutoCSerJsonSerializer.cs: -------------------------------------------------------------------------------- 1 | namespace Swifter.Test.WPF.Serializers 2 | { 3 | //public sealed class AutoCSerJsonSerializer : BaseSerializer 4 | //{ 5 | // public override TObject Deserialize(string symbols) 6 | // { 7 | // return AutoCSer.Json.Parser.Parse(symbols); 8 | // } 9 | 10 | // public override string Serialize(TObject obj) 11 | // { 12 | // return AutoCSer.Json.Serializer.Serialize(obj); 13 | // } 14 | //} 15 | } 16 | -------------------------------------------------------------------------------- /Swifter.Debug/MyConfig.cs: -------------------------------------------------------------------------------- 1 | #if BenchmarkDotNet 2 | 3 | using BenchmarkDotNet.Configs; 4 | using BenchmarkDotNet.Diagnosers; 5 | using BenchmarkDotNet.Jobs; 6 | using BenchmarkDotNet.Order; 7 | 8 | namespace Swifter.Debug 9 | { 10 | public class MyConfig : ManualConfig 11 | { 12 | public MyConfig() 13 | { 14 | AddJob(Job.Default.WithUnrollFactor(2)); 15 | 16 | AddDiagnoser(MemoryDiagnoser.Default); 17 | 18 | Orderer = new DefaultOrderer(SummaryOrderPolicy.Method); 19 | } 20 | } 21 | } 22 | #endif -------------------------------------------------------------------------------- /Swifter.Test.WPF/Serializers/SpanJsonSerializer.cs: -------------------------------------------------------------------------------- 1 | namespace Swifter.Test.WPF.Serializers 2 | { 3 | public sealed class SpanJsonSerializer : BaseSerializer 4 | { 5 | public override TObject Deserialize(string symbols) 6 | { 7 | return SpanJson.JsonSerializer.Generic.Utf16.Deserialize(symbols); 8 | } 9 | 10 | public override string Serialize(TObject obj) 11 | { 12 | return SpanJson.JsonSerializer.Generic.Utf16.Serialize(obj); 13 | } 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /Swifter.Test.WPF/Serializers/SystemTextJsonSerializer.cs: -------------------------------------------------------------------------------- 1 | namespace Swifter.Test.WPF.Serializers 2 | { 3 | public sealed class SystemTextJsonSerializer : BaseSerializer 4 | { 5 | public override TObject Deserialize(string symbols) 6 | { 7 | return System.Text.Json.JsonSerializer.Deserialize(symbols); 8 | } 9 | 10 | public override string Serialize(TObject obj) 11 | { 12 | return System.Text.Json.JsonSerializer.Serialize(obj); 13 | } 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /Swifter.Data/Sql/Select/JoinDirections.cs: -------------------------------------------------------------------------------- 1 | namespace Swifter.Data.Sql 2 | { 3 | /// 4 | /// 表连接方向 5 | /// 6 | public enum JoinDirections 7 | { 8 | /// 9 | /// 左连接 10 | /// 11 | Left, 12 | /// 13 | /// 右连接 14 | /// 15 | Right, 16 | /// 17 | /// 内连接 18 | /// 19 | Inner, 20 | /// 21 | /// 全连接 22 | /// 23 | Full 24 | } 25 | } -------------------------------------------------------------------------------- /Swifter.FSharpExtensions/Properties/PublishProfiles/FolderProfile.pubxml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 6 | 7 | FileSystem 8 | Release 9 | Any CPU 10 | netstandard2.0 11 | ..\publish\ 12 | 13 | -------------------------------------------------------------------------------- /Swifter.Test.WPF/Serializers/NewtonsoftJsonSerializer.cs: -------------------------------------------------------------------------------- 1 | using Newtonsoft.Json; 2 | 3 | namespace Swifter.Test.WPF.Serializers 4 | { 5 | public sealed class NewtonsoftJsonSerializer : BaseSerializer 6 | { 7 | public override TObject Deserialize(string symbols) 8 | { 9 | return JsonConvert.DeserializeObject(symbols); 10 | } 11 | 12 | public override string Serialize(TObject obj) 13 | { 14 | return JsonConvert.SerializeObject(obj); 15 | } 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /Swifter.Core/Tools/Convert/ParseEnum.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | namespace Swifter.Tools 4 | { 5 | internal sealed class ParseEnum : IXConverter where TDestination:struct 6 | { 7 | public TDestination Convert(string value) 8 | { 9 | #if FullParse 10 | 11 | if (Enum.TryParse(value, out var result)) 12 | { 13 | return result; 14 | } 15 | 16 | #endif 17 | return (TDestination)Enum.Parse(typeof(TDestination), value); 18 | } 19 | } 20 | } -------------------------------------------------------------------------------- /Swifter.Test.WPF/Tests/Int32Array.cs: -------------------------------------------------------------------------------- 1 | using System.Collections.Generic; 2 | using System.Linq; 3 | 4 | namespace Swifter.Test.WPF.Tests 5 | { 6 | public class Int32Array : BaseTest 7 | { 8 | public override int[] GetObject() 9 | { 10 | return Enumerable.Range(1, 9999).ToArray(); 11 | } 12 | } 13 | 14 | public class Int32Enumerable : BaseTest> 15 | { 16 | public override IEnumerable GetObject() 17 | { 18 | return Enumerable.Range(1, 1000); 19 | } 20 | } 21 | } -------------------------------------------------------------------------------- /Swifter.Core/RW/IValueInterfaceMaper.cs: -------------------------------------------------------------------------------- 1 | namespace Swifter.RW 2 | { 3 | /// 4 | /// 提供类型与 IValueInterface 的匹配器。 5 | /// 实现它,并使用 ValueInterface.AddMaper 添加它的实例即可自定义类型的读写方法。 6 | /// 7 | public interface IValueInterfaceMaper 8 | { 9 | /// 10 | /// 类型与 IValueInterface 的匹配方法。 11 | /// 匹配成功则返回实例,不成功则返回 Null。 12 | /// 13 | /// 指定类型 14 | /// 返回一个 IValueInterface/ 实例 15 | IValueInterface TryMap(); 16 | } 17 | } -------------------------------------------------------------------------------- /Swifter.Data/Sql/Function/UnaryFunction.cs: -------------------------------------------------------------------------------- 1 | namespace Swifter.Data.Sql 2 | { 3 | /// 4 | /// 一元函数。 5 | /// 6 | public abstract class UnaryFunction : IValue 7 | { 8 | /// 9 | /// 一元函数的参数。 10 | /// 11 | public IValue Value { get; set; } 12 | 13 | /// 14 | /// 构建一元函数。 15 | /// 16 | /// 一元函数的参数 17 | public UnaryFunction(IValue value) 18 | { 19 | Value = value; 20 | } 21 | } 22 | } -------------------------------------------------------------------------------- /Swifter.Test.WPF/Serializers/NeueccMessagePackSerializer.cs: -------------------------------------------------------------------------------- 1 | using MessagePack; 2 | 3 | namespace Swifter.Test.WPF.Serializers 4 | { 5 | public sealed class NeueccMessagePackSerializer : BaseSerializer 6 | { 7 | public override TObject Deserialize(byte[] symbols) 8 | { 9 | return MessagePackSerializer.Deserialize(symbols); 10 | } 11 | 12 | public override byte[] Serialize(TObject obj) 13 | { 14 | return MessagePackSerializer.Serialize(obj); 15 | } 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /Swifter.Data/Sql/Function/String/ConcatFunction.cs: -------------------------------------------------------------------------------- 1 | namespace Swifter.Data.Sql 2 | { 3 | /// 4 | /// 拼接字符串函数。 5 | /// 6 | public sealed class ConcatFunction 7 | { 8 | /// 9 | /// 构建拼接字符串函数。 10 | /// 11 | /// 值数组 12 | public ConcatFunction(IValue[] values) 13 | { 14 | Values = values; 15 | } 16 | 17 | /// 18 | /// 值数组。 19 | /// 20 | public IValue[] Values { get; set; } 21 | } 22 | } -------------------------------------------------------------------------------- /Swifter.Test.WPF/Tests/DeviceDictionary.cs: -------------------------------------------------------------------------------- 1 | using Swifter.RW; 2 | using Swifter.Test.WPF.Models; 3 | using System.Collections.Generic; 4 | 5 | namespace Swifter.Test.WPF.Tests 6 | { 7 | public class DeviceDictionary : BaseTest> 8 | { 9 | public override string TestName => "Dictionary"; 10 | 11 | public override Dictionary GetObject() 12 | { 13 | return ValueCopyer.ValueOf(new RandomValueReader(1218).FastReadObject()).ReadDictionary(); 14 | } 15 | } 16 | 17 | } -------------------------------------------------------------------------------- /Swifter.Core/Tools/Convert/IConverterFactory.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | namespace Swifter.Tools 4 | { 5 | /// 6 | /// 转换器工厂接口。 7 | /// 8 | public interface IConverterFactory 9 | { 10 | /// 11 | /// 获取转换器实例,实例应实现 接口。 12 | /// 13 | /// 原类型 14 | /// 目标类型 15 | /// 返回转换器实例 16 | object GetConverter(Type sourceType, Type destinationType); 17 | } 18 | } -------------------------------------------------------------------------------- /Swifter.Data/Sql/Function/Aggregate/AggregateFunction.cs: -------------------------------------------------------------------------------- 1 | namespace Swifter.Data.Sql 2 | { 3 | /// 4 | /// 聚合函数 5 | /// 6 | public abstract class AggregateFunction : IValue 7 | { 8 | /// 9 | /// 聚合值 10 | /// 11 | public IValue Value { get; } 12 | 13 | /// 14 | /// 聚合函数必要的构造参数 15 | /// 16 | /// 聚合值 17 | protected AggregateFunction(IValue value) 18 | { 19 | Value = value; 20 | } 21 | } 22 | } -------------------------------------------------------------------------------- /Swifter.Core/Tools/Type/ReferenceComparer.cs: -------------------------------------------------------------------------------- 1 | using System.Collections.Generic; 2 | using System.Runtime.CompilerServices; 3 | 4 | namespace Swifter.Tools 5 | { 6 | sealed class ReferenceComparer : IEqualityComparer 7 | { 8 | public static readonly ReferenceComparer Instance = new ReferenceComparer(); 9 | 10 | public new bool Equals(object x, object y) 11 | { 12 | return x == y; 13 | } 14 | 15 | public int GetHashCode(object obj) 16 | { 17 | return RuntimeHelpers.GetHashCode(obj); 18 | } 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /Swifter.Debug/Swifter.Debug.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | Exe 5 | netcoreapp3.0 6 | true 7 | preview 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | -------------------------------------------------------------------------------- /Swifter.Test.WPF/Serializers/ServiceStackSerializer.cs: -------------------------------------------------------------------------------- 1 | namespace Swifter.Test.WPF.Serializers 2 | { 3 | //public sealed class ServiceStackSerializer : BaseSerializer 4 | //{ 5 | // public override TObject Deserialize(string symbols) 6 | // { 7 | // return ServiceStack.Text.JsonSerializer.DeserializeFromString(symbols); 8 | // } 9 | 10 | // public override string Serialize(TObject obj) 11 | // { 12 | // return ServiceStack.Text.JsonSerializer.SerializeToString(obj); 13 | // } 14 | //} 15 | } 16 | -------------------------------------------------------------------------------- /Swifter.Core/Tools/Convert/IXConvert.cs: -------------------------------------------------------------------------------- 1 | using System.ComponentModel; 2 | 3 | namespace Swifter.Tools 4 | { 5 | /// 6 | /// XConvert 实现接口。 7 | /// 8 | /// 原类型 9 | /// 目标类型 10 | public interface IXConverter 11 | { 12 | /// 13 | /// 将原类型的值转换为目标类型的值。 14 | /// 15 | /// 原类型的值 16 | /// 返回目标类型的值 17 | TDestination Convert(TSource value); 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /Swifter.Core/RW/Data/DataTableRWOptions.cs: -------------------------------------------------------------------------------- 1 | namespace Swifter.RW 2 | { 3 | /// 4 | /// DataTable 读写器的配置。 5 | /// 6 | public enum DataTableRWOptions 7 | { 8 | /// 9 | /// 默认配置项。 10 | /// 11 | None = 0, 12 | 13 | /// 14 | /// 设置第一行的数据类型为各个 Column 的类型。否则将设置 Object 为各个 Column 的类型。默认不开启。 15 | /// 16 | SetFirstRowsTypeToColumnTypes = 1, 17 | 18 | /// 19 | /// 设置第二行开始的数据写入为数组。 20 | /// 21 | WriteToArrayFromBeginningSecondRows = 2 22 | } 23 | } -------------------------------------------------------------------------------- /Swifter.Core/RW/RWFieldAccess.cs: -------------------------------------------------------------------------------- 1 | namespace Swifter.RW 2 | { 3 | /// 4 | /// 对象读写器的字段可访问性。 5 | /// 6 | public enum RWFieldAccess : byte 7 | { 8 | /// 9 | /// 表示此字段允许读写。 10 | /// 11 | RW = ReadOnly | WriteOnly, 12 | /// 13 | /// 表示忽略此字段。 14 | /// 15 | Ignore = 0, 16 | /// 17 | /// 表示此字段只能读。 18 | /// 19 | ReadOnly = 1, 20 | /// 21 | /// 表示此字段只能写。 22 | /// 23 | WriteOnly = 2 24 | } 25 | } -------------------------------------------------------------------------------- /Swifter.Test/CommonData.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | namespace Swifter.Test 4 | { 5 | public class CommonData 6 | { 7 | public int RowNum { get; set; } 8 | 9 | public int Id { get; set; } 10 | 11 | public string Name { get; set; } 12 | 13 | public string Type { get; set; } 14 | 15 | public int Sign { get; set; } 16 | 17 | public string Code { get; set; } 18 | 19 | public string CacheToken { get; set; } 20 | 21 | public string Description { get; set; } 22 | 23 | public string Demo { get; set; } 24 | 25 | public Guid Guid { get; set; } 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /Swifter.Test.WPF/AssemblyInfo.cs: -------------------------------------------------------------------------------- 1 | using System.Windows; 2 | 3 | [assembly: ThemeInfo( 4 | ResourceDictionaryLocation.None, //where theme specific resource dictionaries are located 5 | //(used if a resource is not found in the page, 6 | // or application resource dictionaries) 7 | ResourceDictionaryLocation.SourceAssembly //where the generic resource dictionary is located 8 | //(used if a resource is not found in the page, 9 | // app, or any theme specific resource dictionaries) 10 | )] 11 | -------------------------------------------------------------------------------- /Swifter.Core/VersionDifferences/DynamicAttribute.cs: -------------------------------------------------------------------------------- 1 | #if NET20 || NET35 2 | 3 | #pragma warning disable 1591 4 | 5 | using System.Collections.Generic; 6 | 7 | namespace System.Runtime.CompilerServices 8 | { 9 | /// 10 | /// 编译器必要的动态类型特性。 11 | /// 12 | public sealed class DynamicAttribute : Attribute 13 | { 14 | public DynamicAttribute() 15 | { 16 | 17 | } 18 | 19 | public DynamicAttribute(bool[] transformFlags) 20 | { 21 | TransformFlags = transformFlags; 22 | } 23 | 24 | public IList TransformFlags { get; set; } 25 | } 26 | } 27 | 28 | #endif -------------------------------------------------------------------------------- /Swifter.Json/JsonDeserializeException.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | namespace Swifter.Json 4 | { 5 | /// 6 | /// Json 反序列化出错时的异常信息。 7 | /// 8 | public sealed class JsonDeserializeException : Exception 9 | { 10 | /// 11 | /// 构建实例。 12 | /// 13 | /// 反序列化出错所在索引 14 | public JsonDeserializeException(int index) : base("Json deserialize failed.") 15 | { 16 | Index = index; 17 | } 18 | 19 | /// 20 | /// 反序列化出错所在索引。 21 | /// 22 | public int Index { get; } 23 | } 24 | } -------------------------------------------------------------------------------- /Swifter.Test.WPF/Models/Polymorphism.cs: -------------------------------------------------------------------------------- 1 | using MessagePack; 2 | using System; 3 | using System.Collections.Generic; 4 | using System.Text; 5 | 6 | namespace Swifter.Test.WPF.Models.Polymorphism 7 | { 8 | [MessagePackObject(true)] 9 | public class Root 10 | { 11 | public int Count { get; set; } 12 | 13 | public int Id { get; set; } 14 | } 15 | 16 | [MessagePackObject(true)] 17 | public class Base : Root 18 | { 19 | public string Name { get; set; } 20 | } 21 | 22 | [MessagePackObject(true)] 23 | public class Polymorphism : Base 24 | { 25 | public new int Id { get; set; } 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /Swifter.Core/RW/FastObjectRW/ErrorFastObjectRWCreater.cs: -------------------------------------------------------------------------------- 1 | using Swifter.Tools; 2 | using System; 3 | using System.Reflection; 4 | 5 | namespace Swifter.RW 6 | { 7 | sealed class ErrorFastObjectRWCreater : IFastObjectRWCreater 8 | { 9 | public Exception InnerException { get; } 10 | 11 | public ErrorFastObjectRWCreater(Exception innerException) 12 | { 13 | InnerException = innerException; 14 | } 15 | 16 | public FastObjectRW Create() 17 | { 18 | throw new TargetException($"Failed to create FastObjectRW of \"{typeof(T).FullName}\" type.", InnerException); 19 | } 20 | } 21 | } -------------------------------------------------------------------------------- /Swifter.MessagePack/MessagePackLoopReferencingException.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | namespace Swifter.MessagePack 4 | { 5 | /// 6 | /// MessagePack 序列化时出现循环引用引发的异常信息。 7 | /// 8 | public sealed class MessagePackLoopReferencingException : Exception 9 | { 10 | /// 11 | /// 出现循环引用的对象。 12 | /// 13 | public object LoopingObject { get; } 14 | 15 | /// 16 | /// 构建实例 17 | /// 18 | public MessagePackLoopReferencingException(object loopingObject) 19 | { 20 | LoopingObject = loopingObject; 21 | } 22 | } 23 | } -------------------------------------------------------------------------------- /Swifter.Test/BasicTypes.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | namespace Swifter.Test 4 | { 5 | public sealed class BasicTypes 6 | { 7 | public byte Byte { get; set; } 8 | public sbyte SByte { get; set; } 9 | public short Int16 { get; set; } 10 | public ushort UInt16 { get; set; } 11 | public int Int32 { get; set; } 12 | public uint UInt32 { get; set; } 13 | public long Int64 { get; set; } 14 | public ulong UInt64 { get; set; } 15 | public float Single { get; set; } 16 | public double Double { get; set; } 17 | public decimal Decimal { get; set; } 18 | public Guid Guid { get; set; } 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /Swifter.Core/RW/Basic/NullableInterface.cs: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | namespace Swifter.RW 5 | { 6 | internal sealed class NullableInterface : IValueInterface where T : struct 7 | { 8 | public T? ReadValue(IValueReader valueReader) 9 | { 10 | return valueReader.ReadNullable(); 11 | } 12 | 13 | public void WriteValue(IValueWriter valueWriter, T? value) 14 | { 15 | if (value is null) 16 | { 17 | valueWriter.DirectWrite(null); 18 | } 19 | else 20 | { 21 | ValueInterface.WriteValue(valueWriter, value.Value); 22 | } 23 | } 24 | } 25 | } -------------------------------------------------------------------------------- /Swifter.MessagePack/MessagePackDeserializeException.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | namespace Swifter.MessagePack 4 | { 5 | /// 6 | /// MessagePack 反序列化出错时的异常信息。 7 | /// 8 | public class MessagePackDeserializeException : Exception 9 | { 10 | /// 11 | /// 反序列化出错所在索引。 12 | /// 13 | public int Index { get; } 14 | 15 | /// 16 | /// 构建实例。 17 | /// 18 | /// 反序列化出错所在索引 19 | public MessagePackDeserializeException(int index) : base("MessagePack deserialize failed.") 20 | { 21 | Index = index; 22 | } 23 | } 24 | } -------------------------------------------------------------------------------- /Swifter.Test.WPF/ExceptionResult.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | namespace Swifter.Test.WPF 4 | { 5 | public class ExceptionResult 6 | { 7 | public readonly Exception e; 8 | 9 | public ExceptionResult(Exception e) 10 | { 11 | this.e = e; 12 | } 13 | 14 | public override string ToString() 15 | { 16 | if (e is IncorrectException) 17 | { 18 | return "Error"; 19 | } 20 | else if (e is TimeoutException) 21 | { 22 | return "Timeout"; 23 | } 24 | else 25 | { 26 | return "Exception"; 27 | } 28 | } 29 | } 30 | } -------------------------------------------------------------------------------- /Swifter.Core/RW/Basic/DbNullInterface.cs: -------------------------------------------------------------------------------- 1 | 2 | 3 | using System; 4 | 5 | namespace Swifter.RW 6 | { 7 | internal sealed class DbNullInterface : IValueInterface 8 | { 9 | public DBNull ReadValue(IValueReader valueReader) 10 | { 11 | var value = valueReader.DirectRead(); 12 | 13 | if (value is null || value == DBNull.Value) 14 | { 15 | return DBNull.Value; 16 | } 17 | 18 | throw new NotSupportedException("Unable convert value to DbNull."); 19 | } 20 | 21 | public void WriteValue(IValueWriter valueWriter, DBNull value) 22 | { 23 | valueWriter.DirectWrite(null); 24 | } 25 | } 26 | } -------------------------------------------------------------------------------- /Swifter.Core/Tools/Number/GuidStruct.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Runtime.InteropServices; 3 | 4 | namespace Swifter.Tools 5 | { 6 | [StructLayout(LayoutKind.Sequential)] 7 | [Serializable] 8 | internal struct GuidStruct 9 | { 10 | public byte _a4; 11 | public byte _a3; 12 | public byte _a2; 13 | public byte _a1; 14 | public byte _b2; 15 | public byte _b1; 16 | public byte _c2; 17 | public byte _c1; 18 | public byte _d; 19 | public byte _e; 20 | public byte _f; 21 | public byte _g; 22 | public byte _h; 23 | public byte _i; 24 | public byte _j; 25 | public byte _k; 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /Swifter.Data/Sql/Value/ConstantValue.cs: -------------------------------------------------------------------------------- 1 | namespace Swifter.Data.Sql 2 | { 3 | /// 4 | /// 表示一个常量值。 5 | /// 6 | /// 7 | public sealed class ConstantValue : IValue 8 | { 9 | /// 10 | /// 值 11 | /// 12 | public T Value { get; } 13 | 14 | /// 15 | /// 获取该值的字符串表现形式。 16 | /// 17 | /// 返回一个字符串 18 | public override string ToString() 19 | { 20 | return Value?.ToString(); 21 | } 22 | 23 | internal ConstantValue(T value) 24 | { 25 | Value = value; 26 | } 27 | } 28 | } -------------------------------------------------------------------------------- /Swifter.FSharpTest/Swifter.FSharpTest.fsproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | Exe 5 | netcoreapp3.1 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | -------------------------------------------------------------------------------- /Swifter.Core/Tools/Number/ParseCode.cs: -------------------------------------------------------------------------------- 1 | namespace Swifter.Tools 2 | { 3 | /// 4 | /// 解析的结果代码。 5 | /// 6 | public enum ParseCode 7 | { 8 | /// 9 | /// 正常解析。 10 | /// 11 | Success = 0, 12 | 13 | /// 14 | /// 出现超出基数范围内的字符。 15 | /// 16 | OutOfRadix = 1, 17 | 18 | /// 19 | /// 结果超出类型的范围。 20 | /// 21 | OutOfRange = 2, 22 | 23 | /// 24 | /// 格式错误。 25 | /// 26 | WrongFormat = 3, 27 | 28 | /// 29 | /// 空字符串 30 | /// 31 | Empty = 4 32 | } 33 | } -------------------------------------------------------------------------------- /Swifter.Underlying/netstandard1.0/Swifter.Underlying.il: -------------------------------------------------------------------------------- 1 | #define CORE_ASSEMBLY "System.Runtime" 2 | #define IS_READ_ONLY_ATTRIBUTE "System.Runtime.CompilerServices.IsReadOnlyAttribute" 3 | 4 | 5 | .class private auto ansi sealed beforefieldinit System.Runtime.CompilerServices.IsReadOnlyAttribute extends [CORE_ASSEMBLY]System.Attribute 6 | { 7 | .method public hidebysig specialname rtspecialname instance void .ctor () cil managed 8 | { 9 | .maxstack 1 10 | ldarg.0 11 | call instance void [CORE_ASSEMBLY]System.Attribute::.ctor() 12 | ret 13 | } // end of method IsReadOnlyAttribute::.ctor 14 | 15 | } // end of class System.Runtime.CompilerServices.IsReadOnlyAttribute 16 | 17 | 18 | #include "../Swifter.Underlying.il" -------------------------------------------------------------------------------- /Swifter.Test.NUnit/Swifter.Test.NUnit.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | netcoreapp3.0 5 | Swifter.Test 6 | true 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | -------------------------------------------------------------------------------- /Swifter.Test.WPF/Serializers/SwifterJsonSerializer.cs: -------------------------------------------------------------------------------- 1 | using Swifter.Json; 2 | 3 | namespace Swifter.Test.WPF.Serializers 4 | { 5 | public sealed class SwifterJsonSerializer : BaseSerializer 6 | { 7 | static SwifterJsonSerializer() 8 | { 9 | JsonFormatter.CharsPool.Ratio = 0; 10 | } 11 | 12 | public override TObject Deserialize(string symbols) 13 | { 14 | return JsonFormatter.DeserializeObject(symbols, JsonFormatterOptions.IgnoreZero | JsonFormatterOptions.IgnoreNull); 15 | } 16 | 17 | public override string Serialize(TObject obj) 18 | { 19 | return JsonFormatter.SerializeObject(obj); 20 | } 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /Swifter.Data/Sql/DeleteStatement.cs: -------------------------------------------------------------------------------- 1 | namespace Swifter.Data.Sql 2 | { 3 | /// 4 | /// Delete 语句信息 5 | /// 6 | public sealed class DeleteStatement 7 | { 8 | /// 9 | /// 构建 Delete 语句信息 10 | /// 11 | /// 需要 Delete 的表 12 | public DeleteStatement(Table table) 13 | { 14 | Table = table; 15 | 16 | Where = new Conditions(); 17 | } 18 | 19 | /// 20 | /// 需要 Delete 的表。 21 | /// 22 | public Table Table { get; } 23 | 24 | /// 25 | /// Delete 条件。 26 | /// 27 | public Conditions Where { get; } 28 | } 29 | } -------------------------------------------------------------------------------- /Swifter.Data/Sql/Value/AssignValue.cs: -------------------------------------------------------------------------------- 1 | namespace Swifter.Data.Sql 2 | { 3 | /// 4 | /// 赋值信息 5 | /// 6 | public sealed class AssignValue 7 | { 8 | /// 9 | /// 初始化赋值信息 10 | /// 11 | /// 要赋值的列 12 | /// 值 13 | public AssignValue(Column column, IValue value) 14 | { 15 | Column = column; 16 | Value = value; 17 | } 18 | 19 | /// 20 | /// 要赋值的列 21 | /// 22 | public Column Column { get; } 23 | 24 | /// 25 | /// 值 26 | /// 27 | public IValue Value { get; } 28 | } 29 | } -------------------------------------------------------------------------------- /Swifter.Core/VersionDifferences/IgnoresAccessChecksToAttribute.cs: -------------------------------------------------------------------------------- 1 | namespace System.Runtime.CompilerServices 2 | { 3 | /// 4 | /// 表示忽略对指定程序集的访问检查的特性。 5 | /// 6 | [AttributeUsage(AttributeTargets.Assembly, AllowMultiple = true)] 7 | public class IgnoresAccessChecksToAttribute : Attribute 8 | { 9 | /// 10 | /// 初始化特性。 11 | /// 12 | /// 要忽略访问检查的程序集 13 | public IgnoresAccessChecksToAttribute(string assemblyName) 14 | { 15 | AssemblyName = assemblyName; 16 | } 17 | 18 | /// 19 | /// 要忽略访问检查的程序集。 20 | /// 21 | public string AssemblyName { get; } 22 | } 23 | } -------------------------------------------------------------------------------- /Swifter.Json/JsonLoopReferencingException.cs: -------------------------------------------------------------------------------- 1 | using Swifter.RW; 2 | using System; 3 | 4 | namespace Swifter.Json 5 | { 6 | /// 7 | /// Json 序列化时出现循环引用引发的异常信息。 8 | /// 9 | public sealed class JsonLoopReferencingException : Exception 10 | { 11 | /// 12 | /// 出现循环引用的对象。 13 | /// 14 | public object LoopingObject { get; } 15 | 16 | /// 17 | /// 构建实例 18 | /// 19 | internal JsonLoopReferencingException(RWPathInfo ref1, RWPathInfo ref2, object loopingObject) 20 | : base($"Json serializating members '{ref1}' and '{ref2}' loop referencing.") 21 | { 22 | LoopingObject = loopingObject; 23 | } 24 | } 25 | } -------------------------------------------------------------------------------- /Swifter.Core/Reflection/Property/Delegate.cs: -------------------------------------------------------------------------------- 1 | namespace Swifter.Reflection 2 | { 3 | delegate ref TValue XClassRefValueHandler(TClass obj); 4 | delegate TValue XClassGetValueHandler(TClass obj); 5 | delegate void XClassSetValueHandler(TClass obj, TValue value); 6 | 7 | delegate ref TValue XStructRefValueHandler(ref TStruct obj); 8 | delegate TValue XStructGetValueHandler(ref TStruct obj); 9 | delegate void XStructSetValueHandler(ref TStruct obj, TValue value); 10 | 11 | delegate ref TValue XStaticRefValueHandler(); 12 | delegate TValue XStaticGetValueHandler(); 13 | delegate void XStaticSetValueHandler(TValue value); 14 | } 15 | -------------------------------------------------------------------------------- /Swifter.Core/Tools/String/Utf8Byte.cs: -------------------------------------------------------------------------------- 1 | using System.Runtime.InteropServices; 2 | 3 | namespace Swifter.Tools 4 | { 5 | /// 6 | /// 表示 UTF8 专用字节标识。 7 | /// 8 | [StructLayout(LayoutKind.Sequential, Size = sizeof(byte))] 9 | public struct Utf8Byte 10 | { 11 | /// 12 | /// 13 | /// 14 | /// 15 | public static unsafe implicit operator Utf8Byte(byte value) => Underlying.As(ref value); 16 | 17 | /// 18 | /// 19 | /// 20 | /// 21 | 22 | public static unsafe implicit operator byte(Utf8Byte value) => Underlying.As(ref value); 23 | } 24 | } -------------------------------------------------------------------------------- /Swifter.Core/Tools/Type/IGenericInvoker.cs: -------------------------------------------------------------------------------- 1 | namespace Swifter.Tools 2 | { 3 | /// 4 | /// 表示一个泛型执行器。 5 | /// 6 | public interface IGenericInvoker 7 | { 8 | /// 9 | /// 泛型执行方法。 10 | /// 11 | /// 泛型 12 | void Invoke(); 13 | } 14 | 15 | /// 16 | /// 带返回值的泛型执行器。 17 | /// 18 | /// 返回值类型 19 | public interface IGenericInvoker 20 | { 21 | /// 22 | /// 泛型执行方法。 23 | /// 24 | /// 泛型 25 | /// 返回一个泛型值 26 | TResult Invoke(); 27 | } 28 | } -------------------------------------------------------------------------------- /Swifter.Core/Tools/Convert/ConvertAdd.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | namespace Swifter.Tools 4 | { 5 | internal static class ConvertAdd 6 | { 7 | public static string ToString(Guid value) 8 | { 9 | return value.ToString(); 10 | } 11 | 12 | public static Guid ToGuid(string value) 13 | { 14 | return new Guid(value); 15 | } 16 | 17 | public static Guid ToGuid(object value) 18 | { 19 | if (value is Guid guid) 20 | { 21 | return guid; 22 | } 23 | 24 | if (value is string str) 25 | { 26 | return ToGuid(str); 27 | } 28 | 29 | throw new InvalidCastException(nameof(value)); 30 | } 31 | } 32 | } -------------------------------------------------------------------------------- /Swifter.Data/Sql/Function/BinaryFunction.cs: -------------------------------------------------------------------------------- 1 | namespace Swifter.Data.Sql 2 | { 3 | /// 4 | /// 二元函数。 5 | /// 6 | public abstract class BinaryFunction : IValue 7 | { 8 | /// 9 | /// 参数 1 10 | /// 11 | public IValue Left { get; set; } 12 | 13 | /// 14 | /// 参数2 15 | /// 16 | public IValue Right { get; set; } 17 | 18 | /// 19 | /// 构建二元运算函数信息。 20 | /// 21 | /// 参数 1 22 | /// 参数 2 23 | public BinaryFunction(IValue left, IValue right) 24 | { 25 | Left = left; 26 | Right = right; 27 | } 28 | } 29 | } -------------------------------------------------------------------------------- /Swifter.Data/Sql/Select/OrderBy.cs: -------------------------------------------------------------------------------- 1 | namespace Swifter.Data.Sql 2 | { 3 | /// 4 | /// 排序信息 5 | /// 6 | public sealed class OrderBy 7 | { 8 | /// 9 | /// 构建排序信息 10 | /// 11 | /// 要排序的列 12 | /// 排序方向 13 | public OrderBy(Column column, OrderByDirections direction) 14 | { 15 | Column = column; 16 | Direction = direction; 17 | } 18 | 19 | /// 20 | /// 要排序的列。 21 | /// 22 | public Column Column { get; } 23 | 24 | /// 25 | /// 排序方向。 26 | /// 27 | public OrderByDirections Direction { get; } 28 | } 29 | } -------------------------------------------------------------------------------- /Swifter.Extensions.AspNetCore/Properties/launchSettings.json: -------------------------------------------------------------------------------- 1 | { 2 | "iisSettings": { 3 | "windowsAuthentication": false, 4 | "anonymousAuthentication": true, 5 | "iisExpress": { 6 | "applicationUrl": "http://localhost:50621/", 7 | "sslPort": 0 8 | } 9 | }, 10 | "profiles": { 11 | "IIS Express": { 12 | "commandName": "IISExpress", 13 | "launchBrowser": true, 14 | "environmentVariables": { 15 | "ASPNETCORE_ENVIRONMENT": "Development" 16 | } 17 | }, 18 | "Swifter.Extensions.AspNetCore": { 19 | "commandName": "Project", 20 | "launchBrowser": true, 21 | "environmentVariables": { 22 | "ASPNETCORE_ENVIRONMENT": "Development" 23 | }, 24 | "applicationUrl": "http://localhost:5000" 25 | } 26 | } 27 | } -------------------------------------------------------------------------------- /Swifter.Core/RW/Data/DbDataReaderInterface.cs: -------------------------------------------------------------------------------- 1 | 2 | using System; 3 | using static Swifter.RW.DataTableRW; 4 | 5 | namespace Swifter.RW 6 | { 7 | sealed class DbDataReaderInterface : IValueInterface where T : class, System.Data.IDataReader 8 | { 9 | public T ReadValue(IValueReader valueReader) 10 | { 11 | if (valueReader is IValueReader reader) 12 | { 13 | return reader.ReadValue(); 14 | } 15 | 16 | throw new NotSupportedException(); 17 | } 18 | 19 | public void WriteValue(IValueWriter valueWriter, T value) 20 | { 21 | var reader = new DbDataReaderReader(value, GetDataTableRWOptions(valueWriter)); 22 | 23 | valueWriter.WriteArray(reader); 24 | } 25 | } 26 | } -------------------------------------------------------------------------------- /Swifter.Core/RW/IValueInterface.cs: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | namespace Swifter.RW 5 | { 6 | /// 7 | /// 提供某一类型在 IValueReader 中读取值和在 IValueWriter 写入值的方法。 8 | /// 9 | /// 类型 10 | public interface IValueInterface 11 | { 12 | /// 13 | /// 在 IValueReader 中读取该类型的值。 14 | /// 15 | /// 值读取器 16 | /// 返回该类型的值 17 | T ReadValue(IValueReader valueReader); 18 | 19 | /// 20 | /// 在 IValueWriter 中写入该类型的值。 21 | /// 22 | /// 值写入器 23 | /// 该类型的值 24 | void WriteValue(IValueWriter valueWriter, T value); 25 | } 26 | } -------------------------------------------------------------------------------- /Swifter.Json/JsonSerializeModes.cs: -------------------------------------------------------------------------------- 1 | using System.Runtime.InteropServices; 2 | 3 | namespace Swifter.Json 4 | { 5 | static class JsonSerializeModes 6 | { 7 | public struct SimpleMode 8 | { 9 | } 10 | 11 | public struct ComplexMode 12 | { 13 | public string IndentedChars; 14 | public string LineBreakChars; 15 | public string MiddleChars; 16 | 17 | public bool IsInArray; 18 | } 19 | 20 | [StructLayout(LayoutKind.Explicit)] 21 | public struct ReferenceMode 22 | { 23 | [FieldOffset(0)] 24 | public ComplexMode DefaultMode; 25 | 26 | [FieldOffset(40)] 27 | public JsonReferenceWriter References; 28 | } 29 | } 30 | } -------------------------------------------------------------------------------- /Swifter.Test.WPF/Serializers/SwifterMessagePackSerializer.cs: -------------------------------------------------------------------------------- 1 | using Swifter.MessagePack; 2 | 3 | namespace Swifter.Test.WPF.Serializers 4 | { 5 | public sealed class SwifterMessagePackSerializer : BaseSerializer 6 | { 7 | static SwifterMessagePackSerializer() 8 | { 9 | MessagePackFormatter.BytesPool.Ratio = 0; 10 | } 11 | 12 | public override TObject Deserialize(byte[] symbols) 13 | { 14 | return MessagePackFormatter.DeserializeObject(symbols, MessagePackFormatterOptions.IgnoreNull | MessagePackFormatterOptions.IgnoreZero); 15 | } 16 | 17 | public override byte[] Serialize(TObject obj) 18 | { 19 | return MessagePackFormatter.SerializeObject(obj); 20 | } 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /Swifter.Core/Tools/Type/EEClass.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Runtime.InteropServices; 3 | 4 | #pragma warning disable 0649 5 | 6 | namespace Swifter.Tools 7 | { 8 | [StructLayout(LayoutKind.Sequential)] 9 | internal struct EEClass 10 | { 11 | public IntPtr m_pGuidInfo; 12 | public ushort m_rpOptionalFields; 13 | public unsafe MethodTable* m_pMethodTable; 14 | public IntPtr m_pFieldDescList; 15 | public IntPtr m_pChunks; 16 | public IntPtr m_cbNativeSize; 17 | public IntPtr m_pccwTemplate; 18 | public uint m_dwAttrClass; 19 | public uint m_VMFlags; 20 | public byte m_NormType; 21 | public byte m_fFieldsArePacked; 22 | public byte m_cbFixedEEClassFields; 23 | public byte m_cbBaseSizePadding; 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /Swifter.Test.WPF/Serializers/ISerializer.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Runtime.CompilerServices; 4 | using System.Text; 5 | 6 | namespace Swifter.Test.WPF.Serializers 7 | { 8 | public interface ISerializer 9 | { 10 | string Name { get; } 11 | Type SymbolsType { get; } 12 | } 13 | 14 | public abstract class BaseSerializer: ISerializer 15 | { 16 | [MethodImpl(MethodImplOptions.NoInlining)] 17 | public abstract TSymbols Serialize(TObject obj); 18 | 19 | [MethodImpl(MethodImplOptions.NoInlining)] 20 | public abstract TObject Deserialize(TSymbols symbols); 21 | 22 | public Type SymbolsType => typeof(TSymbols); 23 | 24 | public virtual string Name => GetType().Name; 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /Swifter.Core/RW/ValueFilterInfo.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | namespace Swifter.RW 4 | { 5 | /// 6 | /// 值筛选时的值信息。 7 | /// 8 | /// 键类型 9 | public sealed class ValueFilterInfo 10 | { 11 | /// 12 | /// 初始化默认实例。 13 | /// 14 | public ValueFilterInfo() 15 | { 16 | ValueCopyer = new ValueCopyer(); 17 | } 18 | 19 | /// 20 | /// 读取或设置字段名。 21 | /// 22 | public TKey Key; 23 | 24 | /// 25 | /// 读取值的定义类型。 26 | /// 27 | public Type Type; 28 | 29 | /// 30 | /// 获取值的读写器。 31 | /// 32 | public readonly ValueCopyer ValueCopyer; 33 | } 34 | } -------------------------------------------------------------------------------- /Swifter.Core/Tools/Type/MethodTable.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Runtime.InteropServices; 3 | 4 | #pragma warning disable 0649 5 | 6 | namespace Swifter.Tools 7 | { 8 | [StructLayout(LayoutKind.Sequential)] 9 | internal struct MethodTable 10 | { 11 | public uint m_dwFlags; 12 | public uint m_BaseSize; 13 | public ushort m_wFlags2; 14 | public ushort m_wToken; 15 | public ushort m_wNumVirtuals; 16 | public ushort m_wNumInterfaces; 17 | public unsafe MethodTable* m_pParentMethodTable; 18 | public IntPtr m_pLoaderModule; 19 | public IntPtr m_pWriteableData; 20 | public unsafe EEClass* m_pEEClass; 21 | public IntPtr m_pPerInstInfo; 22 | public IntPtr m_pInterfaceMap; 23 | public IntPtr m_pMultipurposeSlot2; 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /Swifter.Test.WPF/Models/Device.cs: -------------------------------------------------------------------------------- 1 | using MessagePack; 2 | using System; 3 | using System.Collections.Generic; 4 | using System.Text; 5 | 6 | namespace Swifter.Test.WPF.Models 7 | { 8 | [MessagePackObject(true)] 9 | public sealed class Device 10 | { 11 | public int Id { get; set; } 12 | public Guid Guid { get; set; } 13 | public string SystemNo { get; set; } 14 | public string IMEI { get; set; } 15 | public int MainRoleId { get; set; } 16 | public int DeviceType { get; set; } 17 | public int DeviceState { get; set; } 18 | public DateTime InstallDate { get; set; } 19 | public DateTime InsertTime { get; set; } 20 | public int MediaChannels { get; set; } 21 | public int SimId { get; set; } 22 | public DateTime LastHeartbeatTime { get; set; } 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /Swifter.Core/RW/Collection/EnumeratorInterface.cs: -------------------------------------------------------------------------------- 1 | using Swifter.RW; 2 | 3 | using System; 4 | using System.Collections; 5 | 6 | namespace Swifter.RW 7 | { 8 | internal sealed class EnumeratorInterface : IValueInterface where T : IEnumerator 9 | { 10 | public T ReadValue(IValueReader valueReader) 11 | { 12 | throw new NotSupportedException(); 13 | } 14 | 15 | public void WriteValue(IValueWriter valueWriter, T value) 16 | { 17 | if (value is null) 18 | { 19 | valueWriter.DirectWrite(null); 20 | 21 | return; 22 | } 23 | 24 | var enumeratorReader = new EnumeratorReader(); 25 | 26 | enumeratorReader.Initialize(value); 27 | 28 | valueWriter.WriteArray(enumeratorReader); 29 | } 30 | } 31 | } -------------------------------------------------------------------------------- /Swifter.FSharpTest/Program.fs: -------------------------------------------------------------------------------- 1 | // Learn more about F# at http://fsharp.org 2 | 3 | open System 4 | open Swifter.Json 5 | 6 | type Payment = Cache of decimal | CreditCard of int | Free 7 | [] type cm 8 | type public Demo = 9 | { Id : int 10 | Name : string 11 | Age : int 12 | BodyHeight : int option 13 | Children : string list 14 | Payment : Payment 15 | WorkDone : Result } 16 | let value = 17 | { Id = 1 18 | Name = "Dogwei" 19 | Age = 42 20 | BodyHeight = Some 195 21 | Children = ["Andy"] 22 | Payment = Free 23 | WorkDone = Error "Not satisfied" 24 | } 25 | 26 | 27 | 28 | let json = JsonFormatter.SerializeObject(value, JsonFormatterOptions.Indented) 29 | 30 | Console.WriteLine json 31 | 32 | let orig = JsonFormatter.DeserializeObject json 33 | 34 | Console.WriteLine orig -------------------------------------------------------------------------------- /Swifter.Core/RW/Collection/EnumerableInterface.cs: -------------------------------------------------------------------------------- 1 | using Swifter.RW; 2 | 3 | using System; 4 | using System.Collections; 5 | 6 | namespace Swifter.RW 7 | { 8 | internal sealed class EnumerableInterface : IValueInterface where T : IEnumerable 9 | { 10 | public T ReadValue(IValueReader valueReader) 11 | { 12 | throw new NotSupportedException(); 13 | } 14 | 15 | public void WriteValue(IValueWriter valueWriter, T value) 16 | { 17 | if (value is null) 18 | { 19 | valueWriter.DirectWrite(null); 20 | 21 | return; 22 | } 23 | 24 | var enumeratorReader = new EnumeratorReader(); 25 | 26 | enumeratorReader.Initialize(value.GetEnumerator()); 27 | 28 | valueWriter.WriteArray(enumeratorReader); 29 | } 30 | } 31 | } -------------------------------------------------------------------------------- /Swifter.Data/Sql/Table.cs: -------------------------------------------------------------------------------- 1 | namespace Swifter.Data.Sql 2 | { 3 | /// 4 | /// 表信息。 5 | /// 6 | public sealed class Table : ITable 7 | { 8 | /// 9 | /// 表示不指定表名。 10 | /// 11 | public static readonly Table Empty = null; 12 | 13 | /// 14 | /// 构建表信息。 15 | /// 16 | /// 表名 17 | public Table(string name) 18 | { 19 | Name = name; 20 | } 21 | 22 | /// 23 | /// 表名 24 | /// 25 | public string Name { get; } 26 | 27 | /// 28 | /// 构建表信息。 29 | /// 30 | /// 表名 31 | public static implicit operator Table(string tableName) => new Table(tableName); 32 | } 33 | } -------------------------------------------------------------------------------- /Swifter.Core/RW/Collection/Generic/EnumeratorInterface.cs: -------------------------------------------------------------------------------- 1 | using Swifter.RW; 2 | 3 | using System; 4 | using System.Collections.Generic; 5 | 6 | namespace Swifter.RW 7 | { 8 | internal sealed class EnumeratorInterface : IValueInterface where T : IEnumerator 9 | { 10 | public T ReadValue(IValueReader valueReader) 11 | { 12 | throw new NotSupportedException(); 13 | } 14 | 15 | public void WriteValue(IValueWriter valueWriter, T value) 16 | { 17 | if (value is null) 18 | { 19 | valueWriter.DirectWrite(null); 20 | 21 | return; 22 | } 23 | 24 | var enumeratorReader = new EnumeratorReader 25 | { 26 | content = value 27 | }; 28 | 29 | valueWriter.WriteArray(enumeratorReader); 30 | } 31 | } 32 | } -------------------------------------------------------------------------------- /Swifter.Core/RW/SetValueFormatInterface.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Globalization; 3 | 4 | namespace Swifter.RW 5 | { 6 | internal sealed class SetValueFormatInterface : IValueInterface where T : IFormattable 7 | { 8 | public readonly IValueInterface DefaultInterface; 9 | public readonly string Format; 10 | 11 | public SetValueFormatInterface(IValueInterface defaultInterface, string format) 12 | { 13 | DefaultInterface = defaultInterface; 14 | Format = format; 15 | } 16 | 17 | public T ReadValue(IValueReader valueReader) 18 | { 19 | return DefaultInterface.ReadValue(valueReader); 20 | } 21 | 22 | public void WriteValue(IValueWriter valueWriter, T value) 23 | { 24 | valueWriter.WriteString(value.ToString(Format, CultureInfo.CurrentCulture)); 25 | } 26 | } 27 | } -------------------------------------------------------------------------------- /Swifter.FSharpExtensions/Swifter.FSharpExtensions.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | netstandard2.0 5 | 1.5.0 6 | Dogwei 7 | LICENSE 8 | icon.png 9 | true 10 | Swifter.FSharpExtensions.snk 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | -------------------------------------------------------------------------------- /Swifter.Underlying/net20/Swifter.Underlying.il: -------------------------------------------------------------------------------- 1 | #define CORE_ASSEMBLY "mscorlib" 2 | #define IS_READ_ONLY_ATTRIBUTE "System.Runtime.CompilerServices.IsReadOnlyAttribute" 3 | 4 | // Metadata version: v2.0.50727 5 | .assembly extern mscorlib 6 | { 7 | .publickeytoken = (B7 7A 5C 56 19 34 E0 89 ) // .z\V.4.. 8 | .ver 2:0:0:0 9 | } 10 | 11 | .class private auto ansi sealed beforefieldinit System.Runtime.CompilerServices.IsReadOnlyAttribute extends [CORE_ASSEMBLY]System.Attribute 12 | { 13 | .method public hidebysig specialname rtspecialname instance void .ctor () cil managed 14 | { 15 | .maxstack 1 16 | ldarg.0 17 | call instance void [CORE_ASSEMBLY]System.Attribute::.ctor() 18 | ret 19 | } // end of method IsReadOnlyAttribute::.ctor 20 | 21 | } // end of class System.Runtime.CompilerServices.IsReadOnlyAttribute 22 | 23 | 24 | #include "../Swifter.Underlying.il" -------------------------------------------------------------------------------- /Swifter.FSharpExtensions/FSharpUnionInterface.cs: -------------------------------------------------------------------------------- 1 | using Swifter.RW; 2 | 3 | namespace Swifter.FSharpExtensions 4 | { 5 | public sealed class FSharpUnionInterface : IValueInterface 6 | { 7 | public T ReadValue(IValueReader valueReader) 8 | { 9 | var rw = new FSharpUnionRW(); 10 | 11 | valueReader.ReadArray(rw); 12 | 13 | return rw.GetContent(); 14 | } 15 | 16 | public void WriteValue(IValueWriter valueWriter, T value) 17 | { 18 | var rw = new FSharpUnionRW { Content = value }; 19 | 20 | var (caceInfo, values) = rw.GetUnionFields(); 21 | 22 | if (values != null && values.Length > 0) 23 | { 24 | valueWriter.WriteArray(rw); 25 | } 26 | else 27 | { 28 | valueWriter.WriteString(caceInfo.Name); 29 | } 30 | } 31 | } 32 | } -------------------------------------------------------------------------------- /Swifter.Core/RW/Collection/CollectionInterface.cs: -------------------------------------------------------------------------------- 1 | 2 | 3 | using System.Collections; 4 | 5 | namespace Swifter.RW 6 | { 7 | internal sealed class CollectionInterface : IValueInterface where T : ICollection 8 | { 9 | public T ReadValue(IValueReader valueReader) 10 | { 11 | var collectionRW = new CollectionRW(); 12 | 13 | valueReader.ReadArray(collectionRW); 14 | 15 | return collectionRW.content; 16 | } 17 | 18 | public void WriteValue(IValueWriter valueWriter, T value) 19 | { 20 | if (value is null) 21 | { 22 | valueWriter.DirectWrite(null); 23 | 24 | return; 25 | } 26 | 27 | var collectionRW = new CollectionRW 28 | { 29 | content = value 30 | }; 31 | 32 | valueWriter.WriteArray(collectionRW); 33 | } 34 | } 35 | } -------------------------------------------------------------------------------- /Swifter.Data/Sql/UpdateStatement.cs: -------------------------------------------------------------------------------- 1 | namespace Swifter.Data.Sql 2 | { 3 | /// 4 | /// Update 语句信息。 5 | /// 6 | public sealed class UpdateStatement 7 | { 8 | /// 9 | /// 构建 Update 语句信息。 10 | /// 11 | /// 要 Update 的表 12 | public UpdateStatement(Table table) 13 | { 14 | Table = table; 15 | 16 | Values = new AssignValues(); 17 | 18 | Where = new Conditions(); 19 | } 20 | 21 | /// 22 | /// 要 Update 的表。 23 | /// 24 | public Table Table { get; } 25 | 26 | /// 27 | /// 要赋值的列的集合。 28 | /// 29 | public AssignValues Values { get; } 30 | 31 | /// 32 | /// Update 条件。 33 | /// 34 | public Conditions Where { get; } 35 | } 36 | } -------------------------------------------------------------------------------- /Swifter.Core/RW/Collection/DictionaryInterface.cs: -------------------------------------------------------------------------------- 1 | 2 | 3 | using System.Collections; 4 | 5 | namespace Swifter.RW 6 | { 7 | internal sealed class DictionaryInterface : IValueInterface where T : IDictionary 8 | { 9 | public T ReadValue(IValueReader valueReader) 10 | { 11 | var dictionaryRW = new DictionaryRW(); 12 | 13 | valueReader.ReadObject(dictionaryRW.As()); 14 | 15 | return dictionaryRW.content; 16 | } 17 | 18 | public void WriteValue(IValueWriter valueWriter, T value) 19 | { 20 | if (value is null) 21 | { 22 | valueWriter.DirectWrite(null); 23 | 24 | return; 25 | } 26 | 27 | var dictionaryRW = new DictionaryRW 28 | { 29 | content = value 30 | }; 31 | 32 | valueWriter.WriteObject(dictionaryRW.As()); 33 | } 34 | } 35 | } -------------------------------------------------------------------------------- /Swifter.Data/Sql/InsertStatement.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | 4 | namespace Swifter.Data.Sql 5 | { 6 | /// 7 | /// Insert 语句信息。 8 | /// 9 | public sealed class InsertStatement 10 | { 11 | /// 12 | /// 构建 Insert 语句信息。 13 | /// 14 | /// 需要 Insert 的表 15 | public InsertStatement(Table table) 16 | { 17 | if (table is null) 18 | { 19 | throw new ArgumentNullException(nameof(table)); 20 | } 21 | 22 | Table = table; 23 | 24 | Values = new AssignValues(); 25 | } 26 | 27 | /// 28 | /// 需要 Insert 的表。 29 | /// 30 | public Table Table { get; } 31 | 32 | /// 33 | /// 需要赋值的列。 34 | /// 35 | public AssignValues Values { get; } 36 | } 37 | } -------------------------------------------------------------------------------- /Swifter.Core/Tools/Type/FieldDesc.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Runtime.InteropServices; 3 | 4 | #pragma warning disable 0649 5 | 6 | namespace Swifter.Tools 7 | { 8 | [StructLayout(LayoutKind.Sequential)] 9 | internal struct FieldDesc 10 | { 11 | public readonly IntPtr m_pMTOfEnclosingClass; 12 | public readonly uint m_dword1; 13 | public readonly uint m_dword2; 14 | 15 | public uint m_mb => m_dword1 & 0xffffffU; 16 | 17 | public bool m_isStatic => (m_dword1 & 0x1000000) != 0; 18 | 19 | public bool m_isThreadLocal => (m_dword1 & 0x2000000) != 0; 20 | 21 | public bool m_isRVA => (m_dword1 & 0x4000000) != 0; 22 | 23 | public byte m_prot => (byte)((m_dword1 >> 27) & 0x7); 24 | 25 | public bool m_requiresFullMbValue => (m_dword1 & 40000000) != 0; 26 | 27 | public uint m_dwOffset => m_dword2 & 0x7ffffffU; 28 | 29 | public uint m_type => (m_dword2 >> 27) & (0x1f); 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /Swifter.Data/Sql/Column.cs: -------------------------------------------------------------------------------- 1 | namespace Swifter.Data.Sql 2 | { 3 | /// 4 | /// 列信息 5 | /// 6 | public sealed class Column : IValue 7 | { 8 | /// 9 | /// 构建列信息 10 | /// 11 | /// 表 12 | /// 列名 13 | public Column(ITable table, string name) 14 | { 15 | Table = table; 16 | Name = name; 17 | } 18 | 19 | /// 20 | /// 列名 21 | /// 22 | public string Name { get; set; } 23 | 24 | /// 25 | /// 表 26 | /// 27 | public ITable Table { get; set; } 28 | 29 | /// 30 | /// 构建一个未设置表的列 31 | /// 32 | /// 列名 33 | public static implicit operator Column(string columnName) => new Column(null, columnName); 34 | } 35 | } -------------------------------------------------------------------------------- /Swifter.Core/RW/Collection/Generic/CollectionInterface.cs: -------------------------------------------------------------------------------- 1 | 2 | 3 | using System.Collections.Generic; 4 | 5 | namespace Swifter.RW 6 | { 7 | internal sealed class CollectionInterface : IValueInterface where T : ICollection 8 | { 9 | public T ReadValue(IValueReader valueReader) 10 | { 11 | var collectionRW = new CollectionRW(); 12 | 13 | valueReader.ReadArray(collectionRW); 14 | 15 | return collectionRW.content; 16 | } 17 | 18 | public void WriteValue(IValueWriter valueWriter, T value) 19 | { 20 | if (value is null) 21 | { 22 | valueWriter.DirectWrite(null); 23 | 24 | return; 25 | } 26 | 27 | var collectionRW = new CollectionRW 28 | { 29 | content = value 30 | }; 31 | 32 | valueWriter.WriteArray(collectionRW); 33 | } 34 | } 35 | } -------------------------------------------------------------------------------- /Swifter.Core/RW/Basic/UriInterface.cs: -------------------------------------------------------------------------------- 1 | 2 | 3 | using System; 4 | 5 | namespace Swifter.RW 6 | { 7 | internal sealed class UriInterface : IValueInterface 8 | { 9 | public Uri ReadValue(IValueReader valueReader) 10 | { 11 | if (valueReader is IValueReader reader) 12 | { 13 | return reader.ReadValue(); 14 | } 15 | 16 | return new Uri(valueReader.ReadString()); 17 | } 18 | 19 | public void WriteValue(IValueWriter valueWriter, Uri value) 20 | { 21 | if (value is null) 22 | { 23 | valueWriter.DirectWrite(null); 24 | 25 | return; 26 | } 27 | 28 | if (valueWriter is IValueWriter writer) 29 | { 30 | writer.WriteValue(value); 31 | 32 | return; 33 | } 34 | 35 | valueWriter.WriteString(value.ToString()); 36 | } 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /Swifter.Core/RW/ArrayRW/ArrayInterfaceMaper.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | namespace Swifter.RW 4 | { 5 | internal sealed class ArrayInterfaceMaper : IValueInterfaceMaper 6 | { 7 | public IValueInterface TryMap() 8 | { 9 | if (typeof(T).IsArray) 10 | { 11 | var elementType = typeof(T).GetElementType(); 12 | 13 | Type interfaceType; 14 | 15 | if (typeof(T).GetArrayRank() == 1 && typeof(T) == elementType.MakeArrayType()) 16 | { 17 | interfaceType = typeof(ArrayInterface<>).MakeGenericType(elementType); 18 | } 19 | else 20 | { 21 | interfaceType = typeof(MultiDimArrayInterface<,>).MakeGenericType(typeof(T), elementType); 22 | } 23 | 24 | return Underlying.As>(Activator.CreateInstance(interfaceType)); 25 | } 26 | 27 | return null; 28 | } 29 | } 30 | } -------------------------------------------------------------------------------- /Swifter.Data/DbRowObjectMap.cs: -------------------------------------------------------------------------------- 1 | using Swifter.RW; 2 | using Swifter.Tools; 3 | using System; 4 | 5 | namespace Swifter.Data 6 | { 7 | [Serializable] 8 | sealed class DbRowObjectMap : Cache, IEquatable 9 | { 10 | public DbRowsFlags flags; 11 | 12 | public bool Equals(DbRowObjectMap other) 13 | { 14 | if (other is null) 15 | { 16 | return false; 17 | } 18 | 19 | if (other.Count != Count) 20 | { 21 | return false; 22 | } 23 | 24 | for (int i = Count - 1; i >= 0; i--) 25 | { 26 | if (this[i].Key != other[i].Key) 27 | { 28 | return false; 29 | } 30 | 31 | if (this[i].Value != other[i].Value) 32 | { 33 | return false; 34 | } 35 | } 36 | 37 | return true; 38 | } 39 | } 40 | } -------------------------------------------------------------------------------- /Swifter.Core/RW/Basic/ObjectInterface.cs: -------------------------------------------------------------------------------- 1 | 2 | using Swifter.Tools; 3 | using System; 4 | 5 | namespace Swifter.RW 6 | { 7 | internal sealed class ObjectInterface : IValueInterface 8 | { 9 | static readonly IntPtr TypeHandle = TypeHelper.GetTypeHandle(typeof(object)); 10 | 11 | public object ReadValue(IValueReader valueReader) 12 | { 13 | return valueReader.DirectRead(); 14 | } 15 | 16 | public void WriteValue(IValueWriter valueWriter, object value) 17 | { 18 | if (value is null) 19 | { 20 | valueWriter.DirectWrite(null); 21 | 22 | return; 23 | } 24 | 25 | /* 父类引用,子类实例时使用 Type 获取写入器。 */ 26 | if (TypeHandle != TypeHelper.GetTypeHandle(value)) 27 | { 28 | ValueInterface.GetInterface(value).Write(valueWriter, value); 29 | 30 | return; 31 | } 32 | 33 | valueWriter.DirectWrite(value); 34 | } 35 | } 36 | } -------------------------------------------------------------------------------- /Swifter.Core/RW/Collection/Generic/DictionaryInterface.cs: -------------------------------------------------------------------------------- 1 | 2 | 3 | using System.Collections.Generic; 4 | 5 | namespace Swifter.RW 6 | { 7 | internal sealed class DictionaryInterface : IValueInterface where T : IDictionary 8 | { 9 | public T ReadValue(IValueReader valueReader) 10 | { 11 | var dictionaryRW = new DictionaryRW(); 12 | 13 | valueReader.ReadObject(dictionaryRW.As()); 14 | 15 | return dictionaryRW.content; 16 | } 17 | 18 | public void WriteValue(IValueWriter valueWriter, T value) 19 | { 20 | if (value is null) 21 | { 22 | valueWriter.DirectWrite(null); 23 | 24 | return; 25 | } 26 | 27 | var dictionaryRW = new DictionaryRW 28 | { 29 | content = value 30 | }; 31 | 32 | valueWriter.WriteObject(dictionaryRW.As()); 33 | } 34 | } 35 | } -------------------------------------------------------------------------------- /Swifter.Core/Reflection/XInterfaceAttributedFieldRW.cs: -------------------------------------------------------------------------------- 1 | 2 | using Swifter.RW; 3 | 4 | using System; 5 | 6 | namespace Swifter.Reflection 7 | { 8 | sealed class XInterfaceAttributedFieldRW : XAttributedFieldRW, IObjectField 9 | { 10 | internal readonly IValueInterface valueInterface; 11 | 12 | public XInterfaceAttributedFieldRW(IXFieldRW fieldRW, RWFieldAttribute attribute, XBindingFlags flags, IValueInterface valueInterface) 13 | : base(fieldRW, attribute, flags) 14 | { 15 | this.valueInterface = valueInterface; 16 | } 17 | 18 | public override void OnReadValue(object obj, IValueWriter valueWriter) 19 | { 20 | valueInterface.WriteValue(valueWriter, ReadValue(obj)); 21 | } 22 | 23 | public override void OnWriteValue(object obj, IValueReader valueReader) 24 | { 25 | WriteValue(obj, valueInterface.ReadValue(valueReader)); 26 | } 27 | 28 | Type IObjectField.AfterType => typeof(T); 29 | } 30 | } -------------------------------------------------------------------------------- /Swifter.Json/JsonToken.cs: -------------------------------------------------------------------------------- 1 | namespace Swifter.Json 2 | { 3 | /// 4 | /// 表示 JSON 值的 Token。 5 | /// 6 | public enum JsonToken 7 | { 8 | /// 9 | /// 表示一个键值对值。 10 | /// 11 | Object, 12 | /// 13 | /// 表示一个数组值。 14 | /// 15 | Array, 16 | /// 17 | /// 表示一个 Boolean 值,包括 True 和 False。 18 | /// 19 | Boolean, 20 | /// 21 | /// 表示一个空值,包括 Null 和 Undefined。 22 | /// 23 | Null, 24 | /// 25 | /// 表示一个数值,包括整数和浮点数。 26 | /// 27 | Number, 28 | /// 29 | /// 表示一个字符串值,包括双引号和单引号。 30 | /// 31 | String, 32 | /// 33 | /// 这不表示一个值,而是表示一个 JSON 的结尾。 34 | /// 35 | End, 36 | /// 37 | /// 其他值,非上述的任何其他值。 38 | /// 39 | Other 40 | } 41 | } 42 | -------------------------------------------------------------------------------- /Swifter.Core/RW/Basic/IntPtrInterface.cs: -------------------------------------------------------------------------------- 1 | 2 | 3 | using System; 4 | 5 | namespace Swifter.RW 6 | { 7 | internal sealed class IntPtrInterface : IValueInterface 8 | { 9 | public IntPtr ReadValue(IValueReader valueReader) 10 | { 11 | if (valueReader is IValueReader intPtrReader) 12 | { 13 | return intPtrReader.ReadValue(); 14 | } 15 | 16 | var value = valueReader.ReadNullable(); 17 | 18 | if (value is null) 19 | { 20 | return IntPtr.Zero; 21 | } 22 | 23 | return (IntPtr)value.Value; 24 | } 25 | 26 | public void WriteValue(IValueWriter valueWriter, IntPtr value) 27 | { 28 | if (valueWriter is IValueWriter intPtrWriter) 29 | { 30 | intPtrWriter.WriteValue(value); 31 | } 32 | else 33 | { 34 | valueWriter.WriteInt64((long)value); 35 | } 36 | } 37 | } 38 | } -------------------------------------------------------------------------------- /Swifter.Core/Reflection/ThrowHelpers.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Reflection; 3 | 4 | namespace Swifter.Reflection 5 | { 6 | static class ThrowHelpers 7 | { 8 | public static void ThrowMissingMethodException(string memberType, Type type, MemberInfo member, string methodType) 9 | { 10 | throw new MissingMethodException($"{memberType} '{type.Name}.{member.Name}' No define '{methodType}' method."); 11 | } 12 | 13 | public static void ThrowTargetException(string parameterName, Type targetType) 14 | { 15 | throw new TargetException("Object does not match target type."); 16 | } 17 | 18 | public static void ThrowArgumentNullException(string parameterName) 19 | { 20 | throw new ArgumentNullException(parameterName); 21 | } 22 | 23 | 24 | public static void ThrowInvalidOperationException(string memberType, string memberAttribute) 25 | { 26 | throw new InvalidOperationException($"Is not {memberAttribute} {memberType}."); 27 | } 28 | } 29 | } -------------------------------------------------------------------------------- /Swifter.Core/Formatters/ITextFormatter.Core.cs: -------------------------------------------------------------------------------- 1 | #if Span 2 | 3 | 4 | using Swifter.RW; 5 | using System; 6 | 7 | namespace Swifter.Formatters 8 | { 9 | partial interface ITextFormatter 10 | { 11 | /// 12 | /// 将文档字符串反序列化为指定类型的值。 13 | /// 14 | /// 指定类型 15 | /// 文档字符串 16 | /// 指定类型的值 17 | T Deserialize(ReadOnlySpan text); 18 | 19 | /// 20 | /// 将文档字符串反序列化到指定的数据写入器中。 21 | /// 22 | /// 文档字符串 23 | /// 数据写入器 24 | void DeserializeTo(ReadOnlySpan text, IDataWriter dataWriter); 25 | 26 | /// 27 | /// 将文档字符串反序列化为指定类型的值。 28 | /// 29 | /// 文档字符串 30 | /// 指定类型 31 | /// 指定类型的值 32 | object Deserialize(ReadOnlySpan text, Type type); 33 | } 34 | } 35 | 36 | #endif -------------------------------------------------------------------------------- /Swifter.Core/RW/Collection/Generic/EnumeratorReader.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | 4 | namespace Swifter.RW 5 | { 6 | internal sealed class EnumeratorReader : IDataReader where T : IEnumerator 7 | { 8 | internal T content; 9 | 10 | public IValueReader this[int key] => throw new NotSupportedException(); 11 | 12 | public IEnumerable Keys => throw new NotSupportedException(); 13 | 14 | public int Count => -1; 15 | 16 | public Type ContentType => typeof(T); 17 | 18 | public object Content 19 | { 20 | get => content; 21 | set => content = (T)value; 22 | } 23 | 24 | public void OnReadAll(IDataWriter dataWriter) 25 | { 26 | for (int i = 0; content.MoveNext(); i++) 27 | { 28 | ValueInterface.WriteValue(dataWriter[i], content.Current); 29 | } 30 | } 31 | 32 | public void OnReadValue(int key, IValueWriter valueWriter) => throw new NotSupportedException(); 33 | } 34 | } -------------------------------------------------------------------------------- /Swifter.Core/Tools/Emit/IHashComparer.cs: -------------------------------------------------------------------------------- 1 | using System.Reflection.Emit; 2 | 3 | namespace Swifter.Tools 4 | { 5 | /// 6 | /// Emit Switch 比较器。 7 | /// 8 | /// 9 | public interface IHashComparer 10 | { 11 | /// 12 | /// 获取值的哈希值。 13 | /// 14 | /// 15 | /// 16 | int GetHashCode(T val); 17 | 18 | /// 19 | /// 比较两个值是否一致。 20 | /// 21 | /// 22 | /// 23 | /// 24 | bool Equals(T x, T y); 25 | 26 | /// 27 | /// 生成获取值的哈希值的 IL 指令。 28 | /// 29 | /// 30 | void EmitGetHashCode(ILGenerator ilGen); 31 | 32 | /// 33 | /// 生成比较两个值是否一致的 IL 指令。 34 | /// 35 | /// 36 | void EmitEquals(ILGenerator ilGen); 37 | } 38 | } -------------------------------------------------------------------------------- /Swifter.Core/RW/Collection/ListInterface.cs: -------------------------------------------------------------------------------- 1 | 2 | 3 | using System.Collections; 4 | 5 | namespace Swifter.RW 6 | { 7 | internal sealed class ListInterface : IValueInterface where T : IList 8 | { 9 | public T ReadValue(IValueReader valueReader) 10 | { 11 | if (valueReader is IValueReader reader) 12 | { 13 | return reader.ReadValue(); 14 | } 15 | 16 | var listRW = new ListRW(); 17 | 18 | valueReader.ReadArray(listRW); 19 | 20 | return listRW.content; 21 | } 22 | 23 | public void WriteValue(IValueWriter valueWriter, T value) 24 | { 25 | if (value is null) 26 | { 27 | valueWriter.DirectWrite(null); 28 | } 29 | else if (valueWriter is IValueWriter writer) 30 | { 31 | writer.WriteValue(value); 32 | } 33 | else 34 | { 35 | valueWriter.WriteArray(new ListRW { content = value }); 36 | } 37 | } 38 | } 39 | } -------------------------------------------------------------------------------- /Swifter.Data/Sql/Condition/Conditions.cs: -------------------------------------------------------------------------------- 1 | using System.Collections.Generic; 2 | 3 | namespace Swifter.Data.Sql 4 | { 5 | /// 6 | /// 条件集合 7 | /// 8 | public sealed class Conditions : List 9 | { 10 | /// 11 | /// 添加一个条件,并排序。 12 | /// 13 | /// 14 | public new void Add(Condition condition) 15 | { 16 | base.Add(condition); 17 | 18 | Sort(); 19 | } 20 | 21 | private new void Sort() 22 | { 23 | for (int i = 1, j = 0; i < Count; j = i, ++i) 24 | { 25 | var swap = this[i]; 26 | 27 | while (swap.CompareTo(this[j]) < 0) 28 | { 29 | this[j + 1] = this[j]; 30 | 31 | --j; 32 | 33 | if (j == -1) 34 | { 35 | break; 36 | } 37 | } 38 | 39 | this[j + 1] = swap; 40 | } 41 | } 42 | } 43 | } -------------------------------------------------------------------------------- /Swifter.Core/Formatters/IBinaryFormatter.Core.cs: -------------------------------------------------------------------------------- 1 | #if Span 2 | 3 | 4 | using Swifter.RW; 5 | using System; 6 | 7 | namespace Swifter.Formatters 8 | { 9 | partial interface IBinaryFormatter 10 | { 11 | /// 12 | /// 将字节码数据源反序列化为指定类型的值。 13 | /// 14 | /// 指定类型 15 | /// 字节码数据源 16 | /// 指定类型的值 17 | T Deserialize(ReadOnlySpan bytes); 18 | 19 | /// 20 | /// 将字节码数据源反序列化到指定的数据写入器中。 21 | /// 22 | /// 字节码数据源 23 | /// 数据写入器 24 | void DeserializeTo(ReadOnlySpan bytes, IDataWriter dataWriter); 25 | 26 | /// 27 | /// 将字节码数据源反序列化为指定类型的值。 28 | /// 29 | /// 字节码数据源 30 | /// 指定类型 31 | /// 指定类型的值 32 | object Deserialize(ReadOnlySpan bytes, Type type); 33 | } 34 | } 35 | 36 | #endif 37 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2018 陈鑫伟 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /Swifter.Core/RW/ArrayRW/ArrayInterface.cs: -------------------------------------------------------------------------------- 1 | namespace Swifter.RW 2 | { 3 | internal sealed class ArrayInterface : IValueInterface 4 | { 5 | public TElement[] ReadValue(IValueReader valueReader) 6 | { 7 | if (valueReader is IValueReader reader) 8 | { 9 | return reader.ReadValue(); 10 | } 11 | else 12 | { 13 | var rw = new ArrayRW(); 14 | 15 | valueReader.ReadArray(rw); 16 | 17 | return rw.GetContent(); 18 | } 19 | } 20 | 21 | public void WriteValue(IValueWriter valueWriter, TElement[] value) 22 | { 23 | if (value is null) 24 | { 25 | valueWriter.DirectWrite(null); 26 | } 27 | else if (valueWriter is IValueWriter writer) 28 | { 29 | writer.WriteValue(value); 30 | } 31 | else 32 | { 33 | valueWriter.WriteArray(new ArrayRW(value)); 34 | } 35 | } 36 | } 37 | } -------------------------------------------------------------------------------- /Swifter.Core/Tools/Emit/IDifferenceComparer.cs: -------------------------------------------------------------------------------- 1 | using System.Reflection.Emit; 2 | 3 | namespace Swifter.Tools 4 | { 5 | /// 6 | /// 差异位比较器。 7 | /// 8 | /// 指定类型 9 | public interface IDifferenceComparer:IHashComparer 10 | { 11 | /// 12 | /// 获取类型实例的长度。 13 | /// 14 | /// 类型实例 15 | /// 返回一个长度 16 | int GetLength(T value); 17 | 18 | /// 19 | /// 获取类型实例指定索引处的 Int32 值。 20 | /// 21 | /// 类型实例 22 | /// 指定索引 23 | /// 返回一个 Int32 值 24 | int ElementAt(T value, int index); 25 | 26 | /// 27 | /// 生成 获取类型实例的长度 的 IL 代码。 28 | /// 29 | /// IL 生成器 30 | void EmitGetLength(ILGenerator ilGen); 31 | 32 | /// 33 | /// 生成 获取类型实例指定索引处值 的 IL 代码。 34 | /// 35 | /// IL 生成器 36 | void EmitElementAt(ILGenerator ilGen); 37 | } 38 | } -------------------------------------------------------------------------------- /Swifter.Data/Sql/NativeStatement.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | namespace Swifter.Data.Sql 4 | { 5 | /// 6 | /// 表示原生 T-SQL 语句。 7 | /// 8 | public sealed class NativeStatement : ITable, IValue 9 | { 10 | readonly Func SqlGetter; 11 | 12 | /// 13 | /// T-SQL 语句。 14 | /// 15 | public string Sql => SqlGetter(); 16 | 17 | /// 18 | /// 初始化原生 T-SQL 语句实例。 19 | /// 20 | /// 获取 T-SQL 的函数 21 | NativeStatement(Func sqlGetter) 22 | { 23 | SqlGetter = sqlGetter; 24 | } 25 | 26 | /// 27 | /// 构建原生 T-SQL 语句。 28 | /// 29 | /// T-SQL 语句 30 | public static implicit operator NativeStatement(string sql) => new NativeStatement(() => sql); 31 | 32 | /// 33 | /// 构建原生 T-SQL 语句。 34 | /// 35 | /// 获取 T-SQL 的函数 36 | public static implicit operator NativeStatement(Func sqlGetter) => new NativeStatement(sqlGetter); 37 | } 38 | } -------------------------------------------------------------------------------- /Swifter.Test/Program.cs: -------------------------------------------------------------------------------- 1 | using Swifter.Json; 2 | using Swifter.Reflection; 3 | using Swifter.RW; 4 | using Swifter.Test; 5 | using Swifter.Tools; 6 | using System; 7 | using System.Collections.Generic; 8 | using System.Diagnostics; 9 | using System.IO; 10 | using System.Text; 11 | using System.Windows.Forms; 12 | 13 | public class Demo 14 | { 15 | public string Name { get; set; } 16 | 17 | public static void Main() 18 | { 19 | //JsonFormatter.CharsPool.Ratio = 0; 20 | //FastObjectRW.DefaultOptions &= ~FastObjectRWOptions.IgnoreCase; 21 | 22 | //Application.Run(new MyForm()); 23 | 24 | //ValueInterface.DefaultObjectInterfaceType = typeof(XObjectInterface<>); 25 | 26 | //var text = Encoding.UTF8.GetString(Resource.catalog); 27 | 28 | //var obj = JsonFormatter.DeserializeObject(text); 29 | 30 | //while (true) 31 | //{ 32 | // var stopwatch = Stopwatch.StartNew(); 33 | 34 | // for (int i = 0; i < 15; i++) 35 | // { 36 | // JsonFormatter.SerializeObject(obj); 37 | // } 38 | 39 | // Console.WriteLine(stopwatch.ElapsedMilliseconds); 40 | //} 41 | } 42 | } 43 | -------------------------------------------------------------------------------- /Swifter.Core/RW/Collection/Generic/ListInterface.cs: -------------------------------------------------------------------------------- 1 | 2 | 3 | using System.Collections.Generic; 4 | 5 | namespace Swifter.RW 6 | { 7 | internal sealed class ListInterface : IValueInterface where T : IList 8 | { 9 | public T ReadValue(IValueReader valueReader) 10 | { 11 | if (valueReader is IValueReader reader) 12 | { 13 | return reader.ReadValue(); 14 | } 15 | else 16 | { 17 | var listRW = new ListRW(); 18 | 19 | valueReader.ReadArray(listRW); 20 | 21 | return listRW.content; 22 | } 23 | 24 | } 25 | 26 | public void WriteValue(IValueWriter valueWriter, T value) 27 | { 28 | if (value is null) 29 | { 30 | valueWriter.DirectWrite(null); 31 | } 32 | else if (valueWriter is IValueWriter writer) 33 | { 34 | writer.WriteValue(value); 35 | } 36 | else 37 | { 38 | valueWriter.WriteArray(new ListRW { content = value }); 39 | } 40 | } 41 | } 42 | } -------------------------------------------------------------------------------- /Swifter.Core/RW/IDataRW.cs: -------------------------------------------------------------------------------- 1 | 2 | 3 | using System; 4 | using System.Collections.Generic; 5 | 6 | namespace Swifter.RW 7 | { 8 | /// 9 | /// 数据读写器 10 | /// 11 | /// 键的类型 12 | public interface IDataRW : IDataRW, IDataReader, IDataWriter 13 | { 14 | /// 15 | /// 获取键集合。 16 | /// 17 | new IEnumerable Keys { get; } 18 | /// 19 | /// 获取指定键的值读写器实例。 20 | /// 21 | /// 指定键 22 | /// 返回值读写器实例 23 | new IValueRW this[TKey key] { get; } 24 | } 25 | 26 | 27 | /// 28 | /// 表示数据读写器 29 | /// 30 | public interface IDataRW : IDataReader, IDataWriter 31 | { 32 | /// 33 | /// 获取读写器的键的数量。 34 | /// 35 | new int Count { get; } 36 | 37 | /// 38 | /// 获取数据源的类型。 39 | /// 40 | new Type ContentType { get; } 41 | 42 | /// 43 | /// 获取或设置数据源。 44 | /// 45 | new object Content { get; set; } 46 | } 47 | } -------------------------------------------------------------------------------- /Swifter.Core/RW/ArrayRW/MultiDimArrayInterface.cs: -------------------------------------------------------------------------------- 1 | namespace Swifter.RW 2 | { 3 | internal sealed class MultiDimArrayInterface : IValueInterface where TArray : class 4 | { 5 | public TArray ReadValue(IValueReader valueReader) 6 | { 7 | if (valueReader is IValueReader reader) 8 | { 9 | return reader.ReadValue(); 10 | } 11 | 12 | var rw = new MultiDimArray.FirstRW(); 13 | 14 | valueReader.ReadArray(rw); 15 | 16 | return rw.GetContent(); 17 | } 18 | 19 | public void WriteValue(IValueWriter valueWriter, TArray value) 20 | { 21 | if (value is null) 22 | { 23 | valueWriter.DirectWrite(null); 24 | } 25 | else if (valueWriter is IValueWriter writer) 26 | { 27 | writer.WriteValue(value); 28 | } 29 | else 30 | { 31 | var rw = new MultiDimArray.FirstRW(); 32 | 33 | rw.Initialize(value); 34 | 35 | valueWriter.WriteArray(rw); 36 | } 37 | } 38 | } 39 | } -------------------------------------------------------------------------------- /Swifter.Core/RW/Basic/VersionInterface.cs: -------------------------------------------------------------------------------- 1 | 2 | 3 | using System; 4 | 5 | namespace Swifter.RW 6 | { 7 | internal sealed class VersionInterface : IValueInterface 8 | { 9 | public Version ReadValue(IValueReader valueReader) 10 | { 11 | if (valueReader is IValueReader versionReader) 12 | { 13 | return versionReader.ReadValue(); 14 | } 15 | 16 | var versionText = valueReader.ReadString(); 17 | 18 | if (versionText is null) 19 | { 20 | return null; 21 | } 22 | 23 | return new Version(versionText); 24 | } 25 | 26 | public void WriteValue(IValueWriter valueWriter, Version value) 27 | { 28 | if (value is null) 29 | { 30 | valueWriter.DirectWrite(null); 31 | 32 | return; 33 | } 34 | 35 | if (valueWriter is IValueWriter versionReader) 36 | { 37 | versionReader.WriteValue(value); 38 | } 39 | else 40 | { 41 | valueWriter.WriteString(value.ToString()); 42 | } 43 | } 44 | } 45 | } -------------------------------------------------------------------------------- /Swifter.Core/RW/Data/DataRowInterface.cs: -------------------------------------------------------------------------------- 1 | 2 | 3 | using System.Data; 4 | 5 | namespace Swifter.RW 6 | { 7 | internal sealed class DataRowInterface : IValueInterface where T : DataRow 8 | { 9 | public T ReadValue(IValueReader valueReader) 10 | { 11 | if (valueReader is IValueReader tReader) 12 | { 13 | return tReader.ReadValue(); 14 | } 15 | 16 | var dataWriter = new DataRowRW(); 17 | 18 | valueReader.ReadObject(dataWriter); 19 | 20 | return dataWriter.datarow; 21 | } 22 | 23 | public void WriteValue(IValueWriter valueWriter, T value) 24 | { 25 | if (value is null) 26 | { 27 | valueWriter.DirectWrite(null); 28 | 29 | return; 30 | } 31 | 32 | if (valueWriter is IValueWriter tWriter) 33 | { 34 | tWriter.WriteValue(value); 35 | 36 | return; 37 | } 38 | 39 | var dataReader = new DataRowRW 40 | { 41 | datarow = value 42 | }; 43 | 44 | valueWriter.WriteObject(dataReader); 45 | } 46 | } 47 | } -------------------------------------------------------------------------------- /Swifter.Core/Tools/Type/CloneHelper.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Reflection; 3 | using System.Runtime.CompilerServices; 4 | 5 | namespace Swifter.Tools 6 | { 7 | internal static unsafe class CloneHelper 8 | { 9 | public static readonly IntPtr p_MemberwiseClone; 10 | 11 | static CloneHelper() 12 | { 13 | p_MemberwiseClone = typeof(object).GetMethod(nameof(MemberwiseClone), BindingFlags.NonPublic | BindingFlags.Instance).MethodHandle.GetFunctionPointer(); 14 | } 15 | 16 | [MethodImpl(VersionDifferences.AggressiveInlining)] 17 | public static object MemberwiseClone(object obj) 18 | { 19 | return Underlying.Invoke(obj, p_MemberwiseClone); 20 | } 21 | 22 | [MethodImpl(VersionDifferences.AggressiveInlining)] 23 | public static string CloneString(string str) 24 | { 25 | fixed (char* pStr = str) 26 | return StringHelper.ToString(pStr, str.Length); 27 | } 28 | 29 | [MethodImpl(VersionDifferences.AggressiveInlining)] 30 | public static Array CloneArray(Array array) 31 | { 32 | return Underlying.As(array.Clone()); 33 | } 34 | } 35 | } -------------------------------------------------------------------------------- /Swifter.Test/Helper.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Data; 3 | using System.Windows.Forms; 4 | 5 | namespace Swifter.Test 6 | { 7 | public static class Helper 8 | { 9 | public static DataRow DataTableNewRow(this Control control, DataTable dataTable) 10 | { 11 | Func method = (table) => 12 | { 13 | return table.NewRow(); 14 | }; 15 | 16 | return (DataRow)control.Invoke(method, dataTable); 17 | } 18 | 19 | public static void SetCellValue(this Control control, DataRow dataRow, string cellName, object value) 20 | { 21 | Action method = (row, name, val) => 22 | { 23 | row[name] = val; 24 | }; 25 | 26 | control.Invoke(method, dataRow, cellName, value); 27 | } 28 | 29 | public static void DataTableAddRow(this Control control, DataTable dataTable, DataRow dataRow) 30 | { 31 | Action method = (table, row) => 32 | { 33 | table.Rows.Add(row); 34 | }; 35 | 36 | control.Invoke(method, dataTable, dataRow); 37 | } 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /Swifter.Core/RW/Data/DataSetInterface.cs: -------------------------------------------------------------------------------- 1 | 2 | 3 | using System.Data; 4 | 5 | namespace Swifter.RW 6 | { 7 | internal sealed class DataSetInterface : IValueInterface where T : DataSet 8 | { 9 | public T ReadValue(IValueReader valueReader) 10 | { 11 | if (valueReader is IValueReader tReader) 12 | { 13 | return tReader.ReadValue(); 14 | } 15 | 16 | var dataReader = new DataSetRW(); 17 | 18 | valueReader.ReadArray(dataReader); 19 | 20 | return dataReader.dataset; 21 | } 22 | 23 | public void WriteValue(IValueWriter valueWriter, T value) 24 | { 25 | if (value is null) 26 | { 27 | valueWriter.DirectWrite(null); 28 | 29 | return; 30 | } 31 | 32 | if (valueWriter is IValueWriter tWriter) 33 | { 34 | tWriter.WriteValue(value); 35 | 36 | return; 37 | } 38 | 39 | var dataReader = new DataSetRW 40 | { 41 | dataset = value 42 | }; 43 | 44 | valueWriter.WriteArray(dataReader); 45 | } 46 | } 47 | } -------------------------------------------------------------------------------- /Swifter.FSharpExtensions/FSharpListInterface.cs: -------------------------------------------------------------------------------- 1 | using Microsoft.FSharp.Collections; 2 | using Swifter.RW; 3 | 4 | namespace Swifter.FSharpExtensions 5 | { 6 | public sealed class FSharpListInterface : IValueInterface> 7 | { 8 | public FSharpList ReadValue(IValueReader valueReader) 9 | { 10 | if (valueReader is IValueReader> reader) 11 | { 12 | return reader.ReadValue(); 13 | } 14 | else 15 | { 16 | var rw = new FSharpListRW(); 17 | 18 | valueReader.ReadArray(rw); 19 | 20 | return rw.content; 21 | } 22 | } 23 | 24 | public void WriteValue(IValueWriter valueWriter, FSharpList value) 25 | { 26 | if (value is null) 27 | { 28 | valueWriter.DirectWrite(null); 29 | } 30 | else if (valueWriter is IValueWriter> writer) 31 | { 32 | writer.WriteValue(value); 33 | } 34 | else 35 | { 36 | valueWriter.WriteArray(new FSharpListRW { content = value }); 37 | } 38 | } 39 | } 40 | } -------------------------------------------------------------------------------- /Swifter.Core/RW/Basic/TimeSpanInterface.cs: -------------------------------------------------------------------------------- 1 | 2 | using Swifter.Tools; 3 | 4 | using System; 5 | 6 | namespace Swifter.RW 7 | { 8 | internal sealed class TimeSpanInterface : IValueInterface 9 | { 10 | public TimeSpan ReadValue(IValueReader valueReader) 11 | { 12 | if (valueReader is IValueReader timeSpanReader) 13 | { 14 | return timeSpanReader.ReadValue(); 15 | } 16 | 17 | object directValue = valueReader.DirectRead(); 18 | 19 | if (directValue is TimeSpan) 20 | { 21 | return (TimeSpan)directValue; 22 | } 23 | 24 | if (directValue is string) 25 | { 26 | return TimeSpan.Parse((string)directValue); 27 | } 28 | 29 | return XConvert.FromObject(directValue); 30 | } 31 | 32 | public void WriteValue(IValueWriter valueWriter, TimeSpan value) 33 | { 34 | if (valueWriter is IValueWriter timeSpanWriter) 35 | { 36 | timeSpanWriter.WriteValue(value); 37 | 38 | return; 39 | } 40 | 41 | valueWriter.DirectWrite(value); 42 | } 43 | } 44 | } -------------------------------------------------------------------------------- /Swifter.Core/RW/Helper/AsWriteAllReader.cs: -------------------------------------------------------------------------------- 1 | using Swifter.Tools; 2 | using System; 3 | using System.Collections.Generic; 4 | using System.Linq; 5 | 6 | namespace Swifter.RW 7 | { 8 | sealed class AsWriteAllReader : IDataReader 9 | { 10 | public readonly IDataReader dataReader; 11 | 12 | public AsWriteAllReader(IDataReader dataReader) 13 | { 14 | this.dataReader = dataReader; 15 | } 16 | 17 | public IValueReader this[TIn key] => dataReader[XConvert.Convert(key)]; 18 | 19 | public IEnumerable Keys => dataReader.Keys.Select(key => XConvert.Convert(key)); 20 | 21 | public int Count => dataReader.Count; 22 | 23 | public object Content 24 | { 25 | get => dataReader.Content; 26 | set => dataReader.Content = value; 27 | } 28 | 29 | public Type ContentType => dataReader.ContentType; 30 | 31 | public void OnReadAll(IDataWriter dataWriter) => 32 | dataReader.OnReadAll(new AsReadAllWriter(dataWriter)); 33 | 34 | public void OnReadValue(TIn key, IValueWriter valueWriter) => 35 | dataReader.OnReadValue(XConvert.Convert(key), valueWriter); 36 | } 37 | } -------------------------------------------------------------------------------- /Swifter.Core/Tools/Storage/THashAlgorithmInstances.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Reflection; 3 | using System.Runtime.CompilerServices; 4 | using System.Security.Cryptography; 5 | 6 | namespace Swifter.Tools 7 | { 8 | static class THashAlgorithmInstances where THashAlgorithm : HashAlgorithm 9 | { 10 | [ThreadStatic] 11 | static THashAlgorithm instance; 12 | 13 | public static THashAlgorithm Instance => instance ?? Create(); 14 | 15 | [MethodImpl(MethodImplOptions.NoInlining)] 16 | static THashAlgorithm Create() 17 | { 18 | var createMethod = typeof(THashAlgorithm).GetMethod( 19 | nameof(HashAlgorithm.Create), 20 | BindingFlags.Public | BindingFlags.Static | BindingFlags.DeclaredOnly, 21 | Type.DefaultBinder, 22 | Type.EmptyTypes, 23 | null); 24 | 25 | if (createMethod != null) 26 | { 27 | instance = (THashAlgorithm)createMethod.Invoke(null, new object[] { }); 28 | } 29 | else 30 | { 31 | instance = Activator.CreateInstance(); 32 | } 33 | 34 | return instance; 35 | } 36 | } 37 | } -------------------------------------------------------------------------------- /Swifter.Core/Tools/Storage/HGlobalCacheExtensions.Core.cs: -------------------------------------------------------------------------------- 1 | 2 | #if Span 3 | 4 | using System; 5 | using System.Runtime.CompilerServices; 6 | using System.Text; 7 | 8 | namespace Swifter.Tools 9 | { 10 | unsafe partial class HGlobalCacheExtensions 11 | { 12 | /// 13 | /// 将 source 的内容缓存到 HGlobalCache 中。 14 | /// 15 | /// HGlobalCache 16 | /// source 17 | /// 编码 18 | /// 返回缓冲的长度 19 | public static void ReadFrom(this HGlobalCache hGCache, ReadOnlySpan source, Encoding encoding) 20 | { 21 | hGCache.Grow(encoding.GetMaxCharCount(source.Length)); 22 | 23 | hGCache.Count += encoding.GetChars(source, new Span(hGCache.Current, hGCache.Rest)); 24 | } 25 | 26 | /// 27 | /// 将字节码转换为 16 进制字符串。 28 | /// 29 | /// 字节码 30 | /// 返回一个字符串 31 | public static string ToHexString(this ReadOnlySpan bytes) 32 | { 33 | return ToHexString(ref Underlying.AsRef(bytes[0]), bytes.Length); 34 | } 35 | } 36 | } 37 | 38 | #endif -------------------------------------------------------------------------------- /Swifter.Core/Tools/Task/TaskHelper.cs: -------------------------------------------------------------------------------- 1 | #if Async 2 | 3 | using System.Runtime.CompilerServices; 4 | using System.Threading.Tasks; 5 | 6 | namespace Swifter.Tools 7 | { 8 | /// 9 | /// 提供异步任务的工具函数。 10 | /// 11 | public static class TaskHelper 12 | { 13 | 14 | /// 15 | /// 不等待该任务执行完成。 16 | /// 17 | [MethodImpl(VersionDifferences.AggressiveInlining)] 18 | public static void NoWait(this Task _) 19 | { 20 | } 21 | 22 | /// 23 | /// 不等待该任务执行完成。 24 | /// 25 | [MethodImpl(VersionDifferences.AggressiveInlining)] 26 | public static void NoWait(this Task _) 27 | { 28 | } 29 | 30 | 31 | #if ValueTask 32 | 33 | /// 34 | /// 不等待该任务执行完成。 35 | /// 36 | [MethodImpl(VersionDifferences.AggressiveInlining)] 37 | public static void NoWait(this ValueTask _) 38 | { 39 | } 40 | 41 | /// 42 | /// 不等待该任务执行完成。 43 | /// 44 | [MethodImpl(VersionDifferences.AggressiveInlining)] 45 | public static void NoWait(this ValueTask _) 46 | { 47 | } 48 | 49 | #endif 50 | } 51 | } 52 | 53 | #endif -------------------------------------------------------------------------------- /Swifter.Core/RW/Collection/EnumeratorReader.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections; 3 | using System.Collections.Generic; 4 | 5 | namespace Swifter.RW 6 | { 7 | internal sealed class EnumeratorReader : IDataReader where T : IEnumerator 8 | { 9 | internal T content; 10 | 11 | public IValueReader this[int key] => throw new NotSupportedException(); 12 | 13 | public IEnumerable Keys => throw new NotSupportedException(); 14 | 15 | public int Count => -1; 16 | 17 | public Type ContentType => typeof(T); 18 | 19 | public object Content 20 | { 21 | get => content; 22 | set => Initialize((T)value); 23 | } 24 | 25 | public void Initialize(T obj) 26 | { 27 | content = obj; 28 | } 29 | 30 | public void OnReadAll(IDataWriter dataWriter) 31 | { 32 | int index = 0; 33 | 34 | while (content.MoveNext()) 35 | { 36 | ValueInterface.WriteValue(dataWriter[index], content.Current); 37 | 38 | ++index; 39 | } 40 | } 41 | 42 | public void OnReadValue(int key, IValueWriter valueWriter) 43 | { 44 | throw new NotSupportedException(); 45 | } 46 | } 47 | } -------------------------------------------------------------------------------- /Swifter.Core/Tools/Storage/HGlobalCache.Core.cs: -------------------------------------------------------------------------------- 1 | #if Span 2 | using System; 3 | 4 | namespace Swifter.Tools 5 | { 6 | unsafe partial class HGlobalCache 7 | { 8 | /// 9 | /// 返回全局缓存中的空间 Span。 10 | /// 11 | /// 全局缓存 12 | public static implicit operator Span(HGlobalCache hGCache) => new Span(hGCache.First, hGCache.Available); 13 | 14 | /// 15 | /// 返回全局缓存中的内容 Span。 16 | /// 17 | /// 全局缓存 18 | public static implicit operator ReadOnlySpan(HGlobalCache hGCache) => new ReadOnlySpan(hGCache.First, hGCache.Count); 19 | 20 | /// 21 | /// 返回全局缓存中的空间 Memory。 22 | /// 23 | /// 24 | public static implicit operator Memory(HGlobalCache hGCache) => new Memory(hGCache.Context, hGCache.Offset, hGCache.Available); 25 | 26 | /// 27 | /// 返回全局缓存中的内容 Memory。 28 | /// 29 | /// 30 | public static implicit operator ReadOnlyMemory(HGlobalCache hGCache) => new ReadOnlyMemory(hGCache.Context, hGCache.Offset, hGCache.Count); 31 | } 32 | } 33 | #endif -------------------------------------------------------------------------------- /Swifter.Data/Sql/Case.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | 4 | namespace Swifter.Data.Sql 5 | { 6 | /// 7 | /// Case 语句。 8 | /// 9 | public sealed class Case : IValue 10 | { 11 | /// 12 | /// Case 项集合。 13 | /// 14 | public List Items { get; } 15 | 16 | /// 17 | /// 底值。 18 | /// 19 | public IValue Else { get; set; } 20 | 21 | /// 22 | /// 构建 Case 语句。 23 | /// 24 | public Case() 25 | { 26 | Else = SqlHelper.ValueOf(DBNull.Value); 27 | Items = new List(); 28 | } 29 | 30 | /// 31 | /// Case 项。 32 | /// 33 | public sealed class Item 34 | { 35 | /// 36 | /// 条件。 37 | /// 38 | public Condition When { get; } 39 | 40 | /// 41 | /// 值。 42 | /// 43 | public IValue Then { get; } 44 | 45 | internal Item(Condition when, IValue then) 46 | { 47 | When = when; 48 | Then = then; 49 | } 50 | } 51 | } 52 | } -------------------------------------------------------------------------------- /Swifter.Test.WPF/Swifter.Test.WPF.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | WinExe 5 | netcoreapp3.0 6 | true 7 | true 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | -------------------------------------------------------------------------------- /Swifter.Core/RW/Data/DataTableInterface.cs: -------------------------------------------------------------------------------- 1 | using System.Data; 2 | using static Swifter.RW.DataTableRW; 3 | 4 | namespace Swifter.RW 5 | { 6 | internal sealed class DataTableInterface : IValueInterface where T : DataTable 7 | { 8 | public T ReadValue(IValueReader valueReader) 9 | { 10 | if (valueReader is IValueReader reader) 11 | { 12 | return reader.ReadValue(); 13 | } 14 | 15 | var writer = new DataTableRW(GetDataTableRWOptions(valueReader)); 16 | 17 | valueReader.ReadArray(writer); 18 | 19 | return writer.datatable; 20 | } 21 | 22 | public void WriteValue(IValueWriter valueWriter, T value) 23 | { 24 | if (value is null) 25 | { 26 | valueWriter.DirectWrite(null); 27 | 28 | return; 29 | } 30 | 31 | if (valueWriter is IValueWriter weiter) 32 | { 33 | weiter.WriteValue(value); 34 | 35 | return; 36 | } 37 | 38 | var reader = new DataTableRW(GetDataTableRWOptions(valueWriter)) 39 | { 40 | datatable = value 41 | }; 42 | 43 | valueWriter.WriteArray(reader); 44 | } 45 | } 46 | } -------------------------------------------------------------------------------- /Swifter.Core/VersionDifferences/BinaryPrimitives.cs: -------------------------------------------------------------------------------- 1 | #if NET20 || NET35 || NET40 || NET45 || NET47 || NETSTANDARD2_0 || NETCOREAPP2_0 2 | 3 | using Swifter; 4 | using System.Runtime.CompilerServices; 5 | 6 | #pragma warning disable 1591 7 | 8 | namespace System.Buffers.Binary 9 | { 10 | public static class BinaryPrimitives 11 | { 12 | [MethodImpl(VersionDifferences.AggressiveInlining)] 13 | public static ushort ReverseEndianness(ushort value) => (ushort)((value >> 8) + (value << 8)); 14 | 15 | [MethodImpl(VersionDifferences.AggressiveInlining)] 16 | public static uint ReverseEndianness(uint value) => RotateRight(value & 0x00FF00FFu, 8) + RotateLeft(value & 0xFF00FF00u, 8); 17 | 18 | [MethodImpl(VersionDifferences.AggressiveInlining)] 19 | public static ulong ReverseEndianness(ulong value) => ((ulong)ReverseEndianness((uint)value) << 32) + ReverseEndianness((uint)(value >> 32)); 20 | 21 | [MethodImpl(VersionDifferences.AggressiveInlining)] 22 | public static uint RotateRight(uint value, int offset) => (value >> offset) | (value << (32 - offset)); 23 | 24 | [MethodImpl(VersionDifferences.AggressiveInlining)] 25 | public static uint RotateLeft(uint value, int offset) => (value << offset) | (value >> (32 - offset)); 26 | } 27 | } 28 | 29 | #endif -------------------------------------------------------------------------------- /Swifter.Core/Tools/Number/DecimalStruct.cs: -------------------------------------------------------------------------------- 1 | using System.Runtime.InteropServices; 2 | 3 | namespace Swifter.Tools 4 | { 5 | [StructLayout(LayoutKind.Sequential)] 6 | struct DecimalStruct 7 | { 8 | private const int SignMask = unchecked((int)0x80000000); 9 | private const int ScaleMask = 0x00FF0000; 10 | private const int ScaleShift = 16; 11 | 12 | #pragma warning disable IDE0044 13 | 14 | private int flags; 15 | private int hi; 16 | private int lo; 17 | private int mid; 18 | 19 | public int Scale 20 | { 21 | get => (flags & ScaleMask) >> ScaleShift; 22 | set => flags = (flags & (~ScaleMask)) | ((value << ScaleShift) & ScaleMask); 23 | } 24 | 25 | public int Sign 26 | { 27 | get => flags & SignMask; 28 | set => flags = value == 0 ? flags & (~SignMask) : flags | SignMask; 29 | } 30 | 31 | public unsafe void GetBits(int* pBits) 32 | { 33 | pBits[0] = lo; 34 | pBits[2] = hi; 35 | pBits[1] = mid; 36 | } 37 | 38 | public unsafe void SetBits(int* pBits) 39 | { 40 | mid = pBits[1]; 41 | hi = pBits[2]; 42 | lo = pBits[0]; 43 | flags = 0; 44 | } 45 | } 46 | } -------------------------------------------------------------------------------- /Swifter.Core/RW/Basic/DateTimeOffsetInterface.cs: -------------------------------------------------------------------------------- 1 | 2 | using Swifter.Tools; 3 | 4 | using System; 5 | 6 | namespace Swifter.RW 7 | { 8 | internal sealed class DateTimeOffsetInterface : IValueInterface 9 | { 10 | public DateTimeOffset ReadValue(IValueReader valueReader) 11 | { 12 | if (valueReader is IValueReader dateTimeOffsetReader) 13 | { 14 | return dateTimeOffsetReader.ReadValue(); 15 | } 16 | 17 | object directValue = valueReader.DirectRead(); 18 | 19 | if (directValue is DateTimeOffset) 20 | { 21 | return (DateTimeOffset)directValue; 22 | } 23 | 24 | if (directValue is string) 25 | { 26 | return DateTimeOffset.Parse((string)directValue); 27 | } 28 | 29 | return XConvert.FromObject(directValue); 30 | } 31 | 32 | public void WriteValue(IValueWriter valueWriter, DateTimeOffset value) 33 | { 34 | if (valueWriter is IValueWriter dateTimeOffsetWriter) 35 | { 36 | dateTimeOffsetWriter.WriteValue(value); 37 | 38 | return; 39 | } 40 | 41 | valueWriter.DirectWrite(value); 42 | } 43 | } 44 | } -------------------------------------------------------------------------------- /Swifter.Core/Tools/Convert/BasicConvert.Overload.tt: -------------------------------------------------------------------------------- 1 | <#@ template debug="false" hostspecific="false" language="C#" #> 2 | <#@ assembly name="System.Core" #> 3 | <#@ Assembly name="$(TargetPath)" #> 4 | <#@ import namespace="Swifter.Tools" #> 5 | <#@ import namespace="System.Linq" #> 6 | <#@ import namespace="System.Text" #> 7 | <#@ import namespace="System.Collections.Generic" #> 8 | <#@ import namespace="System.Reflection" #> 9 | <#@ import namespace="static Swifter.Tools.BasicConvert" #> 10 | <#@ output extension=".cs" #> 11 | 12 | <# 13 | 14 | var ClassName = "BasicConvert"; 15 | var methods = GetConvertMethods(); 16 | 17 | #> 18 | 19 | using System; 20 | 21 | namespace Swifter.Tools 22 | { 23 | partial class <#= ClassName #> : 24 | <# foreach(var method in methods) { #> 25 | IXConvert<<#= GetCodeName(method.GetParameters()[0].ParameterType) #>, <#= GetCodeName(method.ReturnType) #>>, 26 | <# } #> 27 | I<#= ClassName #> 28 | { 29 | <# foreach(var method in methods) { #> 30 | <#= GetCodeName(method.ReturnType) #> IXConvert<<#= GetCodeName(method.GetParameters()[0].ParameterType) #>, <#= GetCodeName(method.ReturnType) #>>.Convert(<#= GetCodeName(method.GetParameters()[0].ParameterType) #> value) 31 | => <#= GetCodeName(method.DeclaringType) #>.<#= method.Name #>(value); 32 | 33 | <# } #> 34 | } 35 | 36 | interface I<#= ClassName #> {} 37 | 38 | } -------------------------------------------------------------------------------- /Swifter.Data/Sql/Select/Join.cs: -------------------------------------------------------------------------------- 1 | namespace Swifter.Data.Sql 2 | { 3 | /// 4 | /// 表连接信息 5 | /// 6 | public sealed class Join 7 | { 8 | /// 9 | /// 构建表连接信息信息 10 | /// 11 | /// 连接方向 12 | /// 要连接的表 13 | public Join(JoinDirections direction, ITable table) 14 | { 15 | Direction = direction; 16 | Table = table; 17 | 18 | On = new Conditions(); 19 | } 20 | 21 | /// 22 | /// 构建表连接信息信息 23 | /// 24 | /// 连接方向 25 | /// 要连接的表 26 | /// 连接条件 27 | public Join(JoinDirections direction, ITable table, Condition condition) : this(direction, table) 28 | { 29 | On.Add(condition); 30 | } 31 | 32 | /// 33 | /// 要连接的表 34 | /// 35 | public ITable Table { get; } 36 | 37 | /// 38 | /// 连接条件 39 | /// 40 | public Conditions On { get; } 41 | 42 | /// 43 | /// 连接方向 44 | /// 45 | public JoinDirections Direction { get; } 46 | } 47 | } -------------------------------------------------------------------------------- /Swifter.Core/RW/Data/DataInterfaceMaper.cs: -------------------------------------------------------------------------------- 1 | 2 | using System; 3 | using System.Data; 4 | 5 | namespace Swifter.RW 6 | { 7 | internal sealed class DataInterfaceMaper : IValueInterfaceMaper 8 | { 9 | public IValueInterface TryMap() 10 | { 11 | var type = typeof(T); 12 | 13 | if (typeof(System.Data.IDataReader).IsAssignableFrom(type)) 14 | { 15 | return CreateInstance(typeof(DbDataReaderInterface<>).MakeGenericType(typeof(T))); 16 | } 17 | 18 | if (typeof(DataRow).IsAssignableFrom(type)) 19 | { 20 | return CreateInstance(typeof(DataRowInterface<>).MakeGenericType(typeof(T))); 21 | } 22 | 23 | if (typeof(DataTable).IsAssignableFrom(type)) 24 | { 25 | return CreateInstance(typeof(DataTableInterface<>).MakeGenericType(typeof(T))); 26 | } 27 | 28 | if (typeof(DataSet).IsAssignableFrom(type)) 29 | { 30 | return CreateInstance(typeof(DataSetInterface<>).MakeGenericType(typeof(T))); 31 | } 32 | 33 | return null; 34 | 35 | static IValueInterface CreateInstance(Type type) 36 | { 37 | return (IValueInterface)Activator.CreateInstance(type); 38 | } 39 | } 40 | } 41 | } -------------------------------------------------------------------------------- /Swifter.Core/Tools/Emit/LengthGroup.cs: -------------------------------------------------------------------------------- 1 | using System.Collections.Generic; 2 | using System.Linq; 3 | 4 | namespace Swifter.Tools 5 | { 6 | internal class LengthGroup : BaseGroup 7 | { 8 | public readonly List<(int length, BaseGroup group)> Groups; 9 | 10 | public LengthGroup(CaseInfo[] strs, IDifferenceComparer comparer) : base(comparer, strs.Length) 11 | { 12 | var groups = new Dictionary>>(); 13 | 14 | foreach (var item in strs) 15 | { 16 | if (!groups.TryGetValue(Comparer.GetLength(item.Value), out var list)) 17 | { 18 | groups[Comparer.GetLength(item.Value)] = list = new List>(); 19 | } 20 | 21 | list.Add(item); 22 | } 23 | 24 | Groups = new List<(int, BaseGroup)>(); 25 | 26 | foreach (var item in groups) 27 | { 28 | var group = item.Value.Count == 1 ? (BaseGroup)new SingleGroup(item.Value[0], comparer) : new DifferenceGroup(item.Value, comparer); 29 | 30 | Groups.Add((item.Key, group)); 31 | } 32 | 33 | Groups.Sort((x, y) => x.length.CompareTo(y.length)); 34 | } 35 | 36 | public override int GetDepth() => Groups.Max(item => item.group.GetDepth()) + 1; 37 | } 38 | } -------------------------------------------------------------------------------- /Swifter.Json/JsonFilteringEventArgs.cs: -------------------------------------------------------------------------------- 1 | using Swifter.RW; 2 | using System; 3 | using System.ComponentModel; 4 | 5 | namespace Swifter.Json 6 | { 7 | /// 8 | /// JSON 事件委托。 9 | /// 10 | /// 事件类型 11 | /// 发送者 12 | /// 事件参数 13 | public delegate void JsonEventHandler(object sender, ref TEventArgs e) where TEventArgs : struct; 14 | 15 | /// 16 | /// JSON 序列化元素时事件参数。 17 | /// 18 | /// 元素键类型 19 | [EditorBrowsable(EditorBrowsableState.Never)] 20 | public struct JsonFilteringEventArgs 21 | { 22 | /// 23 | /// 当前 Json 写入器。 24 | /// 25 | public readonly IJsonWriter JsonWriter; 26 | 27 | /// 28 | /// 当前值信息。 29 | /// 30 | public readonly ValueFilterInfo ValueInfo; 31 | 32 | /// 33 | /// 是否写入该值。 34 | /// 35 | public bool Result; 36 | 37 | internal JsonFilteringEventArgs(IJsonWriter jsonWriter, ValueFilterInfo valueInfo, bool result) 38 | { 39 | JsonWriter = jsonWriter; 40 | ValueInfo = valueInfo; 41 | Result = result; 42 | } 43 | } 44 | } -------------------------------------------------------------------------------- /Swifter.Core/RW/Basic/EnumInterface.cs: -------------------------------------------------------------------------------- 1 | using Swifter.Tools; 2 | using System; 3 | 4 | namespace Swifter.RW 5 | { 6 | internal sealed class EnumInterface : IValueInterface where T : struct, Enum 7 | { 8 | /// 9 | /// 枚举的 TypeCode。 10 | /// 11 | public static readonly TypeCode TypeCode = Type.GetTypeCode(typeof(T)); 12 | 13 | /// 14 | /// 表示此枚举是否是标识符。 15 | /// 16 | public static readonly bool IsFlags = typeof(T).IsDefined(typeof(FlagsAttribute), false); 17 | 18 | /// 19 | /// 枚举值和名称的集合。 20 | /// 21 | public static readonly (ulong Value, string Name)[] Items; 22 | 23 | static EnumInterface() 24 | { 25 | var values = (T[])Enum.GetValues(typeof(T)); 26 | 27 | Items = new (ulong, string)[values.Length]; 28 | 29 | for (int i = 0; i < values.Length; i++) 30 | { 31 | Items[i] = (EnumHelper.AsUInt64(values[i]), Enum.GetName(typeof(T), values[i])); 32 | } 33 | } 34 | 35 | public T ReadValue(IValueReader valueReader) 36 | { 37 | return valueReader.ReadEnum(); 38 | } 39 | 40 | public void WriteValue(IValueWriter valueWriter, T value) 41 | { 42 | valueWriter.WriteEnum(value); 43 | } 44 | } 45 | } -------------------------------------------------------------------------------- /Swifter.Core/Formatters/FormatterHelper.Core.cs: -------------------------------------------------------------------------------- 1 | #if Span 2 | 3 | using Swifter.RW; 4 | using System; 5 | using System.Runtime.CompilerServices; 6 | 7 | namespace Swifter.Formatters 8 | { 9 | partial class FormatterHelper 10 | { 11 | /// 12 | /// 将文档字符串反序列化到指定的对象中。 13 | /// 14 | /// 对象类型 15 | /// 文档反序列化器 16 | /// 文档字符串 17 | /// 对象 18 | [MethodImpl(VersionDifferences.AggressiveInlining)] 19 | public static void DeserializeTo(this ITextFormatter textFormatter, ReadOnlySpan text, T obj) 20 | { 21 | textFormatter.DeserializeTo(text, RWHelper.CreateWriter(obj)); 22 | } 23 | 24 | /// 25 | /// 将字节码内容反序列化到指定的对象中。 26 | /// 27 | /// 对象类型 28 | /// 字节码反序列化器 29 | /// 文档字符串 30 | /// 对象 31 | [MethodImpl(VersionDifferences.AggressiveInlining)] 32 | public static void DeserializeTo(this IBinaryFormatter binaryFromatter, ReadOnlySpan text, T obj) 33 | { 34 | binaryFromatter.DeserializeTo(text, RWHelper.CreateWriter(obj)); 35 | } 36 | } 37 | } 38 | #endif -------------------------------------------------------------------------------- /Swifter.Core/RW/Helper/AsReadAllWriter.cs: -------------------------------------------------------------------------------- 1 | 2 | using Swifter.Tools; 3 | using System; 4 | using System.Collections.Generic; 5 | using System.Linq; 6 | 7 | namespace Swifter.RW 8 | { 9 | sealed class AsReadAllWriter : IDataWriter 10 | { 11 | public readonly IDataWriter dataWriter; 12 | 13 | public AsReadAllWriter(IDataWriter dataWriter) 14 | { 15 | this.dataWriter = dataWriter; 16 | } 17 | 18 | public IValueWriter this[TIn key] => dataWriter[XConvert.Convert(key)]; 19 | 20 | public IEnumerable Keys => dataWriter.Keys.Select(key => XConvert.Convert(key)); 21 | 22 | public int Count => dataWriter.Count; 23 | 24 | public void Initialize()=> dataWriter.Initialize(); 25 | 26 | public void Initialize(int capacity) => dataWriter.Initialize(capacity); 27 | 28 | public void OnWriteAll(IDataReader dataReader) => 29 | dataWriter.OnWriteAll(new AsWriteAllReader(dataReader)); 30 | 31 | public void OnWriteValue(TIn key, IValueReader valueReader)=> 32 | dataWriter.OnWriteValue(XConvert.Convert(key), valueReader); 33 | 34 | public object Content 35 | { 36 | get => dataWriter.Content; 37 | set => dataWriter.Content = value; 38 | } 39 | 40 | public Type ContentType => dataWriter.ContentType; 41 | } 42 | } -------------------------------------------------------------------------------- /Swifter.Core/Tools/Type/OverlappedValue.cs: -------------------------------------------------------------------------------- 1 | using Swifter.RW; 2 | using System; 3 | using System.Runtime.InteropServices; 4 | 5 | #pragma warning disable 1591 6 | 7 | namespace Swifter.Tools 8 | { 9 | /// 10 | /// 一个重叠的基础类型集合。 11 | /// 12 | [StructLayout(LayoutKind.Explicit)] 13 | public struct OverlappedValue 14 | { 15 | [FieldOffset(0)] 16 | public bool Boolean; 17 | [FieldOffset(0)] 18 | public sbyte SByte; 19 | [FieldOffset(0)] 20 | public short Int16; 21 | [FieldOffset(0)] 22 | public int Int32; 23 | [FieldOffset(0)] 24 | public long Int64; 25 | [FieldOffset(0)] 26 | public byte Byte; 27 | [FieldOffset(0)] 28 | public ushort UInt16; 29 | [FieldOffset(0)] 30 | public uint UInt32; 31 | [FieldOffset(0)] 32 | public ulong UInt64; 33 | [FieldOffset(0)] 34 | public float Single; 35 | [FieldOffset(0)] 36 | public double Double; 37 | [FieldOffset(0)] 38 | public decimal Decimal; 39 | [FieldOffset(0)] 40 | public char Char; 41 | [FieldOffset(0)] 42 | public DateTime DateTime; 43 | [FieldOffset(16)] 44 | public object Object; 45 | [FieldOffset(16)] 46 | public string String; 47 | [FieldOffset(16)] 48 | public IDataReader DataReader; 49 | } 50 | } 51 | -------------------------------------------------------------------------------- /Swifter.Data/Sql/SqlBuilderParameters.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | 4 | namespace Swifter.Data.Sql 5 | { 6 | /// 7 | /// T-SQL 生成器使用的参数列表。 8 | /// 9 | public sealed class SqlBuilderParameters : Dictionary 10 | { 11 | const string ParamName = "__PARAM"; 12 | 13 | readonly Dictionary Map; 14 | 15 | int ParametersNum; 16 | 17 | /// 18 | /// 初始化 T-SQL 生成器使用的参数列表。 19 | /// 20 | public SqlBuilderParameters():base(StringComparer.OrdinalIgnoreCase) 21 | { 22 | Map = new Dictionary(); 23 | } 24 | 25 | /// 26 | /// 添加或获取参数。 27 | /// 28 | /// 参数值 29 | /// 返回参数名 30 | public string GetOrAddParameter(object value) 31 | { 32 | if (!Map.TryGetValue(value, out var name)) 33 | { 34 | name = $"{ParamName}{++ParametersNum}"; 35 | 36 | Map.Add(value, name); 37 | Add(name, value); 38 | } 39 | 40 | return name; 41 | } 42 | 43 | /// 44 | /// 清空参数集合。 45 | /// 46 | public void ClearParameters() 47 | { 48 | Clear(); 49 | Map.Clear(); 50 | } 51 | } 52 | } -------------------------------------------------------------------------------- /Swifter.MessagePack/MessagePackFilteringEventArgs.cs: -------------------------------------------------------------------------------- 1 | using Swifter.RW; 2 | using System; 3 | using System.ComponentModel; 4 | 5 | namespace Swifter.MessagePack 6 | { 7 | /// 8 | /// MessagePack 事件委托。 9 | /// 10 | /// 事件类型 11 | /// 发送者 12 | /// 事件参数 13 | public delegate void MessagePackEventHandler(object sender, ref TEventArgs e) where TEventArgs : struct; 14 | 15 | /// 16 | /// MessagePack 序列化元素时事件参数。 17 | /// 18 | /// 元素键类型 19 | [EditorBrowsable(EditorBrowsableState.Never)] 20 | public struct MessagePackFilteringEventArgs 21 | { 22 | /// 23 | /// 当前 MessagePack 写入器。 24 | /// 25 | public readonly IMessagePackWriter JsonWriter; 26 | 27 | /// 28 | /// 当前值信息。 29 | /// 30 | public readonly ValueFilterInfo ValueInfo; 31 | 32 | /// 33 | /// 是否写入该值。 34 | /// 35 | public bool Result; 36 | 37 | internal MessagePackFilteringEventArgs(IMessagePackWriter jsonWriter, ValueFilterInfo valueInfo, bool result) 38 | { 39 | JsonWriter = jsonWriter; 40 | ValueInfo = valueInfo; 41 | Result = result; 42 | } 43 | } 44 | } -------------------------------------------------------------------------------- /Swifter.MessagePack/IMessagePackWriter.cs: -------------------------------------------------------------------------------- 1 | using Swifter.RW; 2 | 3 | using System; 4 | 5 | namespace Swifter.MessagePack 6 | { 7 | /// 8 | /// MessagePack Writer. 9 | /// 10 | public interface IMessagePackWriter : IValueWriter 11 | { 12 | /// 13 | /// 获取已写入的字节数。 14 | /// 15 | int Offset { get; } 16 | /// 17 | /// 设置已写入的 MessagePack 内容长度到 HGCache 的内容数量中。 18 | /// 19 | void Flush(); 20 | 21 | /// 22 | /// 重置 MessagePack 写入位置。 23 | /// 24 | void Clear(); 25 | 26 | /// 27 | /// 写入 Guid 值。 28 | /// 29 | /// Guid 30 | void WriteGuid(Guid value); 31 | 32 | /// 33 | /// 写入 DateTimeOffset 值。 34 | /// 35 | /// DateTimeOffset 36 | void WriteDateTimeOffset(DateTimeOffset value); 37 | 38 | /// 39 | /// 写入 MessagePack 对象开始标识符。 40 | /// 41 | void WriteMapHead(int size); 42 | 43 | /// 44 | /// 写入 MessagePack 数组开始标识符。 45 | /// 46 | void WriteArrayHead(int size); 47 | 48 | /// 49 | /// 将当前内容转换为字节数组。 50 | /// 51 | /// 返回一个字节数组 52 | byte[] ToBytes(); 53 | } 54 | } -------------------------------------------------------------------------------- /Swifter.Core/RW/FastObjectRW/NonPublicFastObjectCreater.cs: -------------------------------------------------------------------------------- 1 | using Swifter.Tools; 2 | using System; 3 | 4 | namespace Swifter.RW 5 | { 6 | sealed class NonPublicFastObjectCreater : IFastObjectRWCreater, IValueInterface 7 | { 8 | static readonly bool CheckDerivedInstance = !(typeof(T).IsSealed || typeof(T).IsValueType); 9 | static readonly IntPtr TypeHandle = TypeHelper.GetTypeHandle(typeof(T)); 10 | 11 | public FastObjectRW Create() 12 | { 13 | return new NonPublicFastObjectRW(); 14 | } 15 | 16 | public T ReadValue(IValueReader valueReader) 17 | { 18 | var writer = new NonPublicFastObjectRW(); 19 | 20 | valueReader.ReadObject(writer); 21 | 22 | return writer.content; 23 | } 24 | 25 | public void WriteValue(IValueWriter valueWriter, T value) 26 | { 27 | if (value is null) 28 | { 29 | valueWriter.DirectWrite(null); 30 | 31 | return; 32 | } 33 | 34 | /* 父类引用,子类实例时使用 Type 获取写入器。 */ 35 | if (CheckDerivedInstance && TypeHandle != TypeHelper.GetTypeHandle(value)) 36 | { 37 | ValueInterface.GetInterface(value).Write(valueWriter, value); 38 | 39 | return; 40 | } 41 | 42 | valueWriter.WriteObject(new NonPublicFastObjectRW 43 | { 44 | content = value 45 | }); 46 | } 47 | } 48 | } -------------------------------------------------------------------------------- /Swifter.Core/Tools/Convert/ConvertMethodComparer.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Reflection; 4 | using System.Text; 5 | 6 | namespace Swifter.Tools 7 | { 8 | sealed class ConvertMethodComparer : IEqualityComparer 9 | { 10 | public static readonly ConvertMethodComparer Instance = new ConvertMethodComparer(); 11 | 12 | private ConvertMethodComparer() 13 | { 14 | 15 | } 16 | 17 | public bool Equals(MethodInfo x, MethodInfo y) 18 | { 19 | if (x.ReturnType != y.ReturnType) 20 | { 21 | return false; 22 | } 23 | 24 | var xp = x.GetParameters(); 25 | var yp = y.GetParameters(); 26 | 27 | if (xp.Length != yp.Length) 28 | { 29 | return false; 30 | } 31 | 32 | for (int i = 0; i < xp.Length; i++) 33 | { 34 | if (xp[i].ParameterType != yp[i].ParameterType) 35 | { 36 | return false; 37 | } 38 | } 39 | 40 | return true; 41 | } 42 | 43 | public int GetHashCode(MethodInfo obj) 44 | { 45 | var hash = obj.ReturnType.GetHashCode(); 46 | 47 | foreach (var item in obj.GetParameters()) 48 | { 49 | hash ^= item.ParameterType.GetHashCode(); 50 | } 51 | 52 | return hash; 53 | } 54 | } 55 | } 56 | -------------------------------------------------------------------------------- /Swifter.Core/Tools/Emit/CaseInfo.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Reflection.Emit; 3 | 4 | namespace Swifter.Tools 5 | { 6 | /// 7 | /// 表示 Switch 的 Case 块 8 | /// 9 | /// 10 | public sealed class CaseInfo : IComparable> 11 | { 12 | /// 13 | /// 获取 Case 块的值。 14 | /// 15 | public readonly T Value; 16 | 17 | /// 18 | /// 获取 Case 块的指令标签。 19 | /// 20 | public readonly Label Label; 21 | 22 | /// 23 | /// 获取或设置值的 HashCode 值。 24 | /// 25 | internal int HashCode; 26 | 27 | /// 28 | /// 辅助变量。 29 | /// 30 | internal object Tag; 31 | 32 | /// 33 | /// 实例化 Case 块。 34 | /// 35 | /// Case 块的值 36 | /// ase 块的指令标签 37 | public CaseInfo(T value, Label label) 38 | { 39 | Value = value; 40 | Label = label; 41 | } 42 | 43 | /// 44 | /// 与另一个 Case 块信息比较 HashCode 的大小。 45 | /// 46 | /// Case 块信息 47 | /// 返回大于 0 则比它大,小于 0 则比它小,否则一样大 48 | public int CompareTo(CaseInfo other) 49 | { 50 | return HashCode.CompareTo(other.HashCode); 51 | } 52 | } 53 | } -------------------------------------------------------------------------------- /Swifter.Extensions.AspNetCore/SwifterJsonResult.cs: -------------------------------------------------------------------------------- 1 | 2 | #if NETFRAMEWORK 3 | 4 | using Swifter.Json; 5 | using System; 6 | using System.Text; 7 | using System.Web.Mvc; 8 | 9 | using static SwifterExtensions; 10 | /// 11 | /// Swifter.Json 提供的快速 Json 返回值。 12 | /// 13 | public class SwifterJsonResult : JsonResult 14 | { 15 | /// 16 | /// JsonFormatter 配置项。 17 | /// 18 | public JsonFormatterOptions Options { get; set; } = JsonFormatterOptions.Default; 19 | 20 | /// 21 | /// 调用 Swifter.Json 快速序列化程序。 22 | /// 23 | /// 控制器上下文 24 | public override void ExecuteResult(ControllerContext context) 25 | { 26 | if (context == null) 27 | throw new ArgumentNullException(nameof(context)); 28 | var response = context.HttpContext.Response; 29 | 30 | var contentType = GetNonEmptyString(ContentType, response.ContentType, JSONContentType); 31 | var encoding = ContentEncoding ?? response.ContentEncoding ?? Encoding.UTF8; 32 | 33 | if (JSONContentType.Equals(contentType, StringComparison.InvariantCultureIgnoreCase)) 34 | { 35 | contentType = $"{JSONContentType};charset={encoding.HeaderName}"; 36 | } 37 | 38 | response.ContentType = contentType; 39 | 40 | if (Data == null) 41 | { 42 | return; 43 | } 44 | 45 | JsonFormatter.SerializeObject(Data, response.OutputStream, encoding, Options); 46 | } 47 | } 48 | 49 | #endif -------------------------------------------------------------------------------- /Swifter.Core/RW/Basic/AssemblyInterface.cs: -------------------------------------------------------------------------------- 1 | using Swifter.Tools; 2 | using System.Reflection; 3 | 4 | namespace Swifter.RW 5 | { 6 | internal sealed class AssemblyInterface : IValueInterface where T : Assembly 7 | { 8 | public T ReadValue(IValueReader valueReader) 9 | { 10 | if (valueReader is IValueReader tReader) 11 | { 12 | return tReader.ReadValue(); 13 | } 14 | 15 | if (valueReader is IValueReader assemblyReader) 16 | { 17 | return (T)assemblyReader.ReadValue(); 18 | } 19 | 20 | var value = valueReader.DirectRead(); 21 | 22 | if (value is string sssemblyString && Assembly.Load(sssemblyString) is T result) 23 | { 24 | return result; 25 | } 26 | 27 | return XConvert.FromObject(value); 28 | } 29 | 30 | public void WriteValue(IValueWriter valueWriter, T value) 31 | { 32 | if (value is null) 33 | { 34 | valueWriter.DirectWrite(null); 35 | } 36 | else if (valueWriter is IValueWriter tWriter) 37 | { 38 | tWriter.WriteValue(value); 39 | } 40 | else if (valueWriter is IValueWriter assemblyWriter) 41 | { 42 | assemblyWriter.WriteValue(value); 43 | } 44 | else 45 | { 46 | valueWriter.WriteString(value.FullName); 47 | } 48 | } 49 | } 50 | } -------------------------------------------------------------------------------- /Swifter.Debug/Reflection.cs: -------------------------------------------------------------------------------- 1 | #if BenchmarkDotNet 2 | 3 | using System; 4 | using System.Reflection; 5 | using Swifter.Tools; 6 | using Swifter.Reflection; 7 | using BenchmarkDotNet.Attributes; 8 | 9 | namespace Swifter.Debug 10 | { 11 | [Config(typeof(MyConfig))] 12 | public class Reflection 13 | { 14 | public const BindingFlags bindingFlags = BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.Static | BindingFlags.DeclaredOnly; 15 | public const XBindingFlags xBindingFlags = XBindingFlags.Public | XBindingFlags.NonPublic | XBindingFlags.Instance | XBindingFlags.Static; 16 | 17 | public static readonly object obj_TestClass = new TestClass(); 18 | public static readonly object obj_TestStruct = new TestStruct(); 19 | 20 | public static readonly EventHandler test_event_handler = new EventHandler((sender, args) => { }); 21 | 22 | public static readonly MethodInfo system_public_static_action = typeof(TestClass).GetMethod("public_static_action", bindingFlags); 23 | public static readonly XMethodInfo swifter_public_static_action = XMethodInfo.Create(system_public_static_action, xBindingFlags); 24 | public static readonly object[] public_static_action_args = new object[] { }; 25 | 26 | public static readonly PropertyInfo system_public_class_property_int = typeof(TestClass).GetProperty("public_class_property_int", bindingFlags); 27 | public static readonly XPropertyInfo swifter_public_class_property_int = XPropertyInfo.Create(system_public_class_property_int, xBindingFlags); 28 | 29 | } 30 | } 31 | 32 | #endif -------------------------------------------------------------------------------- /Swifter.Core/Reflection/SerializationBox.T.cs: -------------------------------------------------------------------------------- 1 | using Swifter.RW; 2 | using System.Runtime.InteropServices; 3 | 4 | using static Swifter.Reflection.SerializationBox; 5 | 6 | namespace Swifter.Reflection 7 | { 8 | /// 9 | /// 对象序列化盒子。 10 | /// 11 | /// 序列化的声明类型 12 | [StructLayout(LayoutKind.Sequential, Pack = 1)] 13 | public readonly struct SerializationBox 14 | { 15 | /// 16 | /// 需要序列化的对象。 17 | /// 18 | public readonly T Value; 19 | 20 | sealed class ValueInterface : IValueInterface> 21 | { 22 | public SerializationBox ReadValue(IValueReader valueReader) 23 | { 24 | return (T)Read(valueReader, typeof(T)); 25 | } 26 | 27 | public void WriteValue(IValueWriter valueWriter, SerializationBox value) 28 | { 29 | Write(valueWriter, value.Value, typeof(T)); 30 | } 31 | } 32 | 33 | /// 34 | /// 将对象隐式转换为对象序列化盒子。 35 | /// 36 | /// 对象 37 | public static implicit operator SerializationBox(T value) 38 | { 39 | return Underlying.As>(ref value); 40 | } 41 | 42 | /// 43 | /// 将对象序列化盒子隐式转换为对象。 44 | /// 45 | /// 对象序列化盒子 46 | public static implicit operator T(SerializationBox value) 47 | { 48 | return value.Value; 49 | } 50 | } 51 | } 52 | -------------------------------------------------------------------------------- /Swifter.Core/RW/Helper/DefaultValueReader.cs: -------------------------------------------------------------------------------- 1 | 2 | 3 | using System; 4 | 5 | namespace Swifter.RW 6 | { 7 | sealed class DefaultValueReader : IValueReader, IValueReader, IValueReader, IValueReader 8 | { 9 | public object DirectRead() => default; 10 | 11 | public void ReadArray(IDataWriter valueWriter) { } 12 | 13 | public bool ReadBoolean() => default; 14 | 15 | public byte ReadByte() => default; 16 | 17 | public char ReadChar() => default; 18 | 19 | public DateTime ReadDateTime() => default; 20 | 21 | public decimal ReadDecimal() => default; 22 | 23 | public double ReadDouble() => default; 24 | 25 | public short ReadInt16() => default; 26 | 27 | public int ReadInt32() => default; 28 | 29 | public long ReadInt64() => default; 30 | 31 | public T? ReadNullable() where T : struct => default; 32 | 33 | public void ReadObject(IDataWriter valueWriter) { } 34 | 35 | public sbyte ReadSByte() => default; 36 | 37 | public float ReadSingle() => default; 38 | 39 | public string ReadString() => default; 40 | 41 | public ushort ReadUInt16() => default; 42 | 43 | public uint ReadUInt32() => default; 44 | 45 | public ulong ReadUInt64() => default; 46 | 47 | public T ReadEnum() where T : struct, Enum => default; 48 | 49 | Guid IValueReader.ReadValue() => default; 50 | 51 | TimeSpan IValueReader.ReadValue() => default; 52 | 53 | DateTimeOffset IValueReader.ReadValue() => default; 54 | } 55 | } 56 | -------------------------------------------------------------------------------- /Swifter.Core/RW/IDataReader.cs: -------------------------------------------------------------------------------- 1 | 2 | using System; 3 | using System.Collections.Generic; 4 | 5 | namespace Swifter.RW 6 | { 7 | /// 8 | /// 提供数据的读取方法。 9 | /// 10 | /// 键的类型 11 | public interface IDataReader : IDataReader 12 | { 13 | /// 14 | /// 获取键的集合。 15 | /// 16 | IEnumerable Keys { get; } 17 | 18 | /// 19 | /// 获取指定键的值读取器实例。 20 | /// 21 | /// 指定键 22 | /// 返回值读取器实例 23 | IValueReader this[TKey key] { get; } 24 | 25 | /// 26 | /// 将指定键对应的值写入到值写入器中。 27 | /// 28 | /// 指定键 29 | /// 值写入器 30 | void OnReadValue(TKey key, IValueWriter valueWriter); 31 | 32 | /// 33 | /// 将数据中的所有键与值写入到数据写入器中。 34 | /// 35 | /// 数据写入器 36 | void OnReadAll(IDataWriter dataWriter); 37 | } 38 | 39 | /// 40 | /// 表示一个数据读取器。 41 | /// 42 | public interface IDataReader 43 | { 44 | /// 45 | /// 获取数据源键的数量。 46 | /// -1 表示未知数量。 47 | /// 48 | int Count { get; } 49 | 50 | /// 51 | /// 获取数据源的类型。 52 | /// 53 | Type ContentType { get; } 54 | 55 | /// 56 | /// 获取或设置数据源。 57 | /// 58 | object Content { get; set; } 59 | } 60 | } -------------------------------------------------------------------------------- /Swifter.Core/Formatters/FormatterHelper.Async.cs: -------------------------------------------------------------------------------- 1 | #if Async 2 | 3 | using Swifter.RW; 4 | using Swifter.Tools; 5 | using System.IO; 6 | using System.Runtime.CompilerServices; 7 | using System.Text; 8 | using System.Threading.Tasks; 9 | 10 | #if ValueTask 11 | 12 | using Task = System.Threading.Tasks.ValueTask; 13 | 14 | #endif 15 | 16 | namespace Swifter.Formatters 17 | { 18 | partial class FormatterHelper 19 | { 20 | 21 | /// 22 | /// 异步将文档字符串反序列化到指定的对象中。 23 | /// 24 | /// 对象类型 25 | /// 文档反序列化器 26 | /// 文档字符串读取器 27 | /// 对象 28 | [MethodImpl(VersionDifferences.AggressiveInlining)] 29 | public static async Task DeserializeToAsync(this ITextFormatter textFormatter, TextReader textReader, T obj) 30 | { 31 | await textFormatter.DeserializeToAsync(textReader, RWHelper.CreateWriter(obj)); 32 | } 33 | 34 | /// 35 | /// 异步将字节码内容反序列化到指定的对象中。 36 | /// 37 | /// 对象类型 38 | /// 字节码反序列化器 39 | /// 字节码内容读取器 40 | /// 对象 41 | [MethodImpl(VersionDifferences.AggressiveInlining)] 42 | public static async Task DeserializeToAsync(this ITextFormatter textFormatter, Stream stream, T obj) 43 | { 44 | await textFormatter.DeserializeToAsync(stream, RWHelper.CreateWriter(obj)); 45 | } 46 | } 47 | } 48 | 49 | #endif --------------------------------------------------------------------------------