├── .editorconfig
├── .github
└── workflows
│ ├── build-debug.yml
│ ├── build-release.yml
│ ├── stale.yml
│ └── toc.yml
├── .gitignore
├── DataTables.sln
├── Directory.Build.props
├── Icon.png
├── LICENSE
├── README.md
├── opensource.snk
├── sandbox
├── Benchmark
│ ├── Benchmark.csproj
│ ├── DataMatrixBase1.cs
│ ├── DataMatrixs.cs
│ ├── Program.cs
│ └── Utils
│ │ └── Helper.cs
└── ConsoleApp
│ ├── ConsoleApp.csproj
│ ├── CustomSample.cs
│ ├── DataTables
│ ├── ConsoleApp.DTDataTableSample.bytes
│ ├── ConsoleApp.DTDataTableSplitSample.x001.bytes
│ ├── ConsoleApp.DTDataTableSplitSample.x002.bytes
│ └── ConsoleApp.DTMatrixSample.bytes
│ ├── Generated
│ ├── DRDataTableSample.cs
│ ├── DRDataTableSplitSample.cs
│ ├── DRMatrixSample.cs
│ └── DataTableManagerExtension.cs
│ ├── JSONSamle.cs
│ ├── Program.cs
│ └── 示例表.xlsx
├── src
├── DataTables.Generator
│ ├── DataTables.Generator.csproj
│ ├── Program.cs
│ ├── Properties
│ │ └── launchSettings.json
│ └── README.md
├── DataTables.GeneratorCore
│ ├── BinaryExtension.cs
│ ├── DataMatrixTemplate.cs
│ ├── DataMatrixTemplate.tt
│ ├── DataTableGenerator.cs
│ ├── DataTableManagerExtensionTemplate.cs
│ ├── DataTableManagerExtensionTemplate.tt
│ ├── DataTableProcessor.ArrayDataProcessor.cs
│ ├── DataTableProcessor.BooleanProcessor.cs
│ ├── DataTableProcessor.ByteProcessor.cs
│ ├── DataTableProcessor.CharProcessor.cs
│ ├── DataTableProcessor.CustomProcessor.cs
│ ├── DataTableProcessor.DataProcessor.cs
│ ├── DataTableProcessor.DataProcessorUtility.cs
│ ├── DataTableProcessor.DateTimeProcessor.cs
│ ├── DataTableProcessor.DecimalProcessor.cs
│ ├── DataTableProcessor.DoubleProcessor.cs
│ ├── DataTableProcessor.EnumProcessor.cs
│ ├── DataTableProcessor.GenericDataProcessor.cs
│ ├── DataTableProcessor.Int16Processor.cs
│ ├── DataTableProcessor.Int32Processor.cs
│ ├── DataTableProcessor.Int64Processor.cs
│ ├── DataTableProcessor.JSONProcessor.cs
│ ├── DataTableProcessor.MapDataProcessor.cs
│ ├── DataTableProcessor.SByteProcessor.cs
│ ├── DataTableProcessor.SingleProcessor.cs
│ ├── DataTableProcessor.StringProcessor.cs
│ ├── DataTableProcessor.UInt16Processor.cs
│ ├── DataTableProcessor.UInt32Processor.cs
│ ├── DataTableProcessor.UInt64Processor.cs
│ ├── DataTableProcessor.cs
│ ├── DataTableTemplate.cs
│ ├── DataTableTemplate.tt
│ ├── DataTables.GeneratorCore.csproj
│ ├── GenerationContext.cs
│ ├── ILogger.cs
│ ├── JsonUtility.cs
│ └── Template.cs
├── DataTables.MSBuild.Tasks
│ ├── DataTables.MSBuild.Tasks.csproj
│ ├── DataTablesGenerator.cs
│ └── build
│ │ └── DataTables.MSBuild.Tasks.props
├── DataTables.Unity
│ ├── Assets
│ │ ├── Plugins.meta
│ │ ├── Plugins
│ │ │ ├── System.Buffers.dll
│ │ │ ├── System.Buffers.dll.meta
│ │ │ ├── System.Memory.dll
│ │ │ ├── System.Memory.dll.meta
│ │ │ ├── System.Runtime.CompilerServices.Unsafe.dll
│ │ │ ├── System.Runtime.CompilerServices.Unsafe.dll.meta
│ │ │ ├── System.Threading.Tasks.Extensions.dll
│ │ │ └── System.Threading.Tasks.Extensions.dll.meta
│ │ ├── Scenes.meta
│ │ ├── Scenes
│ │ │ ├── SampleScene.unity
│ │ │ └── SampleScene.unity.meta
│ │ ├── Scripts.meta
│ │ ├── Scripts
│ │ │ ├── DataTables.meta
│ │ │ ├── DataTables
│ │ │ │ ├── BinaryExtension.cs
│ │ │ │ ├── BinaryExtension.cs.meta
│ │ │ │ ├── DataMatrixBase.cs
│ │ │ │ ├── DataMatrixBase.cs.meta
│ │ │ │ ├── DataRowBase.cs
│ │ │ │ ├── DataRowBase.cs.meta
│ │ │ │ ├── DataTable.cs
│ │ │ │ ├── DataTable.cs.meta
│ │ │ │ ├── DataTableBase.cs
│ │ │ │ ├── DataTableBase.cs.meta
│ │ │ │ ├── DataTableManager.cs
│ │ │ │ ├── DataTableManager.cs.meta
│ │ │ │ ├── DataTables.asmdef
│ │ │ │ ├── DataTables.asmdef.meta
│ │ │ │ ├── DefaultDataTableHelper.cs
│ │ │ │ ├── DefaultDataTableHelper.cs.meta
│ │ │ │ ├── IDataRow.cs
│ │ │ │ ├── IDataRow.cs.meta
│ │ │ │ ├── IDataTable.cs
│ │ │ │ ├── IDataTable.cs.meta
│ │ │ │ ├── IDataTableHelper.cs
│ │ │ │ ├── IDataTableHelper.cs.meta
│ │ │ │ ├── IDataTableManager.cs
│ │ │ │ ├── IDataTableManager.cs.meta
│ │ │ │ ├── TypeNamePair.cs
│ │ │ │ ├── TypeNamePair.cs.meta
│ │ │ │ ├── package.json
│ │ │ │ └── package.json.meta
│ │ │ ├── Editor.meta
│ │ │ └── Editor
│ │ │ │ ├── PackageExporter.cs
│ │ │ │ └── PackageExporter.cs.meta
│ │ ├── Tests.meta
│ │ └── Tests
│ │ │ ├── DataTables.Tests.asmdef
│ │ │ ├── DataTables.Tests.asmdef.meta
│ │ │ ├── IssueTest.cs
│ │ │ └── IssueTest.cs.meta
│ ├── Packages
│ │ ├── manifest.json
│ │ └── packages-lock.json
│ └── ProjectSettings
│ │ ├── AudioManager.asset
│ │ ├── ClusterInputManager.asset
│ │ ├── DynamicsManager.asset
│ │ ├── EditorBuildSettings.asset
│ │ ├── EditorSettings.asset
│ │ ├── GraphicsSettings.asset
│ │ ├── InputManager.asset
│ │ ├── MemorySettings.asset
│ │ ├── NavMeshAreas.asset
│ │ ├── NetworkManager.asset
│ │ ├── PackageManagerSettings.asset
│ │ ├── Physics2DSettings.asset
│ │ ├── PresetManager.asset
│ │ ├── ProjectSettings.asset
│ │ ├── ProjectVersion.txt
│ │ ├── QualitySettings.asset
│ │ ├── TagManager.asset
│ │ ├── TimeManager.asset
│ │ ├── UnityConnectSettings.asset
│ │ ├── VFXManager.asset
│ │ ├── VersionControlSettings.asset
│ │ └── XRSettings.asset
└── DataTables
│ ├── BinaryExtension.cs
│ ├── DataMatrixBase.cs
│ ├── DataRowBase.cs
│ ├── DataTable.cs
│ ├── DataTableBase.cs
│ ├── DataTableManager.cs
│ ├── DataTables.csproj
│ ├── DefaultDataTableHelper.cs
│ ├── IDataRow.cs
│ ├── IDataTable.cs
│ ├── IDataTableHelper.cs
│ ├── IDataTableManager.cs
│ └── TypeNamePair.cs
├── tests
└── DataTables.Tests
│ ├── BinaryExtensionTest.cs
│ ├── BinarySearchTest.cs
│ ├── DataTableProcessTest.cs
│ ├── DataTables.Tests.csproj
│ ├── IssueTest.cs
│ ├── MemoryKeyTest.cs
│ ├── MessagePackResolver.cs
│ ├── MetaTest.cs
│ ├── RangeViewTest.cs
│ └── ValidatorTest.cs
└── tools
└── PostBuildUtility
├── PostBuildUtility.csproj
└── Program.cs
/.github/workflows/build-debug.yml:
--------------------------------------------------------------------------------
1 | name: Build-Debug
2 |
3 | on:
4 | workflow_dispatch:
5 | push:
6 | branches:
7 | - "master"
8 | pull_request:
9 | branches:
10 | - "master"
11 |
12 | jobs:
13 | build-dotnet:
14 | runs-on: ubuntu-latest
15 | timeout-minutes: 10
16 | steps:
17 | - uses: actions/checkout@v4
18 | - uses: ChronosGames/Actions/.github/actions/setup-dotnet@main
19 | - run: dotnet build -c Debug
20 | - run: dotnet test -c Debug --no-build
21 |
22 | build-unity:
23 | if: ${{ ((github.event_name == 'push' && github.repository_owner == 'ChronosGames') || startsWith(github.event.pull_request.head.label, 'ChronosGames:')) && github.triggering_actor != 'dependabot[bot]' }}
24 | strategy:
25 | fail-fast: false
26 | matrix:
27 | unity: ["2022.3.39f1", "6000.0.12f1"] # Test with LTS
28 | runs-on: ubuntu-latest
29 | timeout-minutes: 15
30 | steps:
31 | - uses: actions/checkout@v4
32 |
33 | # Execute Unittest
34 | # /opt/Unity/Editor/Unity -quit -batchmode -nographics -silent-crashes -logFile -projectPath . -executeMethod UnitTestBuilder.BuildUnitTest /headless /ScriptBackend IL2CPP /BuildTarget StandaloneLinux64
35 | - name: Build UnitTest
36 | uses: ChronosGames/Actions/.github/actions/unity-builder@main
37 | env:
38 | UNITY_EMAIL: ${{ secrets.UNITY_EMAIL }}
39 | UNITY_PASSWORD: ${{ secrets.UNITY_PASSWORD }}
40 | UNITY_SERIAL: ${{ secrets.UNITY_SERIAL }}
41 | with:
42 | projectPath: src/DataTables.Unity
43 | unityVersion: ${{ matrix.unity }}
44 | targetPlatform: StandaloneLinux64
45 | buildMethod: UnitTestBuilder.BuildUnitTest
46 | customParameters: "/headless /ScriptBackend IL2CPP"
47 | - name: Check UnitTest file is generated
48 | run: ls -lR ./src/DataTables.Unity/bin/UnitTest
49 | - name: Execute UnitTest
50 | run: ./src/DataTables.Unity/bin/UnitTest/StandaloneLinux64_IL2CPP/test
51 |
52 | - uses: ChronosGames/Actions/.github/actions/check-metas@main # check meta files
53 | with:
54 | directory: src/DataTables.Unity
55 |
--------------------------------------------------------------------------------
/.github/workflows/build-release.yml:
--------------------------------------------------------------------------------
1 | name: Build-Release
2 |
3 | on:
4 | workflow_dispatch:
5 | inputs:
6 | tag:
7 | description: "tag: git tag you want create. (sample 1.0.0)"
8 | required: true
9 | dry-run:
10 | description: "dry-run: false = create release/nuget. true = never create release/nuget."
11 | required: true
12 | default: false
13 | type: boolean
14 |
15 | jobs:
16 | update-packagejson:
17 | uses: ChronosGames/Actions/.github/workflows/update-packagejson.yaml@main
18 | with:
19 | file-path: |
20 | ./src/DataTables.Unity/Assets/Scripts/DataTables/package.json
21 | tag: ${{ inputs.tag }}
22 | dry-run: ${{ inputs.dry-run }}
23 | push-tag: false
24 |
25 | build-dotnet:
26 | needs: [update-packagejson]
27 | runs-on: ubuntu-latest
28 | timeout-minutes: 10
29 | steps:
30 | - run: echo ${{ needs.update-packagejson.outputs.sha }}
31 | - uses: actions/checkout@v4
32 | with:
33 | ref: ${{ needs.update-packagejson.outputs.sha }}
34 | - uses: ChronosGames/Actions/.github/actions/setup-dotnet@main
35 | # pack nuget
36 | - run: dotnet build -c Release -p:Version=${{ inputs.tag }}
37 | - run: dotnet test -c Release --no-build
38 | - run: dotnet pack -c Release --no-build -p:Version=${{ inputs.tag }} -o ./publish
39 | - uses: ChronosGames/Actions/.github/actions/upload-artifact@main
40 | with:
41 | name: nuget
42 | path: ./publish
43 | retention-days: 1
44 |
45 | build-unity:
46 | needs: [update-packagejson]
47 | strategy:
48 | matrix:
49 | unity: ["2022.3.39f1"]
50 | runs-on: ubuntu-latest
51 | timeout-minutes: 15
52 | steps:
53 | - run: echo ${{ needs.update-packagejson.outputs.sha }}
54 | - uses: actions/checkout@v4
55 | with:
56 | ref: ${{ needs.update-packagejson.outputs.sha }}
57 |
58 | # Execute scripts: Export Package
59 | # /opt/Unity/Editor/Unity -quit -batchmode -nographics -silent-crashes -logFile -projectPath . -executeMethod PackageExporter.Export
60 | - name: Build Unity (.unitypacakge)
61 | uses: ChronosGames/Actions/.github/actions/unity-builder@main
62 | env:
63 | UNITY_EMAIL: ${{ secrets.UNITY_EMAIL }}
64 | UNITY_PASSWORD: ${{ secrets.UNITY_PASSWORD }}
65 | UNITY_SERIAL: ${{ secrets.UNITY_SERIAL }}
66 | UNITY_PACKAGE_VERSION: ${{ inputs.tag }}
67 | with:
68 | projectPath: src/DataTables.Unity
69 | unityVersion: ${{ matrix.unity }}
70 | targetPlatform: StandaloneLinux64
71 | buildMethod: PackageExporter.Export
72 |
73 | # check meta files
74 | - uses: ChronosGames/Actions/.github/actions/check-metas@main
75 | with:
76 | directory: src/DataTables.Unity
77 |
78 | # Store artifacts.
79 | - uses: ChronosGames/Actions/.github/actions/upload-artifact@main
80 | with:
81 | name: DataTables.Unity.${{ inputs.tag }}.unitypackage
82 | path: ./src/DataTables.Unity/DataTables.Unity.${{ inputs.tag }}.unitypackage
83 | retention-days: 1
84 |
85 | # release
86 | create-release:
87 | needs: [update-packagejson, build-dotnet, build-unity]
88 | uses: ChronosGames/Actions/.github/workflows/create-release.yaml@main
89 | with:
90 | dry-run: ${{ inputs.dry-run }}
91 | commit-id: ${{ needs.update-packagejson.outputs.sha }}
92 | tag: ${{ inputs.tag }}
93 | nuget-push: true
94 | release-upload: true
95 | release-asset-path: ./DataTables.Unity.${{ inputs.tag }}.unitypackage/DataTables.Unity.${{ inputs.tag }}.unitypackage
96 | secrets: inherit
97 |
98 | cleanup:
99 | if: ${{ needs.update-packagejson.outputs.is-branch-created == 'true' }}
100 | needs: [update-packagejson, create-release]
101 | uses: ChronosGames/Actions/.github/workflows/clean-packagejson-branch.yaml@main
102 | with:
103 | branch: ${{ needs.update-packagejson.outputs.branch-name }}
104 |
--------------------------------------------------------------------------------
/.github/workflows/stale.yml:
--------------------------------------------------------------------------------
1 | name: "Close stale issues"
2 |
3 | on:
4 | workflow_dispatch:
5 | schedule:
6 | - cron: "0 0 * * *"
7 |
8 | jobs:
9 | stale:
10 | uses: ChronosGames/Actions/.github/workflows/stale-issue.yaml@main
11 |
--------------------------------------------------------------------------------
/.github/workflows/toc.yml:
--------------------------------------------------------------------------------
1 | name: TOC Generator
2 |
3 | on:
4 | push:
5 | paths:
6 | - 'README.md'
7 |
8 | jobs:
9 | generateTOC:
10 | name: TOC Generator
11 | runs-on: ubuntu-latest
12 | steps:
13 | - uses: technote-space/toc-generator@v4
14 | with:
15 | TOC_TITLE: "## Table of Contents"
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | # Build Folders (you can keep bin if you'd like, to store dlls and pdbs)
2 | [Bb]in/
3 | [Oo]bj/
4 |
5 | # mstest test results
6 | TestResults
7 |
8 | ## Ignore Visual Studio temporary files, build results, and
9 | ## files generated by popular Visual Studio add-ons.
10 |
11 | # User-specific files
12 | *.suo
13 | *.user
14 | *.sln.docstates
15 |
16 | # Build results
17 | [Dd]ebug/
18 | [Rr]elease/
19 | x64/
20 | *_i.c
21 | *_p.c
22 | *.ilk
23 | *.obj
24 | *.pch
25 | *.pdb
26 | *.pgc
27 | *.pgd
28 | *.rsp
29 | *.sbr
30 | *.tlb
31 | *.tli
32 | *.tlh
33 | *.tmp
34 | *.log
35 | *.vspscc
36 | *.vssscc
37 | .builds
38 |
39 | # Visual C++ cache files
40 | ipch/
41 | *.aps
42 | *.ncb
43 | *.opensdf
44 | *.sdf
45 |
46 | # Visual Studio profiler
47 | *.psess
48 | *.vsp
49 | *.vspx
50 |
51 | # Guidance Automation Toolkit
52 | *.gpState
53 |
54 | # ReSharper is a .NET coding add-in
55 | _ReSharper*
56 |
57 | # NCrunch
58 | *.ncrunch*
59 | .*crunch*.local.xml
60 |
61 | # Installshield output folder
62 | [Ee]xpress
63 |
64 | # DocProject is a documentation generator add-in
65 | DocProject/buildhelp/
66 | DocProject/Help/*.HxT
67 | DocProject/Help/*.HxC
68 | DocProject/Help/*.hhc
69 | DocProject/Help/*.hhk
70 | DocProject/Help/*.hhp
71 | DocProject/Help/Html2
72 | DocProject/Help/html
73 |
74 | # Click-Once directory
75 | publish
76 |
77 | # Publish Web Output
78 | *.Publish.xml
79 |
80 | # NuGet Packages Directory
81 | packages
82 |
83 | # Windows Azure Build Output
84 | csx
85 | *.build.csdef
86 |
87 | # Windows Store app package directory
88 | AppPackages/
89 |
90 | # Others
91 | [Bb]in
92 | [Oo]bj
93 | sql
94 | TestResults
95 | [Tt]est[Rr]esult*
96 | *.Cache
97 | ClientBin
98 | [Ss]tyle[Cc]op.*
99 | ~$*
100 | *.dbmdl
101 | Generated_Code #added for RIA/Silverlight projects
102 |
103 | # Backup & report files from converting an old project file to a newer
104 | # Visual Studio version. Backup files are not needed, because we have git ;-)
105 | _UpgradeReport_Files/
106 | Backup*/
107 | UpgradeLog*.XML
108 | .vs/config/applicationhost.config
109 | .vs/restore.dg
110 |
111 | # Unity
112 | src/MasterMemory.UnityClient/bin/*
113 | src/MasterMemory.UnityClient/Library/*
114 | src/MasterMemory.UnityClient/obj/*
115 | src/MasterMemory.UnityClient/Temp/*
116 |
117 | # OTHER
118 | nuget/tools/*
119 | *.nupkg
120 |
121 | .vs
122 |
123 | # Unity
124 | Library/
125 | Temp/
126 | src/MasterMemory.Unity/Assembly-CSharp-Editor.csproj
127 |
128 | src/MasterMemory.Unity/MasterMemory.csproj
129 |
130 | src/MasterMemory.Unity/MasterMemory.Tests.csproj
131 |
132 | src/MasterMemory.Unity/MasterMemory.Unity.sln
133 |
134 | src/MasterMemory.Unity/MessagePack.Annotations.csproj
135 |
136 | src/MasterMemory.Unity/MessagePack.csproj
137 |
--------------------------------------------------------------------------------
/DataTables.sln:
--------------------------------------------------------------------------------
1 |
2 | Microsoft Visual Studio Solution File, Format Version 12.00
3 | # Visual Studio Version 17
4 | VisualStudioVersion = 17.5.33502.453
5 | MinimumVisualStudioVersion = 10.0.40219.1
6 | Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "src", "src", "{60662102-4523-441E-8D6C-D87A3246C648}"
7 | EndProject
8 | Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "tests", "tests", "{BDAFF1CB-8E53-412B-B389-42A15343C7A3}"
9 | EndProject
10 | Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "sandbox", "sandbox", "{FFAA235C-D30F-4958-BC4E-60CD08979464}"
11 | EndProject
12 | Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "DataTables", "src\DataTables\DataTables.csproj", "{D2720BBB-C233-4A1E-9768-1F00C9602180}"
13 | EndProject
14 | Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "DataTables.Tests", "tests\DataTables.Tests\DataTables.Tests.csproj", "{8C5EBACA-C6C7-463B-B85C-C6A05E5DEB9F}"
15 | EndProject
16 | Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "DataTables.GeneratorCore", "src\DataTables.GeneratorCore\DataTables.GeneratorCore.csproj", "{DAC2FED6-E960-4E57-949F-6B9185924E60}"
17 | EndProject
18 | Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "DataTables.Generator", "src\DataTables.Generator\DataTables.Generator.csproj", "{625ECD09-F1E4-4979-B7A6-F94F23F7BBB0}"
19 | EndProject
20 | Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Benchmark", "sandbox\Benchmark\Benchmark.csproj", "{205509EA-78C8-4ED0-B2B5-8030DDFB0BF0}"
21 | EndProject
22 | Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "ConsoleApp", "sandbox\ConsoleApp\ConsoleApp.csproj", "{2657C9C5-0BEA-4616-BE41-A19E8298C591}"
23 | EndProject
24 | Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "PostBuildUtility", "tools\PostBuildUtility\PostBuildUtility.csproj", "{7080BE3D-4103-489A-9F7E-ED3D54CEC784}"
25 | EndProject
26 | Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "tools", "tools", "{289E4C98-1DBA-4E34-A6CC-F9CF5E212790}"
27 | EndProject
28 | Global
29 | GlobalSection(SolutionConfigurationPlatforms) = preSolution
30 | Debug|Any CPU = Debug|Any CPU
31 | Release|Any CPU = Release|Any CPU
32 | EndGlobalSection
33 | GlobalSection(ProjectConfigurationPlatforms) = postSolution
34 | {D2720BBB-C233-4A1E-9768-1F00C9602180}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
35 | {D2720BBB-C233-4A1E-9768-1F00C9602180}.Debug|Any CPU.Build.0 = Debug|Any CPU
36 | {D2720BBB-C233-4A1E-9768-1F00C9602180}.Release|Any CPU.ActiveCfg = Release|Any CPU
37 | {D2720BBB-C233-4A1E-9768-1F00C9602180}.Release|Any CPU.Build.0 = Release|Any CPU
38 | {8C5EBACA-C6C7-463B-B85C-C6A05E5DEB9F}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
39 | {8C5EBACA-C6C7-463B-B85C-C6A05E5DEB9F}.Debug|Any CPU.Build.0 = Debug|Any CPU
40 | {8C5EBACA-C6C7-463B-B85C-C6A05E5DEB9F}.Release|Any CPU.ActiveCfg = Release|Any CPU
41 | {8C5EBACA-C6C7-463B-B85C-C6A05E5DEB9F}.Release|Any CPU.Build.0 = Release|Any CPU
42 | {DAC2FED6-E960-4E57-949F-6B9185924E60}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
43 | {DAC2FED6-E960-4E57-949F-6B9185924E60}.Debug|Any CPU.Build.0 = Debug|Any CPU
44 | {DAC2FED6-E960-4E57-949F-6B9185924E60}.Release|Any CPU.ActiveCfg = Release|Any CPU
45 | {DAC2FED6-E960-4E57-949F-6B9185924E60}.Release|Any CPU.Build.0 = Release|Any CPU
46 | {625ECD09-F1E4-4979-B7A6-F94F23F7BBB0}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
47 | {625ECD09-F1E4-4979-B7A6-F94F23F7BBB0}.Debug|Any CPU.Build.0 = Debug|Any CPU
48 | {625ECD09-F1E4-4979-B7A6-F94F23F7BBB0}.Release|Any CPU.ActiveCfg = Release|Any CPU
49 | {625ECD09-F1E4-4979-B7A6-F94F23F7BBB0}.Release|Any CPU.Build.0 = Release|Any CPU
50 | {205509EA-78C8-4ED0-B2B5-8030DDFB0BF0}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
51 | {205509EA-78C8-4ED0-B2B5-8030DDFB0BF0}.Debug|Any CPU.Build.0 = Debug|Any CPU
52 | {205509EA-78C8-4ED0-B2B5-8030DDFB0BF0}.Release|Any CPU.ActiveCfg = Release|Any CPU
53 | {205509EA-78C8-4ED0-B2B5-8030DDFB0BF0}.Release|Any CPU.Build.0 = Release|Any CPU
54 | {2657C9C5-0BEA-4616-BE41-A19E8298C591}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
55 | {2657C9C5-0BEA-4616-BE41-A19E8298C591}.Debug|Any CPU.Build.0 = Debug|Any CPU
56 | {2657C9C5-0BEA-4616-BE41-A19E8298C591}.Release|Any CPU.ActiveCfg = Release|Any CPU
57 | {2657C9C5-0BEA-4616-BE41-A19E8298C591}.Release|Any CPU.Build.0 = Release|Any CPU
58 | {7080BE3D-4103-489A-9F7E-ED3D54CEC784}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
59 | {7080BE3D-4103-489A-9F7E-ED3D54CEC784}.Debug|Any CPU.Build.0 = Debug|Any CPU
60 | {7080BE3D-4103-489A-9F7E-ED3D54CEC784}.Release|Any CPU.ActiveCfg = Release|Any CPU
61 | {7080BE3D-4103-489A-9F7E-ED3D54CEC784}.Release|Any CPU.Build.0 = Release|Any CPU
62 | EndGlobalSection
63 | GlobalSection(SolutionProperties) = preSolution
64 | HideSolutionNode = FALSE
65 | EndGlobalSection
66 | GlobalSection(NestedProjects) = preSolution
67 | {D2720BBB-C233-4A1E-9768-1F00C9602180} = {60662102-4523-441E-8D6C-D87A3246C648}
68 | {8C5EBACA-C6C7-463B-B85C-C6A05E5DEB9F} = {BDAFF1CB-8E53-412B-B389-42A15343C7A3}
69 | {DAC2FED6-E960-4E57-949F-6B9185924E60} = {60662102-4523-441E-8D6C-D87A3246C648}
70 | {625ECD09-F1E4-4979-B7A6-F94F23F7BBB0} = {60662102-4523-441E-8D6C-D87A3246C648}
71 | {205509EA-78C8-4ED0-B2B5-8030DDFB0BF0} = {FFAA235C-D30F-4958-BC4E-60CD08979464}
72 | {2657C9C5-0BEA-4616-BE41-A19E8298C591} = {FFAA235C-D30F-4958-BC4E-60CD08979464}
73 | {7080BE3D-4103-489A-9F7E-ED3D54CEC784} = {289E4C98-1DBA-4E34-A6CC-F9CF5E212790}
74 | EndGlobalSection
75 | GlobalSection(ExtensibilityGlobals) = postSolution
76 | SolutionGuid = {0121A3C4-6AE0-4622-BE04-05D9A3E729AC}
77 | EndGlobalSection
78 | EndGlobal
79 |
--------------------------------------------------------------------------------
/Directory.Build.props:
--------------------------------------------------------------------------------
1 |
2 |
3 | latest
4 | enable
5 | true
6 | $(NoWarn);CS1591
7 | true
8 | $(MSBuildThisFileDirectory)opensource.snk
9 |
10 |
11 | $(Version)
12 | ChronosGames
13 | yunjing
14 | © ChronosGames, Inc.
15 | https://github.com/ChronosGames/DataTables
16 | $(PackageProjectUrl)
17 | git
18 | MIT
19 | Icon.png
20 | $(MSBuildThisFileDirectory)opensource.snk
21 |
22 |
23 |
24 |
25 |
26 |
27 |
--------------------------------------------------------------------------------
/Icon.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/ChronosGames/DataTables/b34314effdbdd4c89f39672c86548365af14fae8/Icon.png
--------------------------------------------------------------------------------
/LICENSE:
--------------------------------------------------------------------------------
1 | MIT License
2 |
3 | Copyright (c) 2019 Yoshifumi Kawai / Cysharp, Inc.
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 |
--------------------------------------------------------------------------------
/opensource.snk:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/ChronosGames/DataTables/b34314effdbdd4c89f39672c86548365af14fae8/opensource.snk
--------------------------------------------------------------------------------
/sandbox/Benchmark/Benchmark.csproj:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | Exe
5 | false
6 | net8.0
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
--------------------------------------------------------------------------------
/sandbox/Benchmark/DataMatrixBase1.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Linq;
4 |
5 | namespace DataTables
6 | {
7 | public abstract class DataMatrixBase1 : DataTableBase
8 | where TValue : notnull
9 | {
10 | private Tuple[] m_DataSet = Array.Empty>();
11 | private readonly Dictionary, TValue> m_Dict1 = new Dictionary<(TKey1, TKey2), TValue>();
12 |
13 | protected virtual TValue DefaultValue => default;
14 |
15 | public override Type Type => typeof(TValue);
16 |
17 | public override int Count => m_DataSet.Length;
18 |
19 | public DataMatrixBase1(string name, int capacity) : base(name)
20 | {
21 | m_DataSet = new Tuple[capacity];
22 | }
23 |
24 | protected void SetDataRow(int index, TKey1 key1, TKey2 key2, TValue value)
25 | {
26 | m_DataSet[index] = Tuple.Create(key1, key2, value);
27 | m_Dict1.Add(ValueTuple.Create(key1, key2), value);
28 | }
29 |
30 | ///
31 | /// 获取当前的配置值,为空则取默认值
32 | ///
33 | ///
34 | ///
35 | ///
36 | public TValue? Get(TKey1 key1, TKey2 key2)
37 | {
38 | return m_Dict1.TryGetValue(ValueTuple.Create(key1, key2), out var value) ? value : DefaultValue;
39 | }
40 |
41 | ///
42 | /// 查询指定Key2与Value对应的Key1列表
43 | ///
44 | ///
45 | ///
46 | ///
47 | public IEnumerable FindKey1(TKey2 key2, TValue value)
48 | {
49 | for (var i = 0; i < m_DataSet.Length; i++)
50 | {
51 | var pair = m_DataSet[i];
52 | if (EqualityComparer.Default.Equals(pair.Item2, key2) && EqualityComparer.Default.Equals(pair.Item3, value))
53 | {
54 | yield return pair.Item1;
55 | }
56 | }
57 | }
58 |
59 | ///
60 | /// 查询指定Key1与Value对应的Key2列表
61 | ///
62 | ///
63 | ///
64 | ///
65 | public IEnumerable FindKey2(TKey1 key1, TValue value)
66 | {
67 | for (var i = 0; i < m_DataSet.Length; i++)
68 | {
69 | var pair = m_DataSet[i];
70 | if (EqualityComparer.Default.Equals(pair.Item1, key1) && EqualityComparer.Default.Equals(pair.Item3, value))
71 | {
72 | yield return pair.Item2;
73 | }
74 | }
75 | }
76 |
77 | ///
78 | /// 查询指定条件的结果
79 | ///
80 | ///
81 | ///
82 | public IEnumerable> Where(Func predicate)
83 | {
84 | return m_DataSet.Where(x => predicate(x.Item1, x.Item2, x.Item3));
85 | }
86 |
87 | public override void RemoveAllDataRows()
88 | {
89 | m_DataSet = Array.Empty>();
90 | m_Dict1.Clear();
91 | }
92 |
93 | internal override void Shutdown()
94 | {
95 | m_DataSet = Array.Empty>();
96 | m_Dict1.Clear();
97 | }
98 | }
99 | }
100 |
--------------------------------------------------------------------------------
/sandbox/Benchmark/DataMatrixs.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Diagnostics.CodeAnalysis;
4 | using System.IO;
5 | using DataTables;
6 |
7 | namespace Benchmark;
8 |
9 | public class Key1Comparer : IEqualityComparer
10 | {
11 | public bool Equals(Key1Enum x, Key1Enum y)
12 | {
13 | return (int)x == (int)y;
14 | }
15 |
16 | public int GetHashCode([DisallowNull] Key1Enum obj)
17 | {
18 | return (int)obj;
19 | }
20 | }
21 |
22 | public enum Key1Enum : int
23 | {
24 | Key01 = 0,
25 | Key02,
26 | Key03,
27 | Key04,
28 | Key05,
29 | Key06,
30 | Key07,
31 | Key08,
32 | Key09,
33 | Key10,
34 | Key11,
35 | MAX,
36 | }
37 |
38 | public class Key2Comparer : IEqualityComparer
39 | {
40 | public bool Equals(Key2Enum x, Key2Enum y)
41 | {
42 | return (int)x == (int)y;
43 | }
44 |
45 | public int GetHashCode([DisallowNull] Key2Enum obj)
46 | {
47 | return (int)obj;
48 | }
49 | }
50 |
51 | public enum Key2Enum : int
52 | {
53 | Key21 = 0,
54 | Key22,
55 | Key23,
56 | Key24,
57 | Key25,
58 | Key26,
59 | Key27,
60 | Key28,
61 | Key29,
62 | MAX,
63 | }
64 |
65 | public enum ValueEnum : int
66 | {
67 | Value1 = 0,
68 | Value2,
69 | Value3,
70 | MAX,
71 | }
72 |
73 | public class DataMatrix1 : DataMatrixBase1
74 | {
75 | public DataMatrix1(string name) : base(name, (int)Key1Enum.MAX * (int)Key2Enum.MAX)
76 | {
77 | for (int i = 0; i < (int)Key1Enum.MAX; i++)
78 | {
79 | for (int j = 0; j < (int)Key2Enum.MAX; j++)
80 | {
81 | base.SetDataRow(i * (int)Key2Enum.MAX + j, (Key1Enum)i, (Key2Enum)j, (ValueEnum)Random.Shared.Next((int)ValueEnum.MAX));
82 | }
83 | }
84 | }
85 |
86 | public override bool ParseDataRow(int index, BinaryReader reader)
87 | {
88 | throw new NotImplementedException();
89 | }
90 | }
91 |
92 | public class DataMatrix2 : DataMatrixBase
93 | {
94 | public DataMatrix2(string name) : base(name, (int)Key1Enum.MAX * (int)Key2Enum.MAX)
95 | {
96 | for (int i = 0; i < (int)Key1Enum.MAX; i++)
97 | {
98 | for (int j = 0; j < (int)Key2Enum.MAX; j++)
99 | {
100 | SetDataRow(i * (int)Key2Enum.MAX + j, (Key1Enum)i, (Key2Enum)j, (ValueEnum)Random.Shared.Next((int)ValueEnum.MAX));
101 | }
102 | }
103 | }
104 |
105 | public override void OnLoadCompleted()
106 | {
107 | m_Key1Comparer = new Key1Comparer();
108 | m_Key2Comparer = new Key2Comparer();
109 | }
110 | }
111 |
112 | public class DataMatrix3 : DataMatrixBase1
113 | {
114 | public DataMatrix3(string name) : base(name, (int)Key1Enum.MAX * (int)Key2Enum.MAX)
115 | {
116 | for (int i = 0; i < (int)Key1Enum.MAX; i++)
117 | {
118 | for (int j = 0; j < (int)Key2Enum.MAX; j++)
119 | {
120 | SetDataRow(i * (int)Key2Enum.MAX + j, (Key1Enum)i, (Key2Enum)j, new int[] { Random.Shared.Next(1000, 10000) });
121 | }
122 | }
123 | }
124 |
125 | public override bool ParseDataRow(int index, BinaryReader reader) => throw new NotImplementedException();
126 | }
127 |
128 | public class DataMatrix4 : DataMatrixBase
129 | {
130 | public DataMatrix4(string name) : base(name, (int)Key1Enum.MAX * (int)Key2Enum.MAX)
131 | {
132 | for (int i = 0; i < (int)Key1Enum.MAX; i++)
133 | {
134 | for (int j = 0; j < (int)Key2Enum.MAX; j++)
135 | {
136 | SetDataRow(i * (int)Key2Enum.MAX + j, (Key1Enum)i, (Key2Enum)j, new int[] { Random.Shared.Next(1000, 10000) });
137 | }
138 | }
139 | }
140 | }
141 |
142 | public class DataMatrix6 : DataMatrixBase
143 | {
144 | public DataMatrix6(string name) : base(name, (int)Key1Enum.MAX * (int)Key2Enum.MAX)
145 | {
146 | for (int i = 0; i < (int)Key1Enum.MAX; i++)
147 | {
148 | for (int j = 0; j < (int)Key2Enum.MAX; j++)
149 | {
150 | SetDataRow(i * (int)Key2Enum.MAX + j, Convert.ToString(i), (Key2Enum)j, new int[] { Random.Shared.Next(1000, 10000) });
151 | }
152 | }
153 | }
154 | }
155 |
--------------------------------------------------------------------------------
/sandbox/Benchmark/Utils/Helper.cs:
--------------------------------------------------------------------------------
1 | //using System;
2 | //using System.Collections.Generic;
3 | //using System.Diagnostics;
4 | //using System.Linq;
5 | //using System.Text;
6 | //using System.Threading.Tasks;
7 | //using MessagePack;
8 | //using LiteDB;
9 | //using MasterMemory;
10 |
11 | //namespace TestPerfLiteDB
12 | //{
13 | // [MemoryTable("TestDoc"), MessagePackObject(true)]
14 | // public class TestDoc
15 | // {
16 | // [PrimaryKey]
17 | // public int id { get; set; }
18 | // public string name { get; set; }
19 | // public string lorem { get; set; }
20 |
21 | // public TestDoc()
22 | // {
23 |
24 | // }
25 |
26 | // public TestDoc(int id, string name, string lorem)
27 | // {
28 | // this.id = id;
29 | // this.name = name;
30 | // this.lorem = lorem;
31 | // }
32 | // }
33 |
34 | // public static class Helper
35 | // {
36 | // public static IEnumerable GetDocs(int count)
37 | // {
38 | // for (var i = 0; i < count; i++)
39 | // {
40 | // yield return new BsonDocument
41 | // {
42 | // { "_id", i },
43 | // { "name", Guid.NewGuid().ToString() },
44 | // { "lorem", LoremIpsum(3, 5, 2, 3, 3) }
45 | // };
46 | // }
47 | // }
48 |
49 | // public static string LoremIpsum(int minWords, int maxWords,
50 | // int minSentences, int maxSentences,
51 | // int numParagraphs)
52 | // {
53 | // var words = new[] { "lorem", "ipsum", "dolor", "sit", "amet", "consectetuer",
54 | // "adipiscing", "elit", "sed", "diam", "nonummy", "nibh", "euismod",
55 | // "tincidunt", "ut", "laoreet", "dolore", "magna", "aliquam", "erat" };
56 |
57 | // var rand = new Random(DateTime.Now.Millisecond);
58 | // var numSentences = rand.Next(maxSentences - minSentences) + minSentences + 1;
59 | // var numWords = rand.Next(maxWords - minWords) + minWords + 1;
60 |
61 | // var result = new StringBuilder();
62 |
63 | // for (int p = 0; p < numParagraphs; p++)
64 | // {
65 | // for (int s = 0; s < numSentences; s++)
66 | // {
67 | // for (int w = 0; w < numWords; w++)
68 | // {
69 | // if (w > 0) { result.Append(" "); }
70 | // result.Append(words[rand.Next(words.Length)]);
71 | // }
72 | // result.Append(". ");
73 | // }
74 | // result.AppendLine();
75 | // }
76 |
77 | // return result.ToString();
78 | // }
79 | // }
80 | //}
81 |
--------------------------------------------------------------------------------
/sandbox/ConsoleApp/ConsoleApp.csproj:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | Exe
5 | net8.0
6 | false
7 |
8 |
9 |
10 | $(DefineConstants)TRACE;
11 |
12 |
13 |
14 | $(DefineConstants)TRACE;
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 | Always
24 |
25 |
26 |
27 |
28 |
--------------------------------------------------------------------------------
/sandbox/ConsoleApp/CustomSample.cs:
--------------------------------------------------------------------------------
1 | namespace ConsoleApp
2 | {
3 | public class CustomSample
4 | {
5 | private readonly string m_Raw;
6 |
7 | public string Raw => m_Raw;
8 |
9 | public CustomSample(string raw)
10 | {
11 | m_Raw = raw;
12 | }
13 | }
14 | }
15 |
--------------------------------------------------------------------------------
/sandbox/ConsoleApp/DataTables/ConsoleApp.DTDataTableSample.bytes:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/ChronosGames/DataTables/b34314effdbdd4c89f39672c86548365af14fae8/sandbox/ConsoleApp/DataTables/ConsoleApp.DTDataTableSample.bytes
--------------------------------------------------------------------------------
/sandbox/ConsoleApp/DataTables/ConsoleApp.DTDataTableSplitSample.x001.bytes:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/ChronosGames/DataTables/b34314effdbdd4c89f39672c86548365af14fae8/sandbox/ConsoleApp/DataTables/ConsoleApp.DTDataTableSplitSample.x001.bytes
--------------------------------------------------------------------------------
/sandbox/ConsoleApp/DataTables/ConsoleApp.DTDataTableSplitSample.x002.bytes:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/ChronosGames/DataTables/b34314effdbdd4c89f39672c86548365af14fae8/sandbox/ConsoleApp/DataTables/ConsoleApp.DTDataTableSplitSample.x002.bytes
--------------------------------------------------------------------------------
/sandbox/ConsoleApp/DataTables/ConsoleApp.DTMatrixSample.bytes:
--------------------------------------------------------------------------------
1 |
--------------------------------------------------------------------------------
/sandbox/ConsoleApp/Generated/DRMatrixSample.cs:
--------------------------------------------------------------------------------
1 | //
2 | #pragma warning disable CS0105
3 | #pragma warning disable CS8618 // Non-nullable field must contain a non-null value when exiting constructor. Consider adding the 'required' modifier or declaring as nullable.
4 | #pragma warning disable CS8602 // Dereference of a possibly null reference.
5 | using System;
6 | using System.IO;
7 | using System.Collections.Generic;
8 | using DataTables;
9 |
10 | #nullable enable
11 |
12 | namespace ConsoleApp
13 | {
14 |
15 | public sealed partial class DTMatrixSample : DataMatrixBase
16 | {
17 | protected override bool DefaultValue => true;
18 |
19 | public DTMatrixSample(string name, int capacity) : base(name, capacity)
20 | { }
21 |
22 | public override bool ParseDataRow(int index, BinaryReader reader)
23 | {
24 | short _key1;
25 | _key1 = reader.ReadInt16();
26 |
27 | long _key2;
28 | _key2 = reader.Read7BitEncodedInt64();
29 |
30 | bool _value;
31 | _value = reader.ReadBoolean();
32 |
33 | SetDataRow(index, _key1, _key2, _value);
34 | return true;
35 | }
36 | }
37 |
38 | }
39 |
--------------------------------------------------------------------------------
/sandbox/ConsoleApp/Generated/DataTableManagerExtension.cs:
--------------------------------------------------------------------------------
1 | //
2 | #pragma warning disable CS0105
3 |
4 | using System;
5 | using System.Collections.Generic;
6 | using DataTables;
7 |
8 | #nullable enable
9 |
10 | namespace ConsoleApp
11 | {
12 | public static class DataTableManagerExtension
13 | {
14 | public static readonly Dictionary Tables = new Dictionary
15 | {
16 | { "ConsoleApp.DTDataTableSample", Array.Empty() },
17 | { "ConsoleApp.DTDataTableSplitSample", new string[] {"x001", "x002"} },
18 | { "ConsoleApp.DTMatrixSample", Array.Empty() },
19 | };
20 |
21 | ///
22 | /// 预加载所有数据表。
23 | ///
24 | ///
25 | /// 全部数据表预加载完成时回调。
26 | /// 单步加载完成时回调。
27 | public static void Preload(this DataTableManager manager, Action? onCompleted = default, Action? onProgress = default)
28 | {
29 | const int total = 4;
30 | int done = 0;
31 |
32 | void next()
33 | {
34 | done++;
35 | onProgress?.Invoke((float)done / total);
36 | if (done == total)
37 | {
38 | onCompleted?.Invoke();
39 | }
40 | };
41 |
42 | manager.CreateDataTable(next);
43 | manager.CreateDataTable("x001", next);
44 | manager.CreateDataTable("x002", next);
45 | manager.CreateDataTable(next);
46 | }
47 | }
48 | }
49 |
--------------------------------------------------------------------------------
/sandbox/ConsoleApp/JSONSamle.cs:
--------------------------------------------------------------------------------
1 | using System.Text.Json.Serialization;
2 |
3 | namespace ConsoleApp;
4 |
5 | [JsonDerivedType(typeof(SampleChildren1), typeDiscriminator: "Children1")]
6 | [JsonDerivedType(typeof(SampleChildren2), typeDiscriminator: "Children2")]
7 | public class SampleParent
8 | {
9 | public string Id = string.Empty;
10 | }
11 |
12 | public class SampleChildren1 : SampleParent
13 | {
14 | public int IntValue1;
15 | }
16 |
17 | public class SampleChildren2 : SampleParent
18 | {
19 | public int IntValue2;
20 | }
21 |
--------------------------------------------------------------------------------
/sandbox/ConsoleApp/Program.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Diagnostics;
3 | using DataTables;
4 |
5 | namespace ConsoleApp;
6 |
7 | public enum ColorT
8 | {
9 | Red,
10 | Green,
11 | Blue
12 | }
13 |
14 | internal static class Program
15 | {
16 | private static void Main(string[] args)
17 | {
18 | var manager = new DataTableManager();
19 | manager.SetDataTableHelper(new DefaultDataTableHelper("DataTables"));
20 | manager.Preload(() => Console.WriteLine("数据表全部加载完毕"));
21 |
22 | Debug.Assert(manager.HasDataTable(), "加载配置表失败");
23 |
24 | var dtSample = manager.GetDataTable();
25 | Debug.Assert(dtSample!.GetAllDataRows()[dtSample.Count - 1].CustomFieldType.Raw == "aaa");
26 | Debug.Assert(dtSample.GetDataRowById(1) != null, "加载配置表失败1");
27 | Debug.Assert(dtSample.GetDataRowById(3)!.ArrayStringValue.Length == 2 && dtSample.GetDataRowById(3)!.ArrayStringValue[0] == "a", "加载配置表失败2");
28 | manager.DestroyDataTable(dtSample);
29 |
30 | Debug.Assert(manager.GetDataTable() != null, "加载MatrixSample失败");
31 | Debug.Assert(manager.GetDataTable()!.Get(2, 1) == false, "加载MatrixSample失败");
32 | Debug.Assert(manager.GetDataTable()!.Get(5, 3) == true, "加载MatrixSample失败");
33 | }
34 | }
35 |
--------------------------------------------------------------------------------
/sandbox/ConsoleApp/示例表.xlsx:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/ChronosGames/DataTables/b34314effdbdd4c89f39672c86548365af14fae8/sandbox/ConsoleApp/示例表.xlsx
--------------------------------------------------------------------------------
/src/DataTables.Generator/DataTables.Generator.csproj:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | Exe
5 | net8.0
6 | latest
7 | true
8 | dotnet-dtgen
9 |
10 |
11 |
12 |
13 | DataTables.Generator
14 | $(Version)
15 | Code Generator of DataTables.
16 | https://github.com/ChronosGames/DataTables
17 | unity, excel, generator, datatable
18 | true
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
29 |
30 |
31 |
32 |
33 |
34 |
--------------------------------------------------------------------------------
/src/DataTables.Generator/Program.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Diagnostics;
3 | using System.Threading.Tasks;
4 | using DataTables.GeneratorCore;
5 | using ConsoleAppFramework;
6 |
7 | var app = ConsoleApp.Create();
8 | app.Add();
9 | app.Run(args);
10 |
11 | public class MyCommands
12 | {
13 | ///
14 | /// 导出全部代码文件与配置数据
15 | ///
16 | /// -i, Input file directory(search recursive).
17 | /// -patterns, Input file wildcard.
18 | /// -co, Code output file directory.
19 | /// -do, Data output file directory.
20 | /// -ins, Import namespaces of generated files, split with char '&' for multiple namespaces.
21 | /// -n, Namespace of generated files.
22 | /// -p, Prefix of class names.
23 | /// -t, Tags of filter columns.
24 | /// -f, Overwrite generated files if the content is unchanged.
25 | [Command("")]
26 | public async Task ExportAll(
27 | string[] inputDirectories,
28 | string[] searchPattern,
29 | string codeOutputDir,
30 | string dataOutputDir,
31 | string importNamespaces = "",
32 | string usingNamespace = "",
33 | string prefixClassName = "",
34 | string filterColumnTags = "",
35 | bool forceOverwrite = false)
36 | {
37 | var oldEncoding = Console.OutputEncoding;
38 | Console.OutputEncoding = System.Text.Encoding.UTF8;
39 |
40 | var sw = Stopwatch.StartNew();
41 | Console.WriteLine("Start DataTables CodeGeneration");
42 |
43 | try
44 | {
45 | await new DataTableGenerator().GenerateFile(inputDirectories, searchPattern, codeOutputDir, dataOutputDir, usingNamespace, prefixClassName,
46 | importNamespaces: importNamespaces,
47 | filterColumnTags: filterColumnTags,
48 | forceOverwrite,
49 | Console.WriteLine);
50 | }
51 | catch (Exception e)
52 | {
53 | Console.ForegroundColor = ConsoleColor.Red;
54 | Console.WriteLine(e);
55 | Console.ResetColor();
56 | }
57 |
58 | Console.WriteLine("Complete DataTables Generation, elapsed: " + sw.Elapsed);
59 |
60 | Console.OutputEncoding = oldEncoding;
61 | }
62 |
63 | ///
64 | /// 导出单个数据文件
65 | ///
66 | /// -i, Input file directory(search recursive).
67 | /// -patterns, Input file wildcard.
68 | /// -do, Data output file directory.
69 | /// -ins, Import namespaces of generated files, split with char '&' for multiple namespaces.
70 | /// -n, Namespace of generated files.
71 | /// -p, Prefix of class names.
72 | /// -t, Tags of filter columns.
73 | [Command("data")]
74 | public async Task ExportOne(
75 | string[] inputDirectories,
76 | string[] searchPattern,
77 | string dataOutputDir,
78 | string importNamespaces = "",
79 | string usingNamespace = "",
80 | string prefixClassName = "",
81 | string filterColumnTags = "")
82 | {
83 | var oldEncoding = Console.OutputEncoding;
84 | Console.OutputEncoding = System.Text.Encoding.UTF8;
85 |
86 | var sw = Stopwatch.StartNew();
87 | Console.WriteLine("Start DataTables CodeGeneration");
88 |
89 | try
90 | {
91 | await new DataTableGenerator().GenerateFile(inputDirectories, searchPattern, string.Empty, dataOutputDir, usingNamespace, prefixClassName,
92 | importNamespaces: importNamespaces,
93 | filterColumnTags: filterColumnTags,
94 | true,
95 | Console.WriteLine);
96 | }
97 | catch (Exception e)
98 | {
99 | Console.ForegroundColor = ConsoleColor.Red;
100 | Console.WriteLine(e);
101 | Console.ResetColor();
102 | }
103 |
104 | Console.WriteLine("Complete DataTables Generation, elapsed: " + sw.Elapsed);
105 |
106 | Console.OutputEncoding = oldEncoding;
107 | }
108 | }
109 |
--------------------------------------------------------------------------------
/src/DataTables.Generator/Properties/launchSettings.json:
--------------------------------------------------------------------------------
1 | {
2 | "profiles": {
3 | "DataTables.Generator": {
4 | "commandName": "Project",
5 | "commandLineArgs": "-i [\\\"..\\\\..\\\\..\\\\..\\\\..\\\\sandbox\\\\ConsoleApp\\\"] -patterns \"*.xlsx\" -co \"$(SolutionDir)sandbox\\ConsoleApp\\Generated\" -do \"$(SolutionDir)sandbox\\ConsoleApp\\DataTables\" -t C -p DR -n ConsoleApp"
6 | }
7 | }
8 | }
--------------------------------------------------------------------------------
/src/DataTables.Generator/README.md:
--------------------------------------------------------------------------------
1 | # DataTables.Generator
2 | 数据表生成工具 - 适用于C#和Unity。
3 |
4 | 可用于将游戏数据表(Excel格式)转化为代码文件与数据文件,然后,在游戏内直接读取二进制数据文件,自动解析为对应类,后续可直接使用。
5 |
--------------------------------------------------------------------------------
/src/DataTables.GeneratorCore/BinaryExtension.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.IO;
3 |
4 | namespace DataTables;
5 |
6 | internal static class BinaryExtension
7 | {
8 | ///
9 | /// 从二进制流读取编码后的 32 位有符号整数。
10 | ///
11 | /// 要读取的二进制流。
12 | /// 读取的 32 位有符号整数。
13 | public static int Read7BitEncodedInt32(this BinaryReader binaryReader)
14 | {
15 | int value = 0;
16 | int shift = 0;
17 | byte b;
18 | do
19 | {
20 | if (shift >= 35)
21 | {
22 | throw new Exception("7 bit encoded int is invalid.");
23 | }
24 |
25 | b = binaryReader.ReadByte();
26 | value |= (b & 0x7f) << shift;
27 | shift += 7;
28 | } while ((b & 0x80) != 0);
29 |
30 | return value;
31 | }
32 |
33 | ///
34 | /// 向二进制流写入编码后的 32 位有符号整数。
35 | ///
36 | /// 要写入的二进制流。
37 | /// 要写入的 32 位有符号整数。
38 | public static void Write7BitEncodedInt32(this BinaryWriter binaryWriter, int value)
39 | {
40 | uint num = (uint)value;
41 | while (num >= 0x80)
42 | {
43 | binaryWriter.Write((byte)(num | 0x80));
44 | num >>= 7;
45 | }
46 |
47 | binaryWriter.Write((byte)num);
48 | }
49 |
50 | ///
51 | /// 从二进制流读取编码后的 32 位无符号整数。
52 | ///
53 | /// 要读取的二进制流。
54 | /// 读取的 32 位无符号整数。
55 | public static uint Read7BitEncodedUInt32(this BinaryReader binaryReader)
56 | {
57 | return (uint)Read7BitEncodedInt32(binaryReader);
58 | }
59 |
60 | ///
61 | /// 向二进制流写入编码后的 32 位无符号整数。
62 | ///
63 | /// 要写入的二进制流。
64 | /// 要写入的 32 位无符号整数。
65 | public static void Write7BitEncodedUInt32(this BinaryWriter binaryWriter, uint value)
66 | {
67 | Write7BitEncodedInt32(binaryWriter, (int)value);
68 | }
69 |
70 | ///
71 | /// 从二进制流读取编码后的 64 位有符号整数。
72 | ///
73 | /// 要读取的二进制流。
74 | /// 读取的 64 位有符号整数。
75 | public static long Read7BitEncodedInt64(this BinaryReader binaryReader)
76 | {
77 | long value = 0L;
78 | int shift = 0;
79 | byte b;
80 | do
81 | {
82 | if (shift >= 70)
83 | {
84 | throw new Exception("7 bit encoded int is invalid.");
85 | }
86 |
87 | b = binaryReader.ReadByte();
88 | value |= (b & 0x7fL) << shift;
89 | shift += 7;
90 | } while ((b & 0x80) != 0);
91 |
92 | return value;
93 | }
94 |
95 | ///
96 | /// 向二进制流写入编码后的 64 位有符号整数。
97 | ///
98 | /// 要写入的二进制流。
99 | /// 要写入的 64 位有符号整数。
100 | public static void Write7BitEncodedInt64(this BinaryWriter binaryWriter, long value)
101 | {
102 | ulong num = (ulong)value;
103 | while (num >= 0x80)
104 | {
105 | binaryWriter.Write((byte)(num | 0x80));
106 | num >>= 7;
107 | }
108 |
109 | binaryWriter.Write((byte)num);
110 | }
111 |
112 | ///
113 | /// 从二进制流读取编码后的 64 位无符号整数。
114 | ///
115 | /// 要读取的二进制流。
116 | /// 读取的 64 位无符号整数。
117 | public static ulong Read7BitEncodedUInt64(this BinaryReader binaryReader)
118 | {
119 | return (ulong)Read7BitEncodedInt64(binaryReader);
120 | }
121 |
122 | ///
123 | /// 向二进制流写入编码后的 64 位无符号整数。
124 | ///
125 | /// 要写入的二进制流。
126 | /// 要写入的 64 位无符号整数。
127 | public static void Write7BitEncodedUInt64(this BinaryWriter binaryWriter, ulong value)
128 | {
129 | Write7BitEncodedInt64(binaryWriter, (long)value);
130 | }
131 | }
132 |
--------------------------------------------------------------------------------
/src/DataTables.GeneratorCore/DataMatrixTemplate.tt:
--------------------------------------------------------------------------------
1 | <#@ template debug="false" hostspecific="false" linePragmas="false" language="C#" #>
2 | <#@ assembly name="System.Core" #>
3 | <#@ import namespace="System.Linq" #>
4 | <#@ import namespace="System.Text" #>
5 | <#@ import namespace="System.Collections.Generic" #>
6 | //
7 | #pragma warning disable CS0105
8 | #pragma warning disable CS8618 // Non-nullable field must contain a non-null value when exiting constructor. Consider adding the 'required' modifier or declaring as nullable.
9 | #pragma warning disable CS8602 // Dereference of a possibly null reference.
10 | using System;
11 | using System.IO;
12 | using System.Collections.Generic;
13 | using DataTables;
14 |
15 | #nullable enable
16 |
17 | <# if (!string.IsNullOrEmpty(GenerationContext.Namespace)) { #>
18 | namespace <#= GenerationContext.Namespace #>
19 | {
20 | <# } #>
21 |
22 | public sealed partial class DT<#= GenerationContext.ClassName #> : DataMatrixBase<<#= BuildTypeString(kKey1) #>, <#= BuildTypeString(kKey2) #>, <#= BuildTypeString(kValue) #>>
23 | {
24 | <#= string.IsNullOrEmpty(GenerationContext.MatrixDefaultValue) ? string.Empty : "protected override " + BuildTypeString(kValue) + " DefaultValue => " + BuildTypeValueString(kValue, GenerationContext.MatrixDefaultValue) + ";" + Environment.NewLine #>
25 | public DT<#= GenerationContext.ClassName #>(string name, int capacity) : base(name, capacity)
26 | { }
27 |
28 | public override bool ParseDataRow(int index, BinaryReader reader)
29 | {
30 | <#= BuildTypeString(kKey1) #> <#= kKey1 #>;
31 | <#= BuildDeserializeMethodString(kKey1) #>
32 |
33 | <#= BuildTypeString(kKey2) #> <#= kKey2 #>;
34 | <#= BuildDeserializeMethodString(kKey2) #>
35 |
36 | <#= BuildTypeString(kValue) #> <#= kValue #>;
37 | <#= BuildDeserializeMethodString(kValue) #>
38 |
39 | SetDataRow(index, <#= kKey1 #>, <#= kKey2 #>, <#= kValue #>);
40 | return true;
41 | }
42 | }
43 |
44 | <# if (!string.IsNullOrEmpty(GenerationContext.Namespace)) { #>
45 | }
46 | <# } #>
47 |
--------------------------------------------------------------------------------
/src/DataTables.GeneratorCore/DataTableManagerExtensionTemplate.tt:
--------------------------------------------------------------------------------
1 | <#@ template debug="false" hostspecific="false" linePragmas="false" language="C#" #>
2 | <#@ assembly name="System.Core" #>
3 | <#@ import namespace="System.Linq" #>
4 | <#@ import namespace="System.Text" #>
5 | <#@ import namespace="System.Collections.Generic" #>
6 | //
7 | #pragma warning disable CS0105
8 |
9 | using System;
10 | using System.Collections.Generic;
11 | using DataTables;
12 |
13 | #nullable enable
14 |
15 | <# if (!string.IsNullOrEmpty(Namespace)) { #>
16 | namespace <#= Namespace #>
17 | {
18 | <# } #>
19 | public static class DataTableManagerExtension
20 | {
21 | public static readonly Dictionary Tables = new Dictionary
22 | {
23 | <# foreach (var pair in DataTables)
24 | {
25 | #> { "<#= pair.Key #>", <#=(!pair.Value.Any() ? "Array.Empty()" : "new string[] {\"" + string.Join("\", \"", pair.Value) + "\"}")#> },<#=Environment.NewLine#><#
26 | } #>
27 | };
28 |
29 | ///
30 | /// 预加载所有数据表。
31 | ///
32 | ///
33 | /// 全部数据表预加载完成时回调。
34 | /// 单步加载完成时回调。
35 | public static void Preload(this DataTableManager manager, Action? onCompleted = default, Action? onProgress = default)
36 | {
37 | const int total = <#=DataTables.Sum(pair => pair.Value.Any() ? pair.Value.Count() : 1)#>;
38 | int done = 0;
39 |
40 | void next()
41 | {
42 | done++;
43 | onProgress?.Invoke((float)done / total);
44 | if (done == total)
45 | {
46 | onCompleted?.Invoke();
47 | }
48 | };
49 |
50 | <#
51 | foreach (var pair in DataTables)
52 | {
53 | if (!pair.Value.Any())
54 | {
55 | #> manager.CreateDataTable<<#=pair.Key#>>(next);<#=Environment.NewLine#><#
56 | }
57 | else
58 | {
59 | foreach (var name in pair.Value)
60 | {
61 | #> manager.CreateDataTable<<#=pair.Key#>>("<#=name#>", next);<#=Environment.NewLine#><#
62 | }
63 | }
64 | }
65 | #>
66 | }
67 | }
68 | <# if (!string.IsNullOrEmpty(Namespace)) { #>
69 | }
70 | <# } #>
71 |
--------------------------------------------------------------------------------
/src/DataTables.GeneratorCore/DataTableProcessor.ArrayDataProcessor.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections;
3 | using System.IO;
4 |
5 | namespace DataTables.GeneratorCore;
6 |
7 | public sealed partial class DataTableProcessor
8 | {
9 | public class ArrayDataProcessor : DataProcessor
10 | {
11 | public override Type Type => typeof(ArrayList);
12 |
13 | public override bool IsSystem => false;
14 |
15 | public override string LanguageKeyword => m_LanguageKeyword;
16 |
17 | private readonly string m_KeyTypeStr;
18 | private readonly string m_LanguageKeyword;
19 |
20 | public ArrayDataProcessor()
21 | {
22 | m_KeyTypeStr = string.Empty;
23 | m_LanguageKeyword = string.Empty;
24 | }
25 |
26 | public ArrayDataProcessor(DataProcessor keyProcessor)
27 | {
28 | m_KeyTypeStr = keyProcessor.GetTypeStrings()[0];
29 | m_LanguageKeyword = $"{keyProcessor.LanguageKeyword}[]";
30 | }
31 |
32 | public override string[] GetTypeStrings()
33 | {
34 | return new string[]
35 | {
36 | $"array<{m_KeyTypeStr}>",
37 | $"A<{m_KeyTypeStr}>",
38 | };
39 | }
40 |
41 | public override string GenerateTypeValue(string text) => throw new NotImplementedException();
42 |
43 | public override void WriteToStream(BinaryWriter binaryWriter, string value)
44 | {
45 | // 默认为空时自动补齐为空数组
46 | if (string.IsNullOrEmpty(value) || value == "0")
47 | {
48 | value = "[]";
49 | }
50 |
51 | var arr = JsonUtility.Deserialize(value);
52 | if (arr == null)
53 | {
54 | binaryWriter.Write7BitEncodedInt32(0);
55 | return;
56 | }
57 |
58 | binaryWriter.Write7BitEncodedInt32(arr.Count);
59 | foreach (var item in arr)
60 | {
61 | if (string.Compare(m_KeyTypeStr, "string", StringComparison.OrdinalIgnoreCase) == 0)
62 | {
63 | DataProcessorUtility.GetDataProcessor(m_KeyTypeStr).WriteToStream(binaryWriter, item.ToString()!);
64 | }
65 | else
66 | {
67 | DataProcessorUtility.GetDataProcessor(m_KeyTypeStr).WriteToStream(binaryWriter, JsonUtility.Serialize(item));
68 | }
69 | }
70 | }
71 |
72 | public override string GenerateDeserializeCode(GenerationContext context, string typeName, string propertyName, int depth)
73 | {
74 | return "{\n"
75 | + $"{Tabs(depth + 1)}var __{propertyName}_Count{depth + 1} = reader.Read7BitEncodedInt32();\n"
76 | + $"{Tabs(depth + 1)}{propertyName} = new {BuildArrayInitString(LanguageKeyword, $"__{propertyName}_Count{depth + 1}")};\n"
77 | + $"{Tabs(depth + 1)}for (int x{depth + 1} = 0; x{depth + 1} < __{propertyName}_Count{depth + 1}; x{depth + 1}++)\n"
78 | + $"{Tabs(depth + 1)}{{\n"
79 | + $"{Tabs(depth + 2)}{DataProcessorUtility.GetDataProcessor(m_KeyTypeStr).LanguageKeyword} key{depth + 1};\n"
80 | + $"{Tabs(depth + 2)}{DataProcessorUtility.GetDataProcessor(m_KeyTypeStr).GenerateDeserializeCode(context, Type.Name, $"key{depth + 1}", depth + 2)}\n"
81 | + $"{Tabs(depth + 2)}{propertyName}[x{depth + 1}] = key{depth + 1};\n"
82 | + $"{Tabs(depth + 1)}}}\n"
83 | + $"{Tabs(depth)}}}";
84 | }
85 |
86 | ///
87 | /// 获取数组后缀
88 | ///
89 | ///
90 | ///
91 | private int GetIndexOfFirstArrayLabelPairSuffix(string text)
92 | {
93 | int index = -1;
94 |
95 | for (int i = text.Length - 2; i >= 0; i -= 2)
96 | {
97 | if (text[i] == '[' && text[i + 1] == ']')
98 | {
99 | index = i;
100 | continue;
101 | }
102 |
103 | break;
104 | }
105 |
106 | return index;
107 | }
108 |
109 | private string BuildArrayInitString(string text, string propertyName)
110 | {
111 | int index = GetIndexOfFirstArrayLabelPairSuffix(text);
112 | return text.Substring(0, index + 1) + propertyName + text.Substring(index + 1);
113 | }
114 | }
115 | }
116 |
--------------------------------------------------------------------------------
/src/DataTables.GeneratorCore/DataTableProcessor.BooleanProcessor.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.IO;
4 |
5 | namespace DataTables.GeneratorCore;
6 |
7 | public sealed partial class DataTableProcessor
8 | {
9 | private static Dictionary kBoolMap = new(StringComparer.OrdinalIgnoreCase)
10 | {
11 | { "1", true },
12 | { "0", false },
13 | { "y", true },
14 | { "n", false },
15 | { "yes", true },
16 | { "no", false },
17 | { "true", true },
18 | { "false", false },
19 | { "true()", true },
20 | { "false()", false },
21 | };
22 |
23 | private sealed class BooleanProcessor : GenericDataProcessor
24 | {
25 |
26 | public override bool IsSystem
27 | {
28 | get
29 | {
30 | return true;
31 | }
32 | }
33 |
34 | public override string LanguageKeyword
35 | {
36 | get
37 | {
38 | return "bool";
39 | }
40 | }
41 |
42 | public override Type Type => typeof(bool);
43 |
44 | public override string[] GetTypeStrings()
45 | {
46 | return new string[]
47 | {
48 | "bool",
49 | "boolean",
50 | "system.boolean"
51 | };
52 | }
53 |
54 | public override string GenerateTypeValue(string text)
55 | {
56 | return Parse(text) ? "true" : "false";
57 | }
58 |
59 | public override bool Parse(string value)
60 | {
61 | if (string.IsNullOrEmpty(value))
62 | {
63 | return false;
64 | }
65 |
66 | if (kBoolMap.TryGetValue(value, out var result))
67 | {
68 | return result;
69 | }
70 |
71 | throw new InvalidCastException($"无法将{value}转换为bool类型");
72 | }
73 |
74 | public override string GenerateDeserializeCode(GenerationContext context, string typeName, string propertyName, int depth)
75 | {
76 | return $"{propertyName} = reader.ReadBoolean();";
77 | }
78 |
79 | public override void WriteToStream(BinaryWriter binaryWriter, string value)
80 | {
81 | binaryWriter.Write(Parse(value));
82 | }
83 | }
84 | }
85 |
--------------------------------------------------------------------------------
/src/DataTables.GeneratorCore/DataTableProcessor.ByteProcessor.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.IO;
3 |
4 | namespace DataTables.GeneratorCore;
5 |
6 | public sealed partial class DataTableProcessor
7 | {
8 | private sealed class ByteProcessor : GenericDataProcessor
9 | {
10 | public override bool IsSystem
11 | {
12 | get
13 | {
14 | return true;
15 | }
16 | }
17 |
18 | public override string LanguageKeyword
19 | {
20 | get
21 | {
22 | return "byte";
23 | }
24 | }
25 |
26 | public override string[] GetTypeStrings()
27 | {
28 | return new string[]
29 | {
30 | "byte",
31 | "system.byte"
32 | };
33 | }
34 |
35 | public override Type Type => typeof(byte);
36 |
37 | public override string GenerateTypeValue(string text) => Parse(text).ToString();
38 |
39 | public override byte Parse(string value)
40 | {
41 | return string.IsNullOrEmpty(value) ? default : byte.Parse(value);
42 | }
43 |
44 | public override void WriteToStream(BinaryWriter binaryWriter, string value)
45 | {
46 | binaryWriter.Write(Parse(value));
47 | }
48 |
49 | public override string GenerateDeserializeCode(GenerationContext context, string typeName, string propertyName, int depth)
50 | {
51 | return $"{propertyName} = reader.ReadByte();";
52 | }
53 | }
54 | }
55 |
--------------------------------------------------------------------------------
/src/DataTables.GeneratorCore/DataTableProcessor.CharProcessor.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.IO;
3 |
4 | namespace DataTables.GeneratorCore;
5 |
6 | public sealed partial class DataTableProcessor
7 | {
8 | private sealed class CharProcessor : GenericDataProcessor
9 | {
10 | public override bool IsSystem
11 | {
12 | get
13 | {
14 | return true;
15 | }
16 | }
17 |
18 | public override string LanguageKeyword
19 | {
20 | get
21 | {
22 | return "char";
23 | }
24 | }
25 |
26 | public override string[] GetTypeStrings()
27 | {
28 | return new string[]
29 | {
30 | "char",
31 | "system.char"
32 | };
33 | }
34 |
35 | public override Type Type => typeof(char);
36 |
37 | public override string GenerateTypeValue(string text) => Parse(text).ToString();
38 |
39 | public override char Parse(string value)
40 | {
41 | return string.IsNullOrEmpty(value) ? default : char.Parse(value);
42 | }
43 |
44 | public override void WriteToStream(BinaryWriter binaryWriter, string value)
45 | {
46 | binaryWriter.Write(Parse(value));
47 | }
48 |
49 | public override string GenerateDeserializeCode(GenerationContext context, string typeName, string propertyName, int depth)
50 | {
51 | return $"{propertyName} = reader.ReadChar();";
52 | }
53 | }
54 | }
55 |
--------------------------------------------------------------------------------
/src/DataTables.GeneratorCore/DataTableProcessor.CustomProcessor.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.IO;
3 |
4 | namespace DataTables.GeneratorCore;
5 |
6 | public sealed partial class DataTableProcessor
7 | {
8 | private sealed class CustomizeProcessor : GenericDataProcessor
9 | {
10 | public override bool IsSystem
11 | {
12 | get
13 | {
14 | return false;
15 | }
16 | }
17 |
18 | public override string LanguageKeyword => m_TypeString;
19 |
20 | public override string[] GetTypeStrings()
21 | {
22 | return
23 | [
24 | $"custom<{m_TypeString}>"
25 | ];
26 | }
27 |
28 | public override Type Type => typeof(string);
29 |
30 | private readonly string m_TypeString;
31 |
32 | // ReSharper disable once UnusedMember.Local
33 | public CustomizeProcessor() : this(string.Empty)
34 | { }
35 |
36 | public CustomizeProcessor(string typeString)
37 | {
38 | m_TypeString = typeString;
39 | }
40 |
41 | public override string GenerateTypeValue(string text) => $"new {m_TypeString}(@\"{text}\")";
42 |
43 | public override string Parse(string value)
44 | {
45 | return value.StartsWith("\"") ? JsonUtility.Deserialize(value)! : value;
46 | }
47 |
48 | public override void WriteToStream(BinaryWriter binaryWriter, string value)
49 | {
50 | binaryWriter.Write(Parse(value));
51 | }
52 |
53 | public override string GenerateDeserializeCode(GenerationContext context, string typeName, string propertyName, int depth)
54 | {
55 | return $"{propertyName} = new {m_TypeString}(reader.ReadString());";
56 | }
57 | }
58 | }
59 |
--------------------------------------------------------------------------------
/src/DataTables.GeneratorCore/DataTableProcessor.DataProcessor.cs:
--------------------------------------------------------------------------------
1 | using System.IO;
2 |
3 | namespace DataTables.GeneratorCore;
4 |
5 | public sealed partial class DataTableProcessor
6 | {
7 | public abstract class DataProcessor
8 | {
9 | public abstract System.Type Type
10 | {
11 | get;
12 | }
13 |
14 | public abstract bool IsSystem
15 | {
16 | get;
17 | }
18 |
19 | public abstract string LanguageKeyword
20 | {
21 | get;
22 | }
23 |
24 | protected string Tabs(int depth)
25 | {
26 | return new string(' ', 4 * (depth + 2));
27 | }
28 |
29 | public abstract string[] GetTypeStrings();
30 |
31 | ///
32 | /// 将字符串文本转化为实际变量值
33 | ///
34 | ///
35 | ///
36 | public abstract string GenerateTypeValue(string text);
37 |
38 | public abstract string GenerateDeserializeCode(GenerationContext context, string typeName, string propertyName, int depth);
39 |
40 | public abstract void WriteToStream(BinaryWriter binaryWriter, string value);
41 | }
42 | }
43 |
--------------------------------------------------------------------------------
/src/DataTables.GeneratorCore/DataTableProcessor.DateTimeProcessor.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.IO;
3 |
4 | namespace DataTables.GeneratorCore;
5 |
6 | public sealed partial class DataTableProcessor
7 | {
8 | private sealed class DateTimeProcessor : GenericDataProcessor
9 | {
10 | public override bool IsSystem => true;
11 |
12 | public override string LanguageKeyword
13 | {
14 | get
15 | {
16 | return "DateTime";
17 | }
18 | }
19 |
20 | public override string[] GetTypeStrings()
21 | {
22 | return new string[]
23 | {
24 | "datetime",
25 | "system.datetime"
26 | };
27 | }
28 |
29 | public override Type Type => typeof(DateTime);
30 |
31 | public override string GenerateTypeValue(string text)
32 | {
33 | var datetime = Parse(text);
34 | return $"new DateTime({datetime.Year}, {datetime.Month}, {datetime.Day}, {datetime.Hour}, {datetime.Minute}, {datetime.Second})";
35 | }
36 |
37 | public override DateTime Parse(string value)
38 | {
39 | new DateTime(2012, 2, 2, 3, 4, 5);
40 |
41 | return DateTime.Parse(value);
42 | }
43 |
44 | public override string GenerateDeserializeCode(GenerationContext context, string typeName, string propertyName, int depth)
45 | {
46 | return $"{propertyName} = new DateTime(reader.ReadInt64());";
47 | }
48 |
49 | public override void WriteToStream(BinaryWriter binaryWriter, string value)
50 | {
51 | binaryWriter.Write(Parse(value).Ticks);
52 | }
53 | }
54 | }
55 |
--------------------------------------------------------------------------------
/src/DataTables.GeneratorCore/DataTableProcessor.DecimalProcessor.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.IO;
3 |
4 | namespace DataTables.GeneratorCore;
5 |
6 | public sealed partial class DataTableProcessor
7 | {
8 | private sealed class DecimalProcessor : GenericDataProcessor
9 | {
10 | public override bool IsSystem
11 | {
12 | get
13 | {
14 | return true;
15 | }
16 | }
17 |
18 | public override string LanguageKeyword
19 | {
20 | get
21 | {
22 | return "decimal";
23 | }
24 | }
25 |
26 | public override string[] GetTypeStrings()
27 | {
28 | return new string[]
29 | {
30 | "decimal",
31 | "system.decimal"
32 | };
33 | }
34 |
35 | public override Type Type => typeof(decimal);
36 |
37 | public override string GenerateTypeValue(string text) => Parse(text).ToString() + 'm';
38 |
39 | public override decimal Parse(string value)
40 | {
41 | return decimal.Parse(value);
42 | }
43 |
44 | public override void WriteToStream(BinaryWriter binaryWriter, string value)
45 | {
46 | binaryWriter.Write(Parse(value));
47 | }
48 |
49 | public override string GenerateDeserializeCode(GenerationContext context, string typeName, string propertyName, int depth)
50 | {
51 | return $"{propertyName} = reader.ReadDecimal();";
52 | }
53 | }
54 | }
55 |
--------------------------------------------------------------------------------
/src/DataTables.GeneratorCore/DataTableProcessor.DoubleProcessor.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.IO;
3 |
4 | namespace DataTables.GeneratorCore;
5 |
6 | public sealed partial class DataTableProcessor
7 | {
8 | private sealed class DoubleProcessor : GenericDataProcessor
9 | {
10 | public override bool IsSystem
11 | {
12 | get
13 | {
14 | return true;
15 | }
16 | }
17 |
18 | public override string LanguageKeyword
19 | {
20 | get
21 | {
22 | return "double";
23 | }
24 | }
25 |
26 | public override string[] GetTypeStrings()
27 | {
28 | return new string[]
29 | {
30 | "double",
31 | "system.double"
32 | };
33 | }
34 |
35 | public override Type Type => typeof(double);
36 |
37 | public override string GenerateTypeValue(string text) => Parse(text).ToString() + 'd';
38 |
39 | public override double Parse(string value)
40 | {
41 | return string.IsNullOrEmpty(value) ? 0d : double.Parse(value);
42 | }
43 |
44 | public override void WriteToStream(BinaryWriter binaryWriter, string value)
45 | {
46 | binaryWriter.Write(Parse(value));
47 | }
48 |
49 | public override string GenerateDeserializeCode(GenerationContext context, string typeName, string propertyName, int depth)
50 | {
51 | return $"{propertyName} = reader.ReadDouble();";
52 | }
53 | }
54 | }
55 |
--------------------------------------------------------------------------------
/src/DataTables.GeneratorCore/DataTableProcessor.EnumProcessor.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.IO;
3 |
4 | namespace DataTables.GeneratorCore;
5 |
6 | public sealed partial class DataTableProcessor
7 | {
8 | private sealed class EnumProcessor : GenericDataProcessor
9 | {
10 | public override bool IsSystem
11 | {
12 | get
13 | {
14 | return false;
15 | }
16 | }
17 |
18 | public override string LanguageKeyword => m_TypeString;
19 |
20 | public override string[] GetTypeStrings()
21 | {
22 | return new string[]
23 | {
24 | $"enum<{m_TypeString}>",
25 | $"E<{m_TypeString}>",
26 | };
27 | }
28 |
29 | public override Type Type => typeof(string);
30 |
31 | private readonly string m_TypeString;
32 |
33 | public EnumProcessor() { m_TypeString = string.Empty; }
34 |
35 | public EnumProcessor(string typeString)
36 | {
37 | m_TypeString = typeString;
38 | }
39 |
40 | public override string GenerateTypeValue(string text) => m_TypeString + '.' + text;
41 |
42 | public override string Parse(string value)
43 | {
44 | return value.StartsWith("\"") ? JsonUtility.Deserialize(value)! : value;
45 | }
46 |
47 | public override void WriteToStream(BinaryWriter binaryWriter, string value)
48 | {
49 | binaryWriter.Write(Parse(value));
50 | }
51 |
52 | public override string GenerateDeserializeCode(GenerationContext context, string typeName, string propertyName, int depth)
53 | {
54 | return $"{{\n"
55 | + $"{Tabs(depth + 1)}{m_TypeString} __enumVal = default;\n"
56 | + $"{Tabs(depth + 1)}var __enumStr = reader.ReadString();\n"
57 | + $"{Tabs(depth + 1)}if (!string.IsNullOrEmpty(__enumStr) && !Enum.TryParse(__enumStr, out __enumVal))\n"
58 | + $"{Tabs(depth + 1)}{{\n"
59 | + $"{Tabs(depth + 2)}throw new ArgumentException();\n"
60 | + $"{Tabs(depth + 1)}}}\n"
61 | + $"{Tabs(depth + 1)}{propertyName} = __enumVal;\n"
62 | + $"{Tabs(depth)}}}";
63 | }
64 | }
65 | }
66 |
--------------------------------------------------------------------------------
/src/DataTables.GeneratorCore/DataTableProcessor.GenericDataProcessor.cs:
--------------------------------------------------------------------------------
1 | using System;
2 |
3 | namespace DataTables.GeneratorCore;
4 |
5 | public sealed partial class DataTableProcessor
6 | {
7 | public abstract class GenericDataProcessor : DataProcessor
8 | {
9 | public override Type Type => typeof(T);
10 |
11 | public abstract T Parse(string value);
12 | }
13 | }
14 |
--------------------------------------------------------------------------------
/src/DataTables.GeneratorCore/DataTableProcessor.Int16Processor.cs:
--------------------------------------------------------------------------------
1 | using System.IO;
2 |
3 | namespace DataTables.GeneratorCore;
4 |
5 | public sealed partial class DataTableProcessor
6 | {
7 | private sealed class Int16Processor : GenericDataProcessor
8 | {
9 | public override bool IsSystem
10 | {
11 | get
12 | {
13 | return true;
14 | }
15 | }
16 |
17 | public override string LanguageKeyword
18 | {
19 | get
20 | {
21 | return "short";
22 | }
23 | }
24 |
25 | public override string[] GetTypeStrings()
26 | {
27 | return new string[]
28 | {
29 | "short",
30 | "int16",
31 | "system.int16"
32 | };
33 | }
34 |
35 | public override short Parse(string value)
36 | {
37 | if (string.IsNullOrEmpty(value))
38 | {
39 | return 0;
40 | }
41 |
42 | return JsonUtility.Deserialize(value);
43 | }
44 |
45 | public override string GenerateTypeValue(string text) => Parse(text).ToString();
46 |
47 | public override void WriteToStream(BinaryWriter binaryWriter, string value)
48 | {
49 | binaryWriter.Write(Parse(value));
50 | }
51 |
52 | public override string GenerateDeserializeCode(GenerationContext context, string typeName, string propertyName, int depth)
53 | {
54 | return $"{propertyName} = reader.ReadInt16();";
55 | }
56 | }
57 | }
58 |
--------------------------------------------------------------------------------
/src/DataTables.GeneratorCore/DataTableProcessor.Int32Processor.cs:
--------------------------------------------------------------------------------
1 | using System.IO;
2 |
3 | namespace DataTables.GeneratorCore;
4 |
5 | public sealed partial class DataTableProcessor
6 | {
7 | private sealed class Int32Processor : GenericDataProcessor
8 | {
9 | public override bool IsSystem
10 | {
11 | get
12 | {
13 | return true;
14 | }
15 | }
16 |
17 | public override string LanguageKeyword
18 | {
19 | get
20 | {
21 | return "int";
22 | }
23 | }
24 |
25 | public override string[] GetTypeStrings()
26 | {
27 | return new string[]
28 | {
29 | "int",
30 | "int32",
31 | "system.int32"
32 | };
33 | }
34 |
35 | public override int Parse(string value)
36 | {
37 | if (string.IsNullOrEmpty(value))
38 | {
39 | return 0;
40 | }
41 |
42 | return JsonUtility.Deserialize(value);
43 | }
44 |
45 | public override string GenerateTypeValue(string text) => Parse(text).ToString();
46 |
47 | public override void WriteToStream(BinaryWriter binaryWriter, string value)
48 | {
49 | binaryWriter.Write7BitEncodedInt32(Parse(value));
50 | }
51 |
52 | public override string GenerateDeserializeCode(GenerationContext context, string typeName, string propertyName, int depth)
53 | {
54 | return $"{propertyName} = reader.Read7BitEncodedInt32();";
55 | }
56 | }
57 | }
58 |
--------------------------------------------------------------------------------
/src/DataTables.GeneratorCore/DataTableProcessor.Int64Processor.cs:
--------------------------------------------------------------------------------
1 | using System.IO;
2 |
3 | namespace DataTables.GeneratorCore;
4 |
5 | public sealed partial class DataTableProcessor
6 | {
7 | private sealed class Int64Processor : GenericDataProcessor
8 | {
9 | public override bool IsSystem
10 | {
11 | get
12 | {
13 | return true;
14 | }
15 | }
16 |
17 | public override string LanguageKeyword
18 | {
19 | get
20 | {
21 | return "long";
22 | }
23 | }
24 |
25 | public override string[] GetTypeStrings()
26 | {
27 | return new string[]
28 | {
29 | "long",
30 | "int64",
31 | "system.int64"
32 | };
33 | }
34 |
35 | public override long Parse(string value)
36 | {
37 | if (string.IsNullOrEmpty(value))
38 | {
39 | return 0;
40 | }
41 |
42 | return JsonUtility.Deserialize(value);
43 | }
44 |
45 | public override string GenerateTypeValue(string text) => Parse(text).ToString() + 'L';
46 |
47 | public override void WriteToStream(BinaryWriter binaryWriter, string value)
48 | {
49 | binaryWriter.Write7BitEncodedInt64(Parse(value));
50 | }
51 |
52 | public override string GenerateDeserializeCode(GenerationContext context, string typeName, string propertyName, int depth)
53 | {
54 | return $"{propertyName} = reader.Read7BitEncodedInt64();";
55 | }
56 | }
57 | }
58 |
--------------------------------------------------------------------------------
/src/DataTables.GeneratorCore/DataTableProcessor.JSONProcessor.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.IO;
3 |
4 | namespace DataTables.GeneratorCore;
5 |
6 | public sealed partial class DataTableProcessor
7 | {
8 | private sealed class JSONProcessor : GenericDataProcessor
9 | {
10 | public override bool IsSystem
11 | {
12 | get
13 | {
14 | return false;
15 | }
16 | }
17 |
18 | public override string LanguageKeyword => m_TypeString;
19 |
20 | public override string[] GetTypeStrings()
21 | {
22 | return new string[]
23 | {
24 | $"json<{m_TypeString}>",
25 | };
26 | }
27 |
28 | public override Type Type => typeof(string);
29 |
30 | private readonly string m_TypeString;
31 |
32 | public JSONProcessor() : this(string.Empty) { }
33 |
34 | public JSONProcessor(string typeString)
35 | {
36 | m_TypeString = typeString;
37 | }
38 |
39 | public override string Parse(string value)
40 | {
41 | return value.StartsWith("\"") ? JsonUtility.Deserialize(value)! : value;
42 | }
43 |
44 | public override string GenerateTypeValue(string text) => throw new NotImplementedException();
45 |
46 | public override void WriteToStream(BinaryWriter binaryWriter, string value)
47 | {
48 | binaryWriter.Write(Parse(value));
49 | }
50 |
51 | public override string GenerateDeserializeCode(GenerationContext context, string typeName, string propertyName, int depth)
52 | {
53 | return $"{{\n"
54 | + $"{Tabs(depth + 1)}{propertyName} = reader.ReadJson<{m_TypeString}>();\n"
55 | + $"{Tabs(depth)}}}";
56 | }
57 | }
58 | }
59 |
--------------------------------------------------------------------------------
/src/DataTables.GeneratorCore/DataTableProcessor.MapDataProcessor.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections;
3 | using System.IO;
4 |
5 | namespace DataTables.GeneratorCore;
6 |
7 | public sealed partial class DataTableProcessor
8 | {
9 | public class MapDataProcessor : DataProcessor
10 | {
11 | public override Type Type => typeof(Hashtable);
12 |
13 | public override bool IsSystem => false;
14 |
15 | public override string LanguageKeyword => m_LanguageKeyword;
16 |
17 | private readonly string m_KeyTypeStr;
18 | private readonly string m_ValueTypeStr;
19 | private readonly string m_LanguageKeyword;
20 |
21 | public MapDataProcessor()
22 | {
23 | m_KeyTypeStr = string.Empty;
24 | m_ValueTypeStr = string.Empty;
25 | m_LanguageKeyword = string.Empty;
26 | }
27 |
28 | public MapDataProcessor(DataProcessor keyProcessor, DataProcessor valueProcessor)
29 | {
30 | m_KeyTypeStr = keyProcessor.GetTypeStrings()[0];
31 | m_ValueTypeStr = valueProcessor.GetTypeStrings()[0];
32 | m_LanguageKeyword = $"Dictionary<{keyProcessor.LanguageKeyword}, {valueProcessor.LanguageKeyword}>";
33 | }
34 |
35 | public override string[] GetTypeStrings()
36 | {
37 | return new string[]
38 | {
39 | $"map<{m_KeyTypeStr},{m_ValueTypeStr}>",
40 | $"M<{m_KeyTypeStr},{m_ValueTypeStr}>",
41 | };
42 | }
43 |
44 | public override string GenerateTypeValue(string text) => throw new NotImplementedException();
45 |
46 | public override void WriteToStream(BinaryWriter binaryWriter, string value)
47 | {
48 | // 空的单元格时,自动补齐为空字母
49 | if (string.IsNullOrEmpty(value))
50 | {
51 | value = "{}";
52 | }
53 |
54 | var dict = JsonUtility.Deserialize(value)!;
55 |
56 | binaryWriter.Write7BitEncodedInt32(dict.Count);
57 | foreach (DictionaryEntry item in dict)
58 | {
59 | DataProcessorUtility.GetDataProcessor(m_KeyTypeStr).WriteToStream(binaryWriter, JsonUtility.Serialize(item.Key));
60 | DataProcessorUtility.GetDataProcessor(m_ValueTypeStr).WriteToStream(binaryWriter, JsonUtility.Serialize(item.Value));
61 | }
62 | }
63 |
64 | public override string GenerateDeserializeCode(GenerationContext context, string typeName, string propertyName, int depth)
65 | {
66 | return "{\n"
67 | + $"{Tabs(depth + 1)}{propertyName} = new {LanguageKeyword}();\n"
68 | + $"{Tabs(depth + 1)}var __{propertyName}_Count{depth + 1} = reader.Read7BitEncodedInt32();\n"
69 | + $"{Tabs(depth + 1)}for (int x{depth + 1} = 0; x{depth + 1} < __{propertyName}_Count{depth + 1}; x{depth + 1}++)\n"
70 | + $"{Tabs(depth + 1)}{{\n"
71 | + $"{Tabs(depth + 2)}{DataProcessorUtility.GetDataProcessor(m_KeyTypeStr).LanguageKeyword} key{depth + 1};\n"
72 | + $"{Tabs(depth + 2)}{DataProcessorUtility.GetDataProcessor(m_KeyTypeStr).GenerateDeserializeCode(context, m_KeyTypeStr, $"key{depth + 1}", depth + 2)}\n"
73 | + $"{Tabs(depth + 2)}{DataProcessorUtility.GetDataProcessor(m_ValueTypeStr).LanguageKeyword} value{depth + 1};\n"
74 | + $"{Tabs(depth + 2)}{DataProcessorUtility.GetDataProcessor(m_ValueTypeStr).GenerateDeserializeCode(context, m_ValueTypeStr, $"value{depth + 1}", depth + 2)}\n"
75 | + $"{Tabs(depth + 2)}{propertyName}.Add(key{depth + 1}, value{depth + 1});\n"
76 | + $"{Tabs(depth + 1)}}}\n"
77 | + $"{Tabs(depth)}}}";
78 | }
79 | }
80 | }
81 |
--------------------------------------------------------------------------------
/src/DataTables.GeneratorCore/DataTableProcessor.SByteProcessor.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.IO;
3 |
4 | namespace DataTables.GeneratorCore;
5 |
6 | public sealed partial class DataTableProcessor
7 | {
8 | private sealed class SByteProcessor : GenericDataProcessor
9 | {
10 | public override bool IsSystem
11 | {
12 | get
13 | {
14 | return true;
15 | }
16 | }
17 |
18 | public override string LanguageKeyword
19 | {
20 | get
21 | {
22 | return "sbyte";
23 | }
24 | }
25 |
26 | public override string[] GetTypeStrings()
27 | {
28 | return new string[]
29 | {
30 | "sbyte",
31 | "system.sbyte"
32 | };
33 | }
34 |
35 | public override sbyte Parse(string value)
36 | {
37 | return sbyte.Parse(value);
38 | }
39 |
40 | public override string GenerateTypeValue(string text) => throw new NotImplementedException();
41 |
42 | public override void WriteToStream(BinaryWriter binaryWriter, string value)
43 | {
44 | binaryWriter.Write(Parse(value));
45 | }
46 |
47 | public override string GenerateDeserializeCode(GenerationContext context, string typeName, string propertyName, int depth)
48 | {
49 | return $"{propertyName} = reader.ReadSByte();";
50 | }
51 | }
52 | }
53 |
--------------------------------------------------------------------------------
/src/DataTables.GeneratorCore/DataTableProcessor.SingleProcessor.cs:
--------------------------------------------------------------------------------
1 | using System.IO;
2 |
3 | namespace DataTables.GeneratorCore;
4 |
5 | public sealed partial class DataTableProcessor
6 | {
7 | private sealed class SingleProcessor : GenericDataProcessor
8 | {
9 | public override bool IsSystem
10 | {
11 | get
12 | {
13 | return true;
14 | }
15 | }
16 |
17 | public override string LanguageKeyword
18 | {
19 | get
20 | {
21 | return "float";
22 | }
23 | }
24 |
25 | public override string[] GetTypeStrings()
26 | {
27 | return new string[]
28 | {
29 | "float",
30 | "single",
31 | "system.single"
32 | };
33 | }
34 |
35 | public override float Parse(string value)
36 | {
37 | return string.IsNullOrEmpty(value) ? 0 : float.Parse(value);
38 | }
39 |
40 | public override string GenerateTypeValue(string text) => Parse(text).ToString() + 'f';
41 |
42 | public override void WriteToStream(BinaryWriter binaryWriter, string value)
43 | {
44 | binaryWriter.Write(Parse(value));
45 | }
46 |
47 | public override string GenerateDeserializeCode(GenerationContext context, string typeName, string propertyName, int depth)
48 | {
49 | return $"{propertyName} = reader.ReadSingle();";
50 | }
51 | }
52 | }
53 |
--------------------------------------------------------------------------------
/src/DataTables.GeneratorCore/DataTableProcessor.StringProcessor.cs:
--------------------------------------------------------------------------------
1 | using System.IO;
2 |
3 | namespace DataTables.GeneratorCore;
4 |
5 | public sealed partial class DataTableProcessor
6 | {
7 | private sealed class StringProcessor : GenericDataProcessor
8 | {
9 | public override bool IsSystem
10 | {
11 | get
12 | {
13 | return true;
14 | }
15 | }
16 |
17 | public override string LanguageKeyword
18 | {
19 | get
20 | {
21 | return "string";
22 | }
23 | }
24 |
25 | public override string[] GetTypeStrings()
26 | {
27 | return new string[]
28 | {
29 | "string",
30 | "system.string"
31 | };
32 | }
33 |
34 | public override string Parse(string value)
35 | {
36 | return string.IsNullOrEmpty(value) ? string.Empty : value;
37 | }
38 |
39 | public override string GenerateTypeValue(string text) => $"{Parse(text)}";
40 |
41 | public override void WriteToStream(BinaryWriter binaryWriter, string value)
42 | {
43 | binaryWriter.Write(Parse(value));
44 | }
45 |
46 | public override string GenerateDeserializeCode(GenerationContext context, string typeName, string propertyName, int depth)
47 | {
48 | return $"{propertyName} = reader.ReadString();";
49 | }
50 | }
51 | }
52 |
--------------------------------------------------------------------------------
/src/DataTables.GeneratorCore/DataTableProcessor.UInt16Processor.cs:
--------------------------------------------------------------------------------
1 | using System.IO;
2 |
3 | namespace DataTables.GeneratorCore;
4 |
5 | public sealed partial class DataTableProcessor
6 | {
7 | private sealed class UInt16Processor : GenericDataProcessor
8 | {
9 | public override bool IsSystem
10 | {
11 | get
12 | {
13 | return true;
14 | }
15 | }
16 |
17 | public override string LanguageKeyword
18 | {
19 | get
20 | {
21 | return "ushort";
22 | }
23 | }
24 |
25 | public override string[] GetTypeStrings()
26 | {
27 | return new string[]
28 | {
29 | "ushort",
30 | "uint16",
31 | "system.uint16"
32 | };
33 | }
34 |
35 | public override ushort Parse(string value)
36 | {
37 | if (string.IsNullOrEmpty(value))
38 | {
39 | return 0;
40 | }
41 |
42 | return JsonUtility.Deserialize(value);
43 | }
44 |
45 | public override string GenerateTypeValue(string text) => Parse(text).ToString();
46 |
47 | public override void WriteToStream(BinaryWriter binaryWriter, string value)
48 | {
49 | binaryWriter.Write(Parse(value));
50 | }
51 |
52 | public override string GenerateDeserializeCode(GenerationContext context, string typeName, string propertyName, int depth)
53 | {
54 | return $"{propertyName} = reader.ReadUInt16();";
55 | }
56 | }
57 | }
58 |
--------------------------------------------------------------------------------
/src/DataTables.GeneratorCore/DataTableProcessor.UInt32Processor.cs:
--------------------------------------------------------------------------------
1 | using System.IO;
2 |
3 | namespace DataTables.GeneratorCore;
4 |
5 | public sealed partial class DataTableProcessor
6 | {
7 | private sealed class UInt32Processor : GenericDataProcessor
8 | {
9 | public override bool IsSystem
10 | {
11 | get
12 | {
13 | return true;
14 | }
15 | }
16 |
17 | public override string LanguageKeyword
18 | {
19 | get
20 | {
21 | return "uint";
22 | }
23 | }
24 |
25 | public override string[] GetTypeStrings()
26 | {
27 | return new string[]
28 | {
29 | "uint",
30 | "uint32",
31 | "system.uint32"
32 | };
33 | }
34 |
35 | public override uint Parse(string value)
36 | {
37 | if (string.IsNullOrEmpty(value))
38 | {
39 | return 0;
40 | }
41 |
42 | return JsonUtility.Deserialize(value);
43 | }
44 |
45 | public override string GenerateTypeValue(string text) => Parse(text).ToString();
46 |
47 | public override void WriteToStream(BinaryWriter binaryWriter, string value)
48 | {
49 | binaryWriter.Write7BitEncodedUInt32(Parse(value));
50 | }
51 |
52 | public override string GenerateDeserializeCode(GenerationContext context, string typeName, string propertyName, int depth)
53 | {
54 | return $"{propertyName} = reader.Read7BitEncodedUInt32();";
55 | }
56 | }
57 | }
58 |
--------------------------------------------------------------------------------
/src/DataTables.GeneratorCore/DataTableProcessor.UInt64Processor.cs:
--------------------------------------------------------------------------------
1 | using System.IO;
2 |
3 | namespace DataTables.GeneratorCore;
4 |
5 | public sealed partial class DataTableProcessor
6 | {
7 | private sealed class UInt64Processor : GenericDataProcessor
8 | {
9 | public override bool IsSystem
10 | {
11 | get
12 | {
13 | return true;
14 | }
15 | }
16 |
17 | public override string LanguageKeyword
18 | {
19 | get
20 | {
21 | return "ulong";
22 | }
23 | }
24 |
25 | public override string[] GetTypeStrings()
26 | {
27 | return new string[]
28 | {
29 | "ulong",
30 | "uint64",
31 | "system.uint64"
32 | };
33 | }
34 |
35 | public override ulong Parse(string value)
36 | {
37 | if (string.IsNullOrEmpty(value))
38 | {
39 | return 0;
40 | }
41 |
42 | return JsonUtility.Deserialize(value);
43 | }
44 |
45 | public override string GenerateTypeValue(string text) => Parse(text).ToString();
46 |
47 | public override void WriteToStream(BinaryWriter binaryWriter, string value)
48 | {
49 | binaryWriter.Write7BitEncodedUInt64(Parse(value));
50 | }
51 |
52 | public override string GenerateDeserializeCode(GenerationContext context, string typeName, string propertyName, int depth)
53 | {
54 | return $"{propertyName} = reader.Read7BitEncodedUInt64();";
55 | }
56 | }
57 | }
58 |
--------------------------------------------------------------------------------
/src/DataTables.GeneratorCore/DataTables.GeneratorCore.csproj:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | latest
5 | false
6 | net8.0
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 | DataTableTemplate.tt
17 | True
18 | True
19 |
20 |
21 | True
22 | True
23 | DataMatrixTemplate.tt
24 |
25 |
26 | DataTableManagerExtensionTemplate.tt
27 | True
28 | True
29 |
30 |
31 |
32 |
33 |
34 | DataTableTemplate.cs
35 | TextTemplatingFilePreprocessor
36 |
37 |
38 | TextTemplatingFilePreprocessor
39 | DataMatrixTemplate.cs
40 |
41 |
42 | DataTableManagerExtensionTemplate.cs
43 | TextTemplatingFilePreprocessor
44 |
45 |
46 |
47 |
48 |
49 |
50 |
51 |
52 |
--------------------------------------------------------------------------------
/src/DataTables.GeneratorCore/ILogger.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Text;
3 |
4 | namespace DataTables.GeneratorCore;
5 |
6 | internal class ILogger : IDisposable
7 | {
8 | private readonly Action m_Logger;
9 | private readonly StringBuilder m_StringBuilder;
10 |
11 | private bool m_HasError;
12 |
13 | public ILogger(Action logger)
14 | {
15 | m_Logger = logger;
16 |
17 | m_StringBuilder = new();
18 | m_HasError = false;
19 | }
20 |
21 | public void Debug(string message)
22 | {
23 | m_StringBuilder.AppendLine(message);
24 | }
25 |
26 | public void Debug(string message, params object[] args)
27 | {
28 | m_StringBuilder.AppendFormat(message, args);
29 | m_StringBuilder.AppendLine();
30 | }
31 |
32 | public void Error(string message)
33 | {
34 | m_HasError = true;
35 | m_StringBuilder.AppendLine(message);
36 | }
37 |
38 | public void Error(string message, params object[] args)
39 | {
40 | m_HasError = true;
41 | m_StringBuilder.AppendFormat(message, args);
42 | m_StringBuilder.AppendLine();
43 | }
44 |
45 | public void Dispose()
46 | {
47 | if (m_HasError)
48 | Console.ForegroundColor = ConsoleColor.Red;
49 |
50 | m_Logger(m_StringBuilder.ToString());
51 |
52 | if (m_HasError)
53 | Console.ResetColor();
54 | }
55 | }
56 |
--------------------------------------------------------------------------------
/src/DataTables.GeneratorCore/JsonUtility.cs:
--------------------------------------------------------------------------------
1 | namespace DataTables.GeneratorCore;
2 |
3 | public static class JsonUtility
4 | {
5 | public static string Serialize(object? obj)
6 | {
7 | #if NET7_0_OR_GREATER
8 | return System.Text.Json.JsonSerializer.Serialize(obj);
9 | #else
10 | return Newtonsoft.Json.JsonConvert.SerializeObject(obj);
11 | #endif
12 | }
13 |
14 | public static T? Deserialize(string plain)
15 | {
16 | #if NET7_0_OR_GREATER
17 | return System.Text.Json.JsonSerializer.Deserialize(plain);
18 | #else
19 | var settings = new Newtonsoft.Json.JsonSerializerSettings { TypeNameHandling = Newtonsoft.Json.TypeNameHandling.None };
20 | return Newtonsoft.Json.JsonConvert.DeserializeObject(plain, settings);
21 | #endif
22 | }
23 | }
24 |
--------------------------------------------------------------------------------
/src/DataTables.GeneratorCore/Template.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Linq;
4 | using System.Text;
5 |
6 | namespace DataTables.GeneratorCore;
7 |
8 | public partial class DataTableManagerExtensionTemplate
9 | {
10 | public string Namespace { get; set; } = string.Empty;
11 |
12 | public string DataRowPrefix { get; set; } = string.Empty;
13 |
14 | public IOrderedEnumerable>>? DataTables { get; set; }
15 | }
16 |
17 | public partial class DataTableTemplate
18 | {
19 | public GenerationContext GenerationContext { get; private set; }
20 |
21 | public string Using => string.Join(Environment.NewLine, this.GenerationContext.UsingStrings);
22 |
23 | public string Namespace => GenerationContext.Namespace;
24 |
25 | public string ClassName => GenerationContext.DataRowClassName;
26 |
27 | public DataTableTemplate(GenerationContext context)
28 | {
29 | this.GenerationContext = context;
30 | }
31 |
32 | internal string GetPropertyTypeString(XField property)
33 | {
34 | return DataTableProcessor.GetLanguageKeyword(property);
35 | }
36 |
37 | internal string GetDeserializeMethodString(XField property)
38 | {
39 | return DataTableProcessor.GetDeserializeMethodString(GenerationContext, property);
40 | }
41 |
42 | internal string BuildSummary(string summary)
43 | {
44 | var text = System.Security.SecurityElement.Escape(summary.Trim());
45 | var lines = text.Split('\n');
46 | if (lines.Length == 0)
47 | {
48 | return string.Empty;
49 | }
50 | else if (lines.Length == 1)
51 | {
52 | return lines[0].Trim();
53 | }
54 | else
55 | {
56 | var sb = new StringBuilder();
57 | sb.AppendLine();
58 | sb.Append(" /// ");
59 | sb.AppendLine(lines[0].Trim());
60 | for (int i = 1; i < lines.Length; i++)
61 | {
62 | sb.Append(" /// ");
63 | sb.Append(lines[i].Trim());
64 | sb.AppendLine("");
65 | }
66 | sb.Append(" /// ");
67 | return sb.ToString();
68 | }
69 | }
70 | }
71 |
72 | public partial class DataMatrixTemplate
73 | {
74 | internal const string kKey1 = "_key1";
75 | internal const string kKey2 = "_key2";
76 | internal const string kValue = "_value";
77 |
78 | public GenerationContext GenerationContext { get; private set; }
79 |
80 | public DataMatrixTemplate(GenerationContext generationContext)
81 | {
82 | this.GenerationContext = generationContext;
83 | }
84 |
85 | internal string BuildTypeString(string fieldName) => DataTableProcessor.GetLanguageKeyword(this.GenerationContext.GetField(fieldName)!);
86 | internal string BuildTypeValueString(string fieldName, string fieldValueString) => DataTableProcessor.GetLanguageValue(this.GenerationContext.GetField(fieldName)!, fieldValueString);
87 | internal string BuildDeserializeMethodString(string fieldName) => DataTableProcessor.GetDeserializeMethodString(GenerationContext, this.GenerationContext.GetField(fieldName)!);
88 | }
89 |
--------------------------------------------------------------------------------
/src/DataTables.MSBuild.Tasks/DataTables.MSBuild.Tasks.csproj:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | netstandard2.0
5 | latest
6 |
7 |
8 | true
9 | tasks
10 |
11 | true
12 |
13 | DataTables.MSBuild.Tasks
14 | $(Version)
15 | MSBuild Tasks of DataTables Code Generator.
16 | https://github.com/PhonixGame/DataTables
17 | datatable, embedded, inmemory, unity
18 | true
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
29 |
30 |
31 |
32 |
33 |
34 |
35 |
36 |
37 |
38 |
42 |
43 |
44 | <_PackageFiles Include="$(OutDir)\**\*.dll" Exclude="$(OutDir)$(TargetFileName)">
45 | tasks\netstandard2.0\%(RecursiveDir)
46 | false
47 | Content
48 |
49 |
50 |
51 |
52 |
53 |
--------------------------------------------------------------------------------
/src/DataTables.MSBuild.Tasks/DataTablesGenerator.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using DataTables.GeneratorCore;
3 | using Microsoft.Build.Framework;
4 | using Microsoft.Build.Utilities;
5 |
6 | namespace DataTables.MSBuild.Tasks
7 | {
8 | public class DataTablesGenerator : Task
9 | {
10 | [Required]
11 | public string[] InputDirectories { get; set; } = Array.Empty();
12 | [Required]
13 | public string CodeOutputDirectory { get; set; } = string.Empty;
14 | [Required]
15 | public string DataOutputDirectory { get; set; } = string.Empty;
16 |
17 | public string UsingNamespace { get; set; } = string.Empty;
18 |
19 | public string PrefixClassName { get; set; } = string.Empty;
20 |
21 | public string ImportNamespaces { get; set; } = string.Empty;
22 |
23 | public string FilterColumnTags { get; set; } = string.Empty;
24 |
25 | public bool ForceOverwrite { get; set; }
26 |
27 | public override bool Execute()
28 | {
29 | try
30 | {
31 | new DataTableGenerator().GenerateFile(InputDirectories, CodeOutputDirectory, DataOutputDirectory, UsingNamespace, PrefixClassName, ImportNamespaces, FilterColumnTags, ForceOverwrite, x => this.Log.LogMessage(x));
32 | }
33 | catch (Exception ex)
34 | {
35 | this.Log.LogErrorFromException(ex, true);
36 | return false;
37 | }
38 | return true;
39 | }
40 | }
41 | }
42 |
--------------------------------------------------------------------------------
/src/DataTables.MSBuild.Tasks/build/DataTables.MSBuild.Tasks.props:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | <_DataTablesGeneratorTaskFolder>netstandard2.0
5 | <_DataTablesGeneratorTaskAssembly>$(MSBuildThisFileDirectory)..\tasks\$(_DataTablesGeneratorTaskFolder)\DataTables.MSBuild.Tasks.dll
6 |
7 |
8 |
9 |
10 |
--------------------------------------------------------------------------------
/src/DataTables.Unity/Assets/Plugins.meta:
--------------------------------------------------------------------------------
1 | fileFormatVersion: 2
2 | guid: ce17bade98a412e408e2f3a4b7c4a107
3 | folderAsset: yes
4 | DefaultImporter:
5 | externalObjects: {}
6 | userData:
7 | assetBundleName:
8 | assetBundleVariant:
9 |
--------------------------------------------------------------------------------
/src/DataTables.Unity/Assets/Plugins/System.Buffers.dll:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/ChronosGames/DataTables/b34314effdbdd4c89f39672c86548365af14fae8/src/DataTables.Unity/Assets/Plugins/System.Buffers.dll
--------------------------------------------------------------------------------
/src/DataTables.Unity/Assets/Plugins/System.Buffers.dll.meta:
--------------------------------------------------------------------------------
1 | fileFormatVersion: 2
2 | guid: cfed5f4adebd4cc6586d1ffea90646fc
3 | PluginImporter:
4 | externalObjects: {}
5 | serializedVersion: 2
6 | iconMap: {}
7 | executionOrder: {}
8 | defineConstraints: []
9 | isPreloaded: 0
10 | isOverridable: 0
11 | isExplicitlyReferenced: 0
12 | validateReferences: 1
13 | platformData:
14 | - first:
15 | Any:
16 | second:
17 | enabled: 1
18 | settings: {}
19 | - first:
20 | Editor: Editor
21 | second:
22 | enabled: 0
23 | settings:
24 | DefaultValueInitialized: true
25 | - first:
26 | Windows Store Apps: WindowsStoreApps
27 | second:
28 | enabled: 0
29 | settings:
30 | CPU: AnyCPU
31 | userData:
32 | assetBundleName:
33 | assetBundleVariant:
34 |
--------------------------------------------------------------------------------
/src/DataTables.Unity/Assets/Plugins/System.Memory.dll:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/ChronosGames/DataTables/b34314effdbdd4c89f39672c86548365af14fae8/src/DataTables.Unity/Assets/Plugins/System.Memory.dll
--------------------------------------------------------------------------------
/src/DataTables.Unity/Assets/Plugins/System.Memory.dll.meta:
--------------------------------------------------------------------------------
1 | fileFormatVersion: 2
2 | guid: 4b54c65c745fd3f8b9b5d1ee2b691920
3 | PluginImporter:
4 | externalObjects: {}
5 | serializedVersion: 2
6 | iconMap: {}
7 | executionOrder: {}
8 | defineConstraints: []
9 | isPreloaded: 0
10 | isOverridable: 0
11 | isExplicitlyReferenced: 0
12 | validateReferences: 1
13 | platformData:
14 | - first:
15 | Any:
16 | second:
17 | enabled: 1
18 | settings: {}
19 | - first:
20 | Editor: Editor
21 | second:
22 | enabled: 0
23 | settings:
24 | DefaultValueInitialized: true
25 | - first:
26 | Windows Store Apps: WindowsStoreApps
27 | second:
28 | enabled: 0
29 | settings:
30 | CPU: AnyCPU
31 | userData:
32 | assetBundleName:
33 | assetBundleVariant:
34 |
--------------------------------------------------------------------------------
/src/DataTables.Unity/Assets/Plugins/System.Runtime.CompilerServices.Unsafe.dll:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/ChronosGames/DataTables/b34314effdbdd4c89f39672c86548365af14fae8/src/DataTables.Unity/Assets/Plugins/System.Runtime.CompilerServices.Unsafe.dll
--------------------------------------------------------------------------------
/src/DataTables.Unity/Assets/Plugins/System.Runtime.CompilerServices.Unsafe.dll.meta:
--------------------------------------------------------------------------------
1 | fileFormatVersion: 2
2 | guid: 1b23775a59c7085cdb02341c16a19ef4
3 | PluginImporter:
4 | externalObjects: {}
5 | serializedVersion: 2
6 | iconMap: {}
7 | executionOrder: {}
8 | defineConstraints: []
9 | isPreloaded: 0
10 | isOverridable: 0
11 | isExplicitlyReferenced: 0
12 | validateReferences: 1
13 | platformData:
14 | - first:
15 | Any:
16 | second:
17 | enabled: 1
18 | settings: {}
19 | - first:
20 | Editor: Editor
21 | second:
22 | enabled: 0
23 | settings:
24 | DefaultValueInitialized: true
25 | - first:
26 | Windows Store Apps: WindowsStoreApps
27 | second:
28 | enabled: 0
29 | settings:
30 | CPU: AnyCPU
31 | userData:
32 | assetBundleName:
33 | assetBundleVariant:
34 |
--------------------------------------------------------------------------------
/src/DataTables.Unity/Assets/Plugins/System.Threading.Tasks.Extensions.dll:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/ChronosGames/DataTables/b34314effdbdd4c89f39672c86548365af14fae8/src/DataTables.Unity/Assets/Plugins/System.Threading.Tasks.Extensions.dll
--------------------------------------------------------------------------------
/src/DataTables.Unity/Assets/Plugins/System.Threading.Tasks.Extensions.dll.meta:
--------------------------------------------------------------------------------
1 | fileFormatVersion: 2
2 | guid: 79b471354b1f5b597bf692d41ee441a4
3 | PluginImporter:
4 | externalObjects: {}
5 | serializedVersion: 2
6 | iconMap: {}
7 | executionOrder: {}
8 | defineConstraints: []
9 | isPreloaded: 0
10 | isOverridable: 0
11 | isExplicitlyReferenced: 0
12 | validateReferences: 1
13 | platformData:
14 | - first:
15 | Any:
16 | second:
17 | enabled: 1
18 | settings: {}
19 | - first:
20 | Editor: Editor
21 | second:
22 | enabled: 0
23 | settings:
24 | DefaultValueInitialized: true
25 | - first:
26 | Windows Store Apps: WindowsStoreApps
27 | second:
28 | enabled: 0
29 | settings:
30 | CPU: AnyCPU
31 | userData:
32 | assetBundleName:
33 | assetBundleVariant:
34 |
--------------------------------------------------------------------------------
/src/DataTables.Unity/Assets/Scenes.meta:
--------------------------------------------------------------------------------
1 | fileFormatVersion: 2
2 | guid: 3e4672a57ce755a44805bc58b4ddea29
3 | folderAsset: yes
4 | DefaultImporter:
5 | externalObjects: {}
6 | userData:
7 | assetBundleName:
8 | assetBundleVariant:
9 |
--------------------------------------------------------------------------------
/src/DataTables.Unity/Assets/Scenes/SampleScene.unity.meta:
--------------------------------------------------------------------------------
1 | fileFormatVersion: 2
2 | guid: 2cda990e2423bbf4892e6590ba056729
3 | DefaultImporter:
4 | externalObjects: {}
5 | userData:
6 | assetBundleName:
7 | assetBundleVariant:
8 |
--------------------------------------------------------------------------------
/src/DataTables.Unity/Assets/Scripts.meta:
--------------------------------------------------------------------------------
1 | fileFormatVersion: 2
2 | guid: dfc2745c192a6764a8f038393ed2455c
3 | folderAsset: yes
4 | DefaultImporter:
5 | externalObjects: {}
6 | userData:
7 | assetBundleName:
8 | assetBundleVariant:
9 |
--------------------------------------------------------------------------------
/src/DataTables.Unity/Assets/Scripts/DataTables.meta:
--------------------------------------------------------------------------------
1 | fileFormatVersion: 2
2 | guid: a71ccf5d9c7abcf4c9026aa8056133a7
3 | folderAsset: yes
4 | DefaultImporter:
5 | externalObjects: {}
6 | userData:
7 | assetBundleName:
8 | assetBundleVariant:
9 |
--------------------------------------------------------------------------------
/src/DataTables.Unity/Assets/Scripts/DataTables/BinaryExtension.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.IO;
3 |
4 | namespace DataTables
5 | {
6 | public static class BinaryExtension
7 | {
8 | ///
9 | /// 从二进制流读取编码后的 32 位有符号整数。
10 | ///
11 | /// 要读取的二进制流。
12 | /// 读取的 32 位有符号整数。
13 | public static int Read7BitEncodedInt32(this BinaryReader binaryReader)
14 | {
15 | int value = 0;
16 | int shift = 0;
17 | byte b;
18 | do
19 | {
20 | if (shift >= 35)
21 | {
22 | throw new Exception("7 bit encoded int is invalid.");
23 | }
24 |
25 | b = binaryReader.ReadByte();
26 | value |= (b & 0x7f) << shift;
27 | shift += 7;
28 | } while ((b & 0x80) != 0);
29 |
30 | return value;
31 | }
32 |
33 | ///
34 | /// 向二进制流写入编码后的 32 位有符号整数。
35 | ///
36 | /// 要写入的二进制流。
37 | /// 要写入的 32 位有符号整数。
38 | public static void Write7BitEncodedInt32(this BinaryWriter binaryWriter, int value)
39 | {
40 | uint num = (uint)value;
41 | while (num >= 0x80)
42 | {
43 | binaryWriter.Write((byte)(num | 0x80));
44 | num >>= 7;
45 | }
46 |
47 | binaryWriter.Write((byte)num);
48 | }
49 |
50 | ///
51 | /// 从二进制流读取编码后的 32 位无符号整数。
52 | ///
53 | /// 要读取的二进制流。
54 | /// 读取的 32 位无符号整数。
55 | public static uint Read7BitEncodedUInt32(this BinaryReader binaryReader)
56 | {
57 | return (uint)Read7BitEncodedInt32(binaryReader);
58 | }
59 |
60 | ///
61 | /// 向二进制流写入编码后的 32 位无符号整数。
62 | ///
63 | /// 要写入的二进制流。
64 | /// 要写入的 32 位无符号整数。
65 | public static void Write7BitEncodedUInt32(this BinaryWriter binaryWriter, uint value)
66 | {
67 | Write7BitEncodedInt32(binaryWriter, (int)value);
68 | }
69 |
70 | ///
71 | /// 从二进制流读取编码后的 64 位有符号整数。
72 | ///
73 | /// 要读取的二进制流。
74 | /// 读取的 64 位有符号整数。
75 | public static long Read7BitEncodedInt64(this BinaryReader binaryReader)
76 | {
77 | long value = 0L;
78 | int shift = 0;
79 | byte b;
80 | do
81 | {
82 | if (shift >= 70)
83 | {
84 | throw new Exception("7 bit encoded int is invalid.");
85 | }
86 |
87 | b = binaryReader.ReadByte();
88 | value |= (b & 0x7fL) << shift;
89 | shift += 7;
90 | } while ((b & 0x80) != 0);
91 |
92 | return value;
93 | }
94 |
95 | ///
96 | /// 向二进制流写入编码后的 64 位有符号整数。
97 | ///
98 | /// 要写入的二进制流。
99 | /// 要写入的 64 位有符号整数。
100 | public static void Write7BitEncodedInt64(this BinaryWriter binaryWriter, long value)
101 | {
102 | ulong num = (ulong)value;
103 | while (num >= 0x80)
104 | {
105 | binaryWriter.Write((byte)(num | 0x80));
106 | num >>= 7;
107 | }
108 |
109 | binaryWriter.Write((byte)num);
110 | }
111 |
112 | ///
113 | /// 从二进制流读取编码后的 64 位无符号整数。
114 | ///
115 | /// 要读取的二进制流。
116 | /// 读取的 64 位无符号整数。
117 | public static ulong Read7BitEncodedUInt64(this BinaryReader binaryReader)
118 | {
119 | return (ulong)Read7BitEncodedInt64(binaryReader);
120 | }
121 |
122 | ///
123 | /// 向二进制流写入编码后的 64 位无符号整数。
124 | ///
125 | /// 要写入的二进制流。
126 | /// 要写入的 64 位无符号整数。
127 | public static void Write7BitEncodedUInt64(this BinaryWriter binaryWriter, ulong value)
128 | {
129 | Write7BitEncodedInt64(binaryWriter, (long)value);
130 | }
131 |
132 | public static T? ReadJson(this BinaryReader binaryReader)
133 | {
134 | var plain = binaryReader.ReadString();
135 | if (string.IsNullOrEmpty(plain))
136 | {
137 | return default;
138 | }
139 |
140 | #if NET7_0_OR_GREATER
141 | return System.Text.Json.JsonSerializer.Deserialize(plain);
142 | #elif UNITY_EDITOR
143 | return UnityEngine.JsonUtility.FromJson(plain);
144 | #else
145 | throw new NotImplementedException();
146 | #endif
147 | }
148 | }
149 | }
150 |
--------------------------------------------------------------------------------
/src/DataTables.Unity/Assets/Scripts/DataTables/BinaryExtension.cs.meta:
--------------------------------------------------------------------------------
1 | fileFormatVersion: 2
2 | guid: ab574d4c44ee80144910a3fe6a39a116
3 | MonoImporter:
4 | externalObjects: {}
5 | serializedVersion: 2
6 | defaultReferences: []
7 | executionOrder: 0
8 | icon: {instanceID: 0}
9 | userData:
10 | assetBundleName:
11 | assetBundleVariant:
12 |
--------------------------------------------------------------------------------
/src/DataTables.Unity/Assets/Scripts/DataTables/DataMatrixBase.cs.meta:
--------------------------------------------------------------------------------
1 | fileFormatVersion: 2
2 | guid: d219c1298634167428a55220bec02e70
3 | MonoImporter:
4 | externalObjects: {}
5 | serializedVersion: 2
6 | defaultReferences: []
7 | executionOrder: 0
8 | icon: {instanceID: 0}
9 | userData:
10 | assetBundleName:
11 | assetBundleVariant:
12 |
--------------------------------------------------------------------------------
/src/DataTables.Unity/Assets/Scripts/DataTables/DataRowBase.cs:
--------------------------------------------------------------------------------
1 | using System.IO;
2 |
3 | namespace DataTables
4 | {
5 | public abstract class DataRowBase : IDataRow
6 | {
7 | public abstract bool Deserialize(BinaryReader binaryReader);
8 | }
9 | }
10 |
--------------------------------------------------------------------------------
/src/DataTables.Unity/Assets/Scripts/DataTables/DataRowBase.cs.meta:
--------------------------------------------------------------------------------
1 | fileFormatVersion: 2
2 | guid: 1c913d1557f4ada40a48d7e276a159a6
3 | MonoImporter:
4 | externalObjects: {}
5 | serializedVersion: 2
6 | defaultReferences: []
7 | executionOrder: 0
8 | icon: {instanceID: 0}
9 | userData:
10 | assetBundleName:
11 | assetBundleVariant:
12 |
--------------------------------------------------------------------------------
/src/DataTables.Unity/Assets/Scripts/DataTables/DataTable.cs.meta:
--------------------------------------------------------------------------------
1 | fileFormatVersion: 2
2 | guid: 2d8365351b71b914c89da87ecc9b6f04
3 | MonoImporter:
4 | externalObjects: {}
5 | serializedVersion: 2
6 | defaultReferences: []
7 | executionOrder: 0
8 | icon: {instanceID: 0}
9 | userData:
10 | assetBundleName:
11 | assetBundleVariant:
12 |
--------------------------------------------------------------------------------
/src/DataTables.Unity/Assets/Scripts/DataTables/DataTableBase.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.IO;
3 |
4 | namespace DataTables
5 | {
6 | public abstract class DataTableBase
7 | {
8 | private readonly string m_Name;
9 |
10 | ///
11 | /// 初始化数据表基类的新实例。
12 | ///
13 | /// 数据表名称。
14 | public DataTableBase(string name)
15 | {
16 | m_Name = name;
17 | }
18 |
19 | ///
20 | /// 获取数据表名称。
21 | ///
22 | public string Name => m_Name;
23 |
24 | ///
25 | /// 获取数据表完整名称。
26 | ///
27 | public string FullName => Type.ToString();
28 |
29 | ///
30 | /// 获取数据表行的类型。
31 | ///
32 | public abstract Type Type
33 | {
34 | get;
35 | }
36 |
37 | ///
38 | /// 获取数据表行数。
39 | ///
40 | public abstract int Count
41 | {
42 | get;
43 | }
44 |
45 | ///
46 | /// 增加数据表行。
47 | ///
48 | /// 将要增加的数据表行的索引值。
49 | /// 要解析的数据表行二进制流。
50 | /// 是否增加数据表行成功。
51 | public abstract bool ParseDataRow(int index, BinaryReader reader);
52 |
53 | ///
54 | /// 配置表加载完成
55 | /// 可重载该方法以便自定义一些额外的操作
56 | ///
57 | public virtual void OnLoadCompleted() { }
58 |
59 | ///
60 | /// 清空所有数据表行。
61 | ///
62 | public virtual void RemoveAllDataRows()
63 | { }
64 |
65 | ///
66 | /// 关闭并清理数据表。
67 | ///
68 | internal virtual void Shutdown()
69 | { }
70 | }
71 | }
72 |
--------------------------------------------------------------------------------
/src/DataTables.Unity/Assets/Scripts/DataTables/DataTableBase.cs.meta:
--------------------------------------------------------------------------------
1 | fileFormatVersion: 2
2 | guid: 3b00d8c84f7f6084cba186bf89e635f7
3 | MonoImporter:
4 | externalObjects: {}
5 | serializedVersion: 2
6 | defaultReferences: []
7 | executionOrder: 0
8 | icon: {instanceID: 0}
9 | userData:
10 | assetBundleName:
11 | assetBundleVariant:
12 |
--------------------------------------------------------------------------------
/src/DataTables.Unity/Assets/Scripts/DataTables/DataTableManager.cs.meta:
--------------------------------------------------------------------------------
1 | fileFormatVersion: 2
2 | guid: 18516a9b905d16a4c8d684764ac05df5
3 | MonoImporter:
4 | externalObjects: {}
5 | serializedVersion: 2
6 | defaultReferences: []
7 | executionOrder: 0
8 | icon: {instanceID: 0}
9 | userData:
10 | assetBundleName:
11 | assetBundleVariant:
12 |
--------------------------------------------------------------------------------
/src/DataTables.Unity/Assets/Scripts/DataTables/DataTables.asmdef:
--------------------------------------------------------------------------------
1 | {
2 | "name": "DataTables",
3 | "references": [],
4 | "optionalUnityReferences": [],
5 | "includePlatforms": [],
6 | "excludePlatforms": [],
7 | "allowUnsafeCode": false,
8 | "overrideReferences": false,
9 | "precompiledReferences": [
10 | "System.Memory.dll",
11 | "System.Buffers.dll",
12 | "System.Runtime.CompilerServices.Unsafe.dll"
13 | ],
14 | "autoReferenced": true,
15 | "defineConstraints": []
16 | }
--------------------------------------------------------------------------------
/src/DataTables.Unity/Assets/Scripts/DataTables/DataTables.asmdef.meta:
--------------------------------------------------------------------------------
1 | fileFormatVersion: 2
2 | guid: 0632cc6b22db61d41898dfef78dc32f5
3 | AssemblyDefinitionImporter:
4 | externalObjects: {}
5 | userData:
6 | assetBundleName:
7 | assetBundleVariant:
8 |
--------------------------------------------------------------------------------
/src/DataTables.Unity/Assets/Scripts/DataTables/DefaultDataTableHelper.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.IO;
3 |
4 | namespace DataTables
5 | {
6 | public class DefaultDataTableHelper : IDataTableHelper
7 | {
8 | private readonly string m_DataDir;
9 |
10 | public DefaultDataTableHelper(string dataDir)
11 | {
12 | m_DataDir = dataDir;
13 | }
14 |
15 | public void Read(string fileName, Action callback)
16 | {
17 | var raw = File.ReadAllBytes(Path.Combine(m_DataDir, fileName) + ".bytes");
18 | callback(raw);
19 | }
20 | }
21 | }
22 |
--------------------------------------------------------------------------------
/src/DataTables.Unity/Assets/Scripts/DataTables/DefaultDataTableHelper.cs.meta:
--------------------------------------------------------------------------------
1 | fileFormatVersion: 2
2 | guid: 1022563c5a5d3b44492004ed46fd53f8
3 | MonoImporter:
4 | externalObjects: {}
5 | serializedVersion: 2
6 | defaultReferences: []
7 | executionOrder: 0
8 | icon: {instanceID: 0}
9 | userData:
10 | assetBundleName:
11 | assetBundleVariant:
12 |
--------------------------------------------------------------------------------
/src/DataTables.Unity/Assets/Scripts/DataTables/IDataRow.cs:
--------------------------------------------------------------------------------
1 | using System.IO;
2 |
3 | namespace DataTables
4 | {
5 | ///
6 | /// 数据表行接口。
7 | ///
8 | public interface IDataRow
9 | {
10 | ///
11 | /// 解锁数据表行
12 | ///
13 | /// 要解析的数据表行二进制流
14 | /// 是否解析数据表行成功
15 | bool Deserialize(BinaryReader reader);
16 | }
17 | }
18 |
--------------------------------------------------------------------------------
/src/DataTables.Unity/Assets/Scripts/DataTables/IDataRow.cs.meta:
--------------------------------------------------------------------------------
1 | fileFormatVersion: 2
2 | guid: 76b9c52a1c65b824caf7fd67dbaa3c27
3 | MonoImporter:
4 | externalObjects: {}
5 | serializedVersion: 2
6 | defaultReferences: []
7 | executionOrder: 0
8 | icon: {instanceID: 0}
9 | userData:
10 | assetBundleName:
11 | assetBundleVariant:
12 |
--------------------------------------------------------------------------------
/src/DataTables.Unity/Assets/Scripts/DataTables/IDataTable.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Linq;
4 |
5 | namespace DataTables
6 | {
7 | public interface IDataTable : IEnumerable where T : IDataRow
8 | {
9 | ///
10 | /// 获取数据表名称。
11 | ///
12 | string Name
13 | {
14 | get;
15 | }
16 |
17 | ///
18 | /// 获取数据表完整名称。
19 | ///
20 | string FullName
21 | {
22 | get;
23 | }
24 |
25 | ///
26 | /// 获取数据表行的类型。
27 | ///
28 | Type Type
29 | {
30 | get;
31 | }
32 |
33 | ///
34 | /// 获取数据表行数。
35 | ///
36 | int Count
37 | {
38 | get;
39 | }
40 |
41 | ///
42 | /// 检查是否存在数据表行。
43 | ///
44 | /// 要检查的条件。
45 | /// 是否存在数据表行。
46 | bool HasDataRow(Predicate condition);
47 |
48 | ///
49 | /// 获取符合条件的数据表行。
50 | ///
51 | /// 要检查的条件。
52 | /// 符合条件的数据表行。
53 | /// 当存在多个符合条件的数据表行时,仅返回第一个符合条件的数据表行。
54 | T? GetDataRow(Predicate condition);
55 |
56 | ///
57 | /// 获取符合条件的数据表行。
58 | ///
59 | /// 要检查的条件。
60 | /// 符合条件的数据表行。
61 | IEnumerable GetDataRows(Predicate condition);
62 |
63 | ///
64 | /// 获取符合条件的数据表行。
65 | ///
66 | /// 要检查的条件。
67 | /// 符合条件的数据表行。
68 | void GetDataRows(Predicate condition, List results);
69 |
70 | ///
71 | /// 获取排序后的数据表行。
72 | ///
73 | /// 要排序的条件。
74 | /// 排序后的数据表行。
75 | T[] GetDataRows(Comparison comparison);
76 |
77 | ///
78 | /// 获取排序后的数据表行。
79 | ///
80 | /// 要排序的条件。
81 | /// 排序后的数据表行。
82 | void GetDataRows(Comparison comparison, List results);
83 |
84 | ///
85 | /// 获取排序后的符合条件的数据表行。
86 | ///
87 | /// 要检查的条件。
88 | /// 要排序的条件。
89 | /// 排序后的符合条件的数据表行。
90 | IOrderedEnumerable GetDataRows(Predicate condition, Comparison comparison);
91 |
92 | ///
93 | /// 获取排序后的符合条件的数据表行。
94 | ///
95 | /// 要检查的条件。
96 | /// 要排序的条件。
97 | /// 排序后的符合条件的数据表行。
98 | void GetDataRows(Predicate condition, Comparison comparison, List results);
99 |
100 | ///
101 | /// 获取所有数据表行。
102 | ///
103 | /// 所有数据表行。
104 | T[] GetAllDataRows();
105 |
106 | ///
107 | /// 获取所有数据表行。
108 | ///
109 | /// 所有数据表行。
110 | void GetAllDataRows(List results);
111 |
112 | ///
113 | /// 清空所有数据表行。
114 | ///
115 | void RemoveAllDataRows();
116 | }
117 | }
118 |
--------------------------------------------------------------------------------
/src/DataTables.Unity/Assets/Scripts/DataTables/IDataTable.cs.meta:
--------------------------------------------------------------------------------
1 | fileFormatVersion: 2
2 | guid: 578d58c3a3efc3b4a8af4bf7fbde3a56
3 | MonoImporter:
4 | externalObjects: {}
5 | serializedVersion: 2
6 | defaultReferences: []
7 | executionOrder: 0
8 | icon: {instanceID: 0}
9 | userData:
10 | assetBundleName:
11 | assetBundleVariant:
12 |
--------------------------------------------------------------------------------
/src/DataTables.Unity/Assets/Scripts/DataTables/IDataTableHelper.cs:
--------------------------------------------------------------------------------
1 | using System;
2 |
3 | namespace DataTables
4 | {
5 | ///
6 | /// 数据表辅助器接口。
7 | ///
8 | public interface IDataTableHelper
9 | {
10 | void Read(string fileName, Action callback);
11 | }
12 | }
13 |
--------------------------------------------------------------------------------
/src/DataTables.Unity/Assets/Scripts/DataTables/IDataTableHelper.cs.meta:
--------------------------------------------------------------------------------
1 | fileFormatVersion: 2
2 | guid: e3c8d2a5bea16c741a89870959cb162a
3 | MonoImporter:
4 | externalObjects: {}
5 | serializedVersion: 2
6 | defaultReferences: []
7 | executionOrder: 0
8 | icon: {instanceID: 0}
9 | userData:
10 | assetBundleName:
11 | assetBundleVariant:
12 |
--------------------------------------------------------------------------------
/src/DataTables.Unity/Assets/Scripts/DataTables/IDataTableManager.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 |
4 | namespace DataTables
5 | {
6 | ///
7 | /// 数据表管理器接口。
8 | ///
9 | public interface IDataTableManager
10 | {
11 | ///
12 | /// 获取数据表数量。
13 | ///
14 | int Count
15 | {
16 | get;
17 | }
18 |
19 | ///
20 | /// 设置数据表辅助器。
21 | ///
22 | /// 数据表辅助器。
23 | void SetDataTableHelper(IDataTableHelper dataTableHelper);
24 |
25 | ///
26 | /// 是否存在数据表。
27 | ///
28 | /// 数据表的类型。
29 | /// 数据表名称。
30 | /// 是否存在数据表。
31 | bool HasDataTable(Type dataTableType, string name = "");
32 |
33 | ///
34 | /// 是否存在数据表。
35 | ///
36 | /// 数据表的类型。
37 | /// 数据表名称。
38 | /// 是否存在数据表。
39 | bool HasDataTable(string name = "") where T : DataTableBase;
40 |
41 | ///
42 | /// 获取数据表。
43 | ///
44 | /// 数据表的类型。
45 | /// 数据表名称。
46 | /// 要获取的数据表。
47 | T? GetDataTable(string name = "") where T : DataTableBase;
48 |
49 | ///
50 | /// 获取数据表。
51 | ///
52 | /// 数据表的类型。
53 | /// 数据表名称。
54 | /// 要获取的数据表。
55 | DataTableBase? GetDataTable(Type dataTableType, string name = "");
56 |
57 | ///
58 | /// 获取所有数据表。
59 | ///
60 | /// 所有数据表。
61 | DataTableBase[] GetAllDataTables();
62 |
63 | ///
64 | /// 获取所有数据表。
65 | ///
66 | /// 所有数据表。
67 | void GetAllDataTables(List results);
68 |
69 | ///
70 | /// 创建数据表。
71 | ///
72 | /// 数据表的类型。
73 | /// 数据表加载完成时回调。
74 | void CreateDataTable(Action onCompleted) where T : DataTableBase;
75 |
76 | ///
77 | /// 创建数据表。
78 | ///
79 | /// 数据表的类型。
80 | /// 数据表加载完成时回调。
81 | void CreateDataTable(Type dataTableType, Action onCompleted);
82 |
83 | ///
84 | /// 创建数据表。
85 | ///
86 | /// 数据表的类型。
87 | /// 数据表名称。
88 | /// 数据表加载完成时回调。
89 | void CreateDataTable(string name, Action onCompleted) where T : DataTableBase;
90 |
91 | ///
92 | /// 创建数据表。
93 | ///
94 | /// 数据表的类型。
95 | /// 数据表名称。
96 | /// 数据表加载完成时回调。
97 | void CreateDataTable(Type dataTableType, string name, Action onCompleted);
98 |
99 | ///
100 | /// 销毁数据表。
101 | ///
102 | /// 要销毁的数据表。
103 | /// 是否销毁数据表成功。
104 | bool DestroyDataTable(DataTableBase dataTable);
105 |
106 | ///
107 | /// 销毁数据表。
108 | ///
109 | /// 数据表的类型。
110 | /// 数据表名称。
111 | /// 是否销毁数据表成功。
112 | bool DestroyDataTable(string name = "") where T : DataTableBase;
113 |
114 | ///
115 | /// 销毁数据表。
116 | ///
117 | /// 数据表的类型。
118 | /// 数据表名称。
119 | /// 是否销毁数据表成功。
120 | bool DestroyDataTable(Type dataTableType, string name = "");
121 | }
122 | }
123 |
--------------------------------------------------------------------------------
/src/DataTables.Unity/Assets/Scripts/DataTables/IDataTableManager.cs.meta:
--------------------------------------------------------------------------------
1 | fileFormatVersion: 2
2 | guid: 42f92f35cf444734eb116281227b56b0
3 | MonoImporter:
4 | externalObjects: {}
5 | serializedVersion: 2
6 | defaultReferences: []
7 | executionOrder: 0
8 | icon: {instanceID: 0}
9 | userData:
10 | assetBundleName:
11 | assetBundleVariant:
12 |
--------------------------------------------------------------------------------
/src/DataTables.Unity/Assets/Scripts/DataTables/TypeNamePair.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Runtime.CompilerServices;
3 | using System.Runtime.InteropServices;
4 |
5 | namespace DataTables
6 | {
7 | ///
8 | /// 类型和名称的组合值。
9 | ///
10 | [StructLayout(LayoutKind.Auto)]
11 | internal readonly struct TypeNamePair : IEquatable
12 | {
13 | private readonly Type m_Type;
14 | private readonly string m_Name;
15 |
16 | ///
17 | /// 初始化类型和名称的组合值的新实例。
18 | ///
19 | /// 类型。
20 | public TypeNamePair(Type type) : this(type, string.Empty)
21 | {
22 | }
23 |
24 | ///
25 | /// 初始化类型和名称的组合值的新实例。
26 | ///
27 | /// 类型。
28 | /// 名称。
29 | public TypeNamePair(Type type, string name)
30 | {
31 | if (type == null)
32 | {
33 | throw new Exception("Type is invalid.");
34 | }
35 |
36 | m_Type = type;
37 | m_Name = name ?? string.Empty;
38 | }
39 |
40 | ///
41 | /// 获取类型。
42 | ///
43 | public Type Type
44 | {
45 | get
46 | {
47 | return m_Type;
48 | }
49 | }
50 |
51 | ///
52 | /// 获取名称。
53 | ///
54 | public string Name
55 | {
56 | get
57 | {
58 | return m_Name;
59 | }
60 | }
61 |
62 | ///
63 | /// 获取类型和名称的组合值字符串。
64 | ///
65 | /// 类型和名称的组合值字符串。
66 | public override string ToString()
67 | {
68 | if (m_Type == null)
69 | {
70 | throw new Exception("Type is invalid.");
71 | }
72 |
73 | string typeName = m_Type.FullName!;
74 | return string.IsNullOrEmpty(m_Name) ? typeName : string.Format("{0}.{1}", typeName, m_Name);
75 | }
76 |
77 | ///
78 | /// 获取对象的哈希值。
79 | ///
80 | /// 对象的哈希值。
81 | [MethodImpl(MethodImplOptions.AggressiveInlining)]
82 | public override int GetHashCode()
83 | {
84 | return HashCode.Combine(m_Type, m_Name);
85 | }
86 |
87 | ///
88 | /// 比较对象是否与自身相等。
89 | ///
90 | /// 要比较的对象。
91 | /// 被比较的对象是否与自身相等。
92 | [MethodImpl(MethodImplOptions.AggressiveInlining)]
93 | public override bool Equals(object? obj)
94 | {
95 | return obj is TypeNamePair && Equals((TypeNamePair)obj);
96 | }
97 |
98 | ///
99 | /// 比较对象是否与自身相等。
100 | ///
101 | /// 要比较的对象。
102 | /// 被比较的对象是否与自身相等。
103 | [MethodImpl(MethodImplOptions.AggressiveInlining)]
104 | public bool Equals(TypeNamePair value)
105 | {
106 | return m_Type == value.m_Type && string.CompareOrdinal(m_Name, value.m_Name) == 0;
107 | }
108 |
109 | ///
110 | /// 判断两个对象是否相等。
111 | ///
112 | /// 值 a。
113 | /// 值 b。
114 | /// 两个对象是否相等。
115 | [MethodImpl(MethodImplOptions.AggressiveInlining)]
116 | public static bool operator ==(TypeNamePair a, TypeNamePair b)
117 | {
118 | return a.Equals(b);
119 | }
120 |
121 | ///
122 | /// 判断两个对象是否不相等。
123 | ///
124 | /// 值 a。
125 | /// 值 b。
126 | /// 两个对象是否不相等。
127 | [MethodImpl(MethodImplOptions.AggressiveInlining)]
128 | public static bool operator !=(TypeNamePair a, TypeNamePair b)
129 | {
130 | return !a.Equals(b);
131 | }
132 | }
133 | }
134 |
--------------------------------------------------------------------------------
/src/DataTables.Unity/Assets/Scripts/DataTables/TypeNamePair.cs.meta:
--------------------------------------------------------------------------------
1 | fileFormatVersion: 2
2 | guid: dcc67d2b224f14b43bfa7cb3363cbb6f
3 | MonoImporter:
4 | externalObjects: {}
5 | serializedVersion: 2
6 | defaultReferences: []
7 | executionOrder: 0
8 | icon: {instanceID: 0}
9 | userData:
10 | assetBundleName:
11 | assetBundleVariant:
12 |
--------------------------------------------------------------------------------
/src/DataTables.Unity/Assets/Scripts/DataTables/package.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "game.phonix.datatables",
3 | "displayName": "DataTables",
4 | "version": "0.12.17",
5 | "unity": "2022.3",
6 | "description": "Configuration tables for .NET Core and Unity.",
7 | "keywords": [
8 | "datatables",
9 | "excel",
10 | "tool"
11 | ],
12 | "license": "MIT",
13 | "category": "tool",
14 | "dependencies": {}
15 | }
16 |
--------------------------------------------------------------------------------
/src/DataTables.Unity/Assets/Scripts/DataTables/package.json.meta:
--------------------------------------------------------------------------------
1 | fileFormatVersion: 2
2 | guid: cc408136425ca7549b079eb65c6b0deb
3 | TextScriptImporter:
4 | externalObjects: {}
5 | userData:
6 | assetBundleName:
7 | assetBundleVariant:
8 |
--------------------------------------------------------------------------------
/src/DataTables.Unity/Assets/Scripts/Editor.meta:
--------------------------------------------------------------------------------
1 | fileFormatVersion: 2
2 | guid: c46767cc8d723d649ab6aaaeb1d72c12
3 | folderAsset: yes
4 | DefaultImporter:
5 | externalObjects: {}
6 | userData:
7 | assetBundleName:
8 | assetBundleVariant:
9 |
--------------------------------------------------------------------------------
/src/DataTables.Unity/Assets/Scripts/Editor/PackageExporter.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.IO;
3 | using System.Linq;
4 | using UnityEditor;
5 | using UnityEngine;
6 |
7 | public static class PackageExporter
8 | {
9 | [MenuItem("Tools/Export Unitypackage")]
10 | public static void Export()
11 | {
12 | var root = "Scripts/DataTables";
13 | var version = GetVersion(root);
14 |
15 | var fileName = string.IsNullOrEmpty(version) ? "DataTables.Unity.unitypackage" : $"DataTables.Unity.{version}.unitypackage";
16 | var exportPath = "./" + fileName;
17 |
18 | var path = Path.Combine(Application.dataPath, root);
19 | var assets = Directory.EnumerateFiles(path, "*", SearchOption.AllDirectories)
20 | .Where(x => Path.GetExtension(x) == ".cs" || Path.GetExtension(x) == ".asmdef" || Path.GetExtension(x) == ".json" || Path.GetExtension(x) == ".meta")
21 | .Select(x => "Assets" + x.Replace(Application.dataPath, "").Replace(@"\", "/"))
22 | .ToArray();
23 |
24 | UnityEngine.Debug.Log("Export below files" + Environment.NewLine + string.Join(Environment.NewLine, assets));
25 |
26 | AssetDatabase.ExportPackage(
27 | assets,
28 | exportPath,
29 | ExportPackageOptions.Default);
30 |
31 | UnityEngine.Debug.Log("Export complete: " + Path.GetFullPath(exportPath));
32 | }
33 |
34 | static string GetVersion(string root)
35 | {
36 | var version = Environment.GetEnvironmentVariable("UNITY_PACKAGE_VERSION");
37 | var versionJson = Path.Combine(Application.dataPath, root, "package.json");
38 |
39 | if (File.Exists(versionJson))
40 | {
41 | var v = JsonUtility.FromJson(File.ReadAllText(versionJson));
42 |
43 | if (!string.IsNullOrEmpty(version))
44 | {
45 | if (v.version != version)
46 | {
47 | var msg = $"package.json and env version are mismatched. UNITY_PACKAGE_VERSION:{version}, package.json:{v.version}";
48 |
49 | if (Application.isBatchMode)
50 | {
51 | Console.WriteLine(msg);
52 | Application.Quit(1);
53 | }
54 |
55 | throw new Exception("package.json and env version are mismatched.");
56 | }
57 | }
58 |
59 | version = v.version;
60 | }
61 |
62 | return version;
63 | }
64 |
65 | public class Version
66 | {
67 | public string version;
68 | }
69 | }
--------------------------------------------------------------------------------
/src/DataTables.Unity/Assets/Scripts/Editor/PackageExporter.cs.meta:
--------------------------------------------------------------------------------
1 | fileFormatVersion: 2
2 | guid: 0104ef67be3b9ca498ff698ad4e0bd71
3 | MonoImporter:
4 | externalObjects: {}
5 | serializedVersion: 2
6 | defaultReferences: []
7 | executionOrder: 0
8 | icon: {instanceID: 0}
9 | userData:
10 | assetBundleName:
11 | assetBundleVariant:
12 |
--------------------------------------------------------------------------------
/src/DataTables.Unity/Assets/Tests.meta:
--------------------------------------------------------------------------------
1 | fileFormatVersion: 2
2 | guid: 045b54ace96b9764bae81f0adca442d0
3 | folderAsset: yes
4 | DefaultImporter:
5 | externalObjects: {}
6 | userData:
7 | assetBundleName:
8 | assetBundleVariant:
9 |
--------------------------------------------------------------------------------
/src/DataTables.Unity/Assets/Tests/DataTables.Tests.asmdef:
--------------------------------------------------------------------------------
1 | {
2 | "name": "DataTables.Tests",
3 | "references": [
4 | "DataTables"
5 | ],
6 | "optionalUnityReferences": [],
7 | "includePlatforms": [],
8 | "excludePlatforms": [],
9 | "allowUnsafeCode": false,
10 | "overrideReferences": false,
11 | "precompiledReferences": [],
12 | "autoReferenced": true,
13 | "defineConstraints": []
14 | }
--------------------------------------------------------------------------------
/src/DataTables.Unity/Assets/Tests/DataTables.Tests.asmdef.meta:
--------------------------------------------------------------------------------
1 | fileFormatVersion: 2
2 | guid: b8b409d5c4a9b0d48a2d16252f84b2f1
3 | AssemblyDefinitionImporter:
4 | externalObjects: {}
5 | userData:
6 | assetBundleName:
7 | assetBundleVariant:
8 |
--------------------------------------------------------------------------------
/src/DataTables.Unity/Assets/Tests/IssueTest.cs:
--------------------------------------------------------------------------------
1 | //using FluentAssertions;
2 | //using DataTables.Tests.TestStructures;
3 | //using System;
4 | //using System.Collections.Generic;
5 | //using System.Linq;
6 | //using System.Text;
7 | //using Xunit;
8 |
9 | //namespace DataTables.Tests
10 | //{
11 | // public class IssueTest
12 | // {
13 | // //[Fact]
14 | // //public void Issue49()
15 | // //{
16 | // // var builder = new DatabaseBuilder().Append(new[]
17 | // // {
18 | // // new PersonModel { FirstName = "realname", LastName="reallast" },
19 | // // new PersonModel { FirstName = "fakefirst", LastName="fakelast" },
20 | // // });
21 |
22 | // // var data = builder.Build();
23 | // // var database = new MemoryDatabase(data);
24 |
25 | // // var entries = database.PersonModelTable.FindClosestByFirstNameAndLastName(("real", "real"), false);
26 | // // var firstEntry = entries.FirstOrDefault();
27 |
28 | // // var firstIs = firstEntry.FirstName;
29 |
30 | // //}
31 |
32 | // Sample[] CreateData()
33 | // {
34 | // // Id = Unique, PK
35 | // // FirstName + LastName = Unique
36 | // var data = new[]
37 | // {
38 | // new Sample { Id = 5, Age = 19, FirstName = "aaa", LastName = "foo" },
39 | // new Sample { Id = 6, Age = 29, FirstName = "bbb", LastName = "foo" },
40 | // new Sample { Id = 7, Age = 39, FirstName = "ccc", LastName = "foo" },
41 | // new Sample { Id = 8, Age = 49, FirstName = "ddd", LastName = "foo" },
42 | // new Sample { Id = 1, Age = 59, FirstName = "eee", LastName = "foo" },
43 | // new Sample { Id = 2, Age = 89, FirstName = "aaa", LastName = "bar" },
44 | // new Sample { Id = 3, Age = 79, FirstName = "be", LastName = "de" },
45 | // new Sample { Id = 4, Age = 89, FirstName = "aaa", LastName = "tako" },
46 | // new Sample { Id = 9, Age = 99, FirstName = "aaa", LastName = "ika" },
47 | // new Sample { Id = 10, Age = 9, FirstName = "eee", LastName = "baz" },
48 | // };
49 | // return data;
50 | // }
51 |
52 | // [Fact]
53 | // public void Issue57()
54 | // {
55 | // var builder = new DatabaseBuilder();
56 | // builder.Append(CreateData());
57 |
58 | // var bin = builder.Build();
59 | // var db = new MemoryDatabase(bin);
60 |
61 | // db.SampleTable.FindRangeByAge(2, 2).Select(x => x.Id).ToArray().Should().BeEquivalentTo(new int[] { });
62 | // db.SampleTable.FindRangeByAge(30, 50).Select(x => x.Id).ToArray().Should().BeEquivalentTo(new int[] { 7, 8 });
63 | // db.SampleTable.FindRangeByAge(100, 100).Select(x => x.Id).ToArray().Should().BeEquivalentTo(new int[] { });
64 | // }
65 |
66 | // }
67 | //}
68 |
--------------------------------------------------------------------------------
/src/DataTables.Unity/Assets/Tests/IssueTest.cs.meta:
--------------------------------------------------------------------------------
1 | fileFormatVersion: 2
2 | guid: 826c21784d299f44b8f6b64eaaf2ed57
3 | MonoImporter:
4 | externalObjects: {}
5 | serializedVersion: 2
6 | defaultReferences: []
7 | executionOrder: 0
8 | icon: {instanceID: 0}
9 | userData:
10 | assetBundleName:
11 | assetBundleVariant:
12 |
--------------------------------------------------------------------------------
/src/DataTables.Unity/Packages/manifest.json:
--------------------------------------------------------------------------------
1 | {
2 | "dependencies": {
3 | "com.cysharp.runtimeunittesttoolkit": "https://github.com/Cysharp/RuntimeUnitTestToolkit.git?path=RuntimeUnitTestToolkit/Assets/RuntimeUnitTestToolkit#2.6.1",
4 | "com.unity.ide.rider": "3.0.34",
5 | "com.unity.test-framework": "1.1.33",
6 | "com.unity.test-framework.performance": "2.8.1-preview",
7 | "com.unity.toolchain.win-x86_64-linux-x86_64": "2.0.9",
8 | "com.unity.collab-proxy": "2.4.3",
9 | "com.unity.ugui": "1.0.0",
10 | "com.unity.modules.ai": "1.0.0",
11 | "com.unity.modules.androidjni": "1.0.0",
12 | "com.unity.modules.animation": "1.0.0",
13 | "com.unity.modules.assetbundle": "1.0.0",
14 | "com.unity.modules.audio": "1.0.0",
15 | "com.unity.modules.cloth": "1.0.0",
16 | "com.unity.modules.director": "1.0.0",
17 | "com.unity.modules.imageconversion": "1.0.0",
18 | "com.unity.modules.imgui": "1.0.0",
19 | "com.unity.modules.jsonserialize": "1.0.0",
20 | "com.unity.modules.particlesystem": "1.0.0",
21 | "com.unity.modules.physics": "1.0.0",
22 | "com.unity.modules.physics2d": "1.0.0",
23 | "com.unity.modules.screencapture": "1.0.0",
24 | "com.unity.modules.terrain": "1.0.0",
25 | "com.unity.modules.terrainphysics": "1.0.0",
26 | "com.unity.modules.tilemap": "1.0.0",
27 | "com.unity.modules.ui": "1.0.0",
28 | "com.unity.modules.uielements": "1.0.0",
29 | "com.unity.modules.umbra": "1.0.0",
30 | "com.unity.modules.unityanalytics": "1.0.0",
31 | "com.unity.modules.unitywebrequest": "1.0.0",
32 | "com.unity.modules.unitywebrequestassetbundle": "1.0.0",
33 | "com.unity.modules.unitywebrequestaudio": "1.0.0",
34 | "com.unity.modules.unitywebrequesttexture": "1.0.0",
35 | "com.unity.modules.unitywebrequestwww": "1.0.0",
36 | "com.unity.modules.vehicles": "1.0.0",
37 | "com.unity.modules.video": "1.0.0",
38 | "com.unity.modules.vr": "1.0.0",
39 | "com.unity.modules.wind": "1.0.0",
40 | "com.unity.modules.xr": "1.0.0"
41 | }
42 | }
43 |
--------------------------------------------------------------------------------
/src/DataTables.Unity/ProjectSettings/AudioManager.asset:
--------------------------------------------------------------------------------
1 | %YAML 1.1
2 | %TAG !u! tag:unity3d.com,2011:
3 | --- !u!11 &1
4 | AudioManager:
5 | m_ObjectHideFlags: 0
6 | m_Volume: 1
7 | Rolloff Scale: 1
8 | Doppler Factor: 1
9 | Default Speaker Mode: 2
10 | m_SampleRate: 0
11 | m_DSPBufferSize: 1024
12 | m_VirtualVoiceCount: 512
13 | m_RealVoiceCount: 32
14 | m_SpatializerPlugin:
15 | m_AmbisonicDecoderPlugin:
16 | m_DisableAudio: 0
17 | m_VirtualizeEffects: 1
18 |
--------------------------------------------------------------------------------
/src/DataTables.Unity/ProjectSettings/ClusterInputManager.asset:
--------------------------------------------------------------------------------
1 | %YAML 1.1
2 | %TAG !u! tag:unity3d.com,2011:
3 | --- !u!236 &1
4 | ClusterInputManager:
5 | m_ObjectHideFlags: 0
6 | m_Inputs: []
7 |
--------------------------------------------------------------------------------
/src/DataTables.Unity/ProjectSettings/DynamicsManager.asset:
--------------------------------------------------------------------------------
1 | %YAML 1.1
2 | %TAG !u! tag:unity3d.com,2011:
3 | --- !u!55 &1
4 | PhysicsManager:
5 | m_ObjectHideFlags: 0
6 | serializedVersion: 7
7 | m_Gravity: {x: 0, y: -9.81, z: 0}
8 | m_DefaultMaterial: {fileID: 0}
9 | m_BounceThreshold: 2
10 | m_SleepThreshold: 0.005
11 | m_DefaultContactOffset: 0.01
12 | m_DefaultSolverIterations: 6
13 | m_DefaultSolverVelocityIterations: 1
14 | m_QueriesHitBackfaces: 0
15 | m_QueriesHitTriggers: 1
16 | m_EnableAdaptiveForce: 0
17 | m_ClothInterCollisionDistance: 0
18 | m_ClothInterCollisionStiffness: 0
19 | m_ContactsGeneration: 1
20 | m_LayerCollisionMatrix: ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff
21 | m_AutoSimulation: 1
22 | m_AutoSyncTransforms: 0
23 | m_ReuseCollisionCallbacks: 1
24 | m_ClothInterCollisionSettingsToggle: 0
25 | m_ContactPairsMode: 0
26 | m_BroadphaseType: 0
27 | m_WorldBounds:
28 | m_Center: {x: 0, y: 0, z: 0}
29 | m_Extent: {x: 250, y: 250, z: 250}
30 | m_WorldSubdivisions: 8
31 |
--------------------------------------------------------------------------------
/src/DataTables.Unity/ProjectSettings/EditorBuildSettings.asset:
--------------------------------------------------------------------------------
1 | %YAML 1.1
2 | %TAG !u! tag:unity3d.com,2011:
3 | --- !u!1045 &1
4 | EditorBuildSettings:
5 | m_ObjectHideFlags: 0
6 | serializedVersion: 2
7 | m_Scenes:
8 | - enabled: 1
9 | path: Assets/Scenes/SampleScene.unity
10 | guid: 2cda990e2423bbf4892e6590ba056729
11 | m_configObjects: {}
12 |
--------------------------------------------------------------------------------
/src/DataTables.Unity/ProjectSettings/EditorSettings.asset:
--------------------------------------------------------------------------------
1 | %YAML 1.1
2 | %TAG !u! tag:unity3d.com,2011:
3 | --- !u!159 &1
4 | EditorSettings:
5 | m_ObjectHideFlags: 0
6 | serializedVersion: 7
7 | m_ExternalVersionControlSupport: Visible Meta Files
8 | m_SerializationMode: 2
9 | m_LineEndingsForNewScripts: 2
10 | m_DefaultBehaviorMode: 1
11 | m_SpritePackerMode: 4
12 | m_SpritePackerPaddingPower: 1
13 | m_EtcTextureCompressorBehavior: 1
14 | m_EtcTextureFastCompressor: 1
15 | m_EtcTextureNormalCompressor: 2
16 | m_EtcTextureBestCompressor: 4
17 | m_ProjectGenerationIncludedExtensions: txt;xml;fnt;cd
18 | m_ProjectGenerationRootNamespace:
19 | m_UserGeneratedProjectSuffix:
20 | m_CollabEditorSettings:
21 | inProgressEnabled: 1
22 |
--------------------------------------------------------------------------------
/src/DataTables.Unity/ProjectSettings/GraphicsSettings.asset:
--------------------------------------------------------------------------------
1 | %YAML 1.1
2 | %TAG !u! tag:unity3d.com,2011:
3 | --- !u!30 &1
4 | GraphicsSettings:
5 | m_ObjectHideFlags: 0
6 | serializedVersion: 12
7 | m_Deferred:
8 | m_Mode: 1
9 | m_Shader: {fileID: 69, guid: 0000000000000000f000000000000000, type: 0}
10 | m_DeferredReflections:
11 | m_Mode: 1
12 | m_Shader: {fileID: 74, guid: 0000000000000000f000000000000000, type: 0}
13 | m_ScreenSpaceShadows:
14 | m_Mode: 1
15 | m_Shader: {fileID: 64, guid: 0000000000000000f000000000000000, type: 0}
16 | m_LegacyDeferred:
17 | m_Mode: 1
18 | m_Shader: {fileID: 63, guid: 0000000000000000f000000000000000, type: 0}
19 | m_DepthNormals:
20 | m_Mode: 1
21 | m_Shader: {fileID: 62, guid: 0000000000000000f000000000000000, type: 0}
22 | m_MotionVectors:
23 | m_Mode: 1
24 | m_Shader: {fileID: 75, guid: 0000000000000000f000000000000000, type: 0}
25 | m_LightHalo:
26 | m_Mode: 1
27 | m_Shader: {fileID: 105, guid: 0000000000000000f000000000000000, type: 0}
28 | m_LensFlare:
29 | m_Mode: 1
30 | m_Shader: {fileID: 102, guid: 0000000000000000f000000000000000, type: 0}
31 | m_AlwaysIncludedShaders:
32 | - {fileID: 10753, guid: 0000000000000000f000000000000000, type: 0}
33 | - {fileID: 10770, guid: 0000000000000000f000000000000000, type: 0}
34 | - {fileID: 16000, guid: 0000000000000000f000000000000000, type: 0}
35 | - {fileID: 16001, guid: 0000000000000000f000000000000000, type: 0}
36 | - {fileID: 17000, guid: 0000000000000000f000000000000000, type: 0}
37 | m_PreloadedShaders: []
38 | m_SpritesDefaultMaterial: {fileID: 10754, guid: 0000000000000000f000000000000000,
39 | type: 0}
40 | m_CustomRenderPipeline: {fileID: 0}
41 | m_TransparencySortMode: 0
42 | m_TransparencySortAxis: {x: 0, y: 0, z: 1}
43 | m_DefaultRenderingPath: 1
44 | m_DefaultMobileRenderingPath: 1
45 | m_TierSettings: []
46 | m_LightmapStripping: 0
47 | m_FogStripping: 0
48 | m_InstancingStripping: 0
49 | m_LightmapKeepPlain: 1
50 | m_LightmapKeepDirCombined: 1
51 | m_LightmapKeepDynamicPlain: 1
52 | m_LightmapKeepDynamicDirCombined: 1
53 | m_LightmapKeepShadowMask: 1
54 | m_LightmapKeepSubtractive: 1
55 | m_FogKeepLinear: 1
56 | m_FogKeepExp: 1
57 | m_FogKeepExp2: 1
58 | m_AlbedoSwatchInfos: []
59 | m_LightsUseLinearIntensity: 0
60 | m_LightsUseColorTemperature: 0
61 |
--------------------------------------------------------------------------------
/src/DataTables.Unity/ProjectSettings/MemorySettings.asset:
--------------------------------------------------------------------------------
1 | %YAML 1.1
2 | %TAG !u! tag:unity3d.com,2011:
3 | --- !u!387306366 &1
4 | MemorySettings:
5 | m_ObjectHideFlags: 0
6 | m_EditorMemorySettings:
7 | m_MainAllocatorBlockSize: -1
8 | m_ThreadAllocatorBlockSize: -1
9 | m_MainGfxBlockSize: -1
10 | m_ThreadGfxBlockSize: -1
11 | m_CacheBlockSize: -1
12 | m_TypetreeBlockSize: -1
13 | m_ProfilerBlockSize: -1
14 | m_ProfilerEditorBlockSize: -1
15 | m_BucketAllocatorGranularity: -1
16 | m_BucketAllocatorBucketsCount: -1
17 | m_BucketAllocatorBlockSize: -1
18 | m_BucketAllocatorBlockCount: -1
19 | m_ProfilerBucketAllocatorGranularity: -1
20 | m_ProfilerBucketAllocatorBucketsCount: -1
21 | m_ProfilerBucketAllocatorBlockSize: -1
22 | m_ProfilerBucketAllocatorBlockCount: -1
23 | m_TempAllocatorSizeMain: -1
24 | m_JobTempAllocatorBlockSize: -1
25 | m_BackgroundJobTempAllocatorBlockSize: -1
26 | m_JobTempAllocatorReducedBlockSize: -1
27 | m_TempAllocatorSizeGIBakingWorker: -1
28 | m_TempAllocatorSizeNavMeshWorker: -1
29 | m_TempAllocatorSizeAudioWorker: -1
30 | m_TempAllocatorSizeCloudWorker: -1
31 | m_TempAllocatorSizeGfx: -1
32 | m_TempAllocatorSizeJobWorker: -1
33 | m_TempAllocatorSizeBackgroundWorker: -1
34 | m_TempAllocatorSizePreloadManager: -1
35 | m_PlatformMemorySettings: {}
36 |
--------------------------------------------------------------------------------
/src/DataTables.Unity/ProjectSettings/NavMeshAreas.asset:
--------------------------------------------------------------------------------
1 | %YAML 1.1
2 | %TAG !u! tag:unity3d.com,2011:
3 | --- !u!126 &1
4 | NavMeshProjectSettings:
5 | m_ObjectHideFlags: 0
6 | serializedVersion: 2
7 | areas:
8 | - name: Walkable
9 | cost: 1
10 | - name: Not Walkable
11 | cost: 1
12 | - name: Jump
13 | cost: 2
14 | - name:
15 | cost: 1
16 | - name:
17 | cost: 1
18 | - name:
19 | cost: 1
20 | - name:
21 | cost: 1
22 | - name:
23 | cost: 1
24 | - name:
25 | cost: 1
26 | - name:
27 | cost: 1
28 | - name:
29 | cost: 1
30 | - name:
31 | cost: 1
32 | - name:
33 | cost: 1
34 | - name:
35 | cost: 1
36 | - name:
37 | cost: 1
38 | - name:
39 | cost: 1
40 | - name:
41 | cost: 1
42 | - name:
43 | cost: 1
44 | - name:
45 | cost: 1
46 | - name:
47 | cost: 1
48 | - name:
49 | cost: 1
50 | - name:
51 | cost: 1
52 | - name:
53 | cost: 1
54 | - name:
55 | cost: 1
56 | - name:
57 | cost: 1
58 | - name:
59 | cost: 1
60 | - name:
61 | cost: 1
62 | - name:
63 | cost: 1
64 | - name:
65 | cost: 1
66 | - name:
67 | cost: 1
68 | - name:
69 | cost: 1
70 | - name:
71 | cost: 1
72 | m_LastAgentTypeID: -887442657
73 | m_Settings:
74 | - serializedVersion: 2
75 | agentTypeID: 0
76 | agentRadius: 0.5
77 | agentHeight: 2
78 | agentSlope: 45
79 | agentClimb: 0.75
80 | ledgeDropHeight: 0
81 | maxJumpAcrossDistance: 0
82 | minRegionArea: 2
83 | manualCellSize: 0
84 | cellSize: 0.16666667
85 | manualTileSize: 0
86 | tileSize: 256
87 | accuratePlacement: 0
88 | debug:
89 | m_Flags: 0
90 | m_SettingNames:
91 | - Humanoid
92 |
--------------------------------------------------------------------------------
/src/DataTables.Unity/ProjectSettings/NetworkManager.asset:
--------------------------------------------------------------------------------
1 | %YAML 1.1
2 | %TAG !u! tag:unity3d.com,2011:
3 | --- !u!149 &1
4 | NetworkManager:
5 | m_ObjectHideFlags: 0
6 | m_DebugLevel: 0
7 | m_Sendrate: 15
8 | m_AssetToPrefab: {}
9 |
--------------------------------------------------------------------------------
/src/DataTables.Unity/ProjectSettings/PackageManagerSettings.asset:
--------------------------------------------------------------------------------
1 | %YAML 1.1
2 | %TAG !u! tag:unity3d.com,2011:
3 | --- !u!114 &1
4 | MonoBehaviour:
5 | m_ObjectHideFlags: 61
6 | m_CorrespondingSourceObject: {fileID: 0}
7 | m_PrefabInstance: {fileID: 0}
8 | m_PrefabAsset: {fileID: 0}
9 | m_GameObject: {fileID: 0}
10 | m_Enabled: 1
11 | m_EditorHideFlags: 0
12 | m_Script: {fileID: 13964, guid: 0000000000000000e000000000000000, type: 0}
13 | m_Name:
14 | m_EditorClassIdentifier:
15 | m_EnablePreviewPackages: 0
16 | m_EnablePackageDependencies: 0
17 | m_AdvancedSettingsExpanded: 1
18 | m_ScopedRegistriesSettingsExpanded: 1
19 | oneTimeWarningShown: 0
20 | m_Registries:
21 | - m_Id: main
22 | m_Name:
23 | m_Url: https://packages.unity.com
24 | m_Scopes: []
25 | m_IsDefault: 1
26 | m_Capabilities: 7
27 | m_UserSelectedRegistryName:
28 | m_UserAddingNewScopedRegistry: 0
29 | m_RegistryInfoDraft:
30 | m_ErrorMessage:
31 | m_Original:
32 | m_Id:
33 | m_Name:
34 | m_Url:
35 | m_Scopes: []
36 | m_IsDefault: 0
37 | m_Capabilities: 0
38 | m_Modified: 0
39 | m_Name:
40 | m_Url:
41 | m_Scopes:
42 | -
43 | m_SelectedScopeIndex: 0
44 |
--------------------------------------------------------------------------------
/src/DataTables.Unity/ProjectSettings/Physics2DSettings.asset:
--------------------------------------------------------------------------------
1 | %YAML 1.1
2 | %TAG !u! tag:unity3d.com,2011:
3 | --- !u!19 &1
4 | Physics2DSettings:
5 | m_ObjectHideFlags: 0
6 | serializedVersion: 4
7 | m_Gravity: {x: 0, y: -9.81}
8 | m_DefaultMaterial: {fileID: 0}
9 | m_VelocityIterations: 8
10 | m_PositionIterations: 3
11 | m_VelocityThreshold: 1
12 | m_MaxLinearCorrection: 0.2
13 | m_MaxAngularCorrection: 8
14 | m_MaxTranslationSpeed: 100
15 | m_MaxRotationSpeed: 360
16 | m_BaumgarteScale: 0.2
17 | m_BaumgarteTimeOfImpactScale: 0.75
18 | m_TimeToSleep: 0.5
19 | m_LinearSleepTolerance: 0.01
20 | m_AngularSleepTolerance: 2
21 | m_DefaultContactOffset: 0.01
22 | m_JobOptions:
23 | serializedVersion: 2
24 | useMultithreading: 0
25 | useConsistencySorting: 0
26 | m_InterpolationPosesPerJob: 100
27 | m_NewContactsPerJob: 30
28 | m_CollideContactsPerJob: 100
29 | m_ClearFlagsPerJob: 200
30 | m_ClearBodyForcesPerJob: 200
31 | m_SyncDiscreteFixturesPerJob: 50
32 | m_SyncContinuousFixturesPerJob: 50
33 | m_FindNearestContactsPerJob: 100
34 | m_UpdateTriggerContactsPerJob: 100
35 | m_IslandSolverCostThreshold: 100
36 | m_IslandSolverBodyCostScale: 1
37 | m_IslandSolverContactCostScale: 10
38 | m_IslandSolverJointCostScale: 10
39 | m_IslandSolverBodiesPerJob: 50
40 | m_IslandSolverContactsPerJob: 50
41 | m_AutoSimulation: 1
42 | m_QueriesHitTriggers: 1
43 | m_QueriesStartInColliders: 1
44 | m_CallbacksOnDisable: 1
45 | m_ReuseCollisionCallbacks: 0
46 | m_AutoSyncTransforms: 0
47 | m_AlwaysShowColliders: 0
48 | m_ShowColliderSleep: 1
49 | m_ShowColliderContacts: 0
50 | m_ShowColliderAABB: 0
51 | m_ContactArrowScale: 0.2
52 | m_ColliderAwakeColor: {r: 0.5686275, g: 0.95686275, b: 0.54509807, a: 0.7529412}
53 | m_ColliderAsleepColor: {r: 0.5686275, g: 0.95686275, b: 0.54509807, a: 0.36078432}
54 | m_ColliderContactColor: {r: 1, g: 0, b: 1, a: 0.6862745}
55 | m_ColliderAABBColor: {r: 1, g: 1, b: 0, a: 0.2509804}
56 | m_LayerCollisionMatrix: ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff
57 |
--------------------------------------------------------------------------------
/src/DataTables.Unity/ProjectSettings/PresetManager.asset:
--------------------------------------------------------------------------------
1 | %YAML 1.1
2 | %TAG !u! tag:unity3d.com,2011:
3 | --- !u!1386491679 &1
4 | PresetManager:
5 | m_ObjectHideFlags: 0
6 | m_DefaultList: []
7 |
--------------------------------------------------------------------------------
/src/DataTables.Unity/ProjectSettings/ProjectVersion.txt:
--------------------------------------------------------------------------------
1 | m_EditorVersion: 2021.3.19f1
2 | m_EditorVersionWithRevision: 2021.3.19f1 (c9714fde33b6)
3 |
--------------------------------------------------------------------------------
/src/DataTables.Unity/ProjectSettings/TagManager.asset:
--------------------------------------------------------------------------------
1 | %YAML 1.1
2 | %TAG !u! tag:unity3d.com,2011:
3 | --- !u!78 &1
4 | TagManager:
5 | serializedVersion: 2
6 | tags: []
7 | layers:
8 | - Default
9 | - TransparentFX
10 | - Ignore Raycast
11 | -
12 | - Water
13 | - UI
14 | -
15 | -
16 | -
17 | -
18 | -
19 | -
20 | -
21 | -
22 | -
23 | -
24 | -
25 | -
26 | -
27 | -
28 | -
29 | -
30 | -
31 | -
32 | -
33 | -
34 | -
35 | -
36 | -
37 | -
38 | -
39 | -
40 | m_SortingLayers:
41 | - name: Default
42 | uniqueID: 0
43 | locked: 0
44 |
--------------------------------------------------------------------------------
/src/DataTables.Unity/ProjectSettings/TimeManager.asset:
--------------------------------------------------------------------------------
1 | %YAML 1.1
2 | %TAG !u! tag:unity3d.com,2011:
3 | --- !u!5 &1
4 | TimeManager:
5 | m_ObjectHideFlags: 0
6 | Fixed Timestep: 0.02
7 | Maximum Allowed Timestep: 0.1
8 | m_TimeScale: 1
9 | Maximum Particle Timestep: 0.03
10 |
--------------------------------------------------------------------------------
/src/DataTables.Unity/ProjectSettings/UnityConnectSettings.asset:
--------------------------------------------------------------------------------
1 | %YAML 1.1
2 | %TAG !u! tag:unity3d.com,2011:
3 | --- !u!310 &1
4 | UnityConnectSettings:
5 | m_ObjectHideFlags: 0
6 | serializedVersion: 1
7 | m_Enabled: 0
8 | m_TestMode: 0
9 | m_EventOldUrl: https://api.uca.cloud.unity3d.com/v1/events
10 | m_EventUrl: https://cdp.cloud.unity3d.com/v1/events
11 | m_ConfigUrl: https://config.uca.cloud.unity3d.com
12 | m_DashboardUrl: https://dashboard.unity3d.com
13 | m_TestInitMode: 0
14 | CrashReportingSettings:
15 | m_EventUrl: https://perf-events.cloud.unity3d.com
16 | m_Enabled: 0
17 | m_LogBufferSize: 10
18 | m_CaptureEditorExceptions: 1
19 | UnityPurchasingSettings:
20 | m_Enabled: 0
21 | m_TestMode: 0
22 | UnityAnalyticsSettings:
23 | m_Enabled: 0
24 | m_TestMode: 0
25 | m_InitializeOnStartup: 1
26 | m_PackageRequiringCoreStatsPresent: 0
27 | UnityAdsSettings:
28 | m_Enabled: 0
29 | m_InitializeOnStartup: 1
30 | m_TestMode: 0
31 | m_IosGameId:
32 | m_AndroidGameId:
33 | m_GameIds: {}
34 | m_GameId:
35 | PerformanceReportingSettings:
36 | m_Enabled: 0
37 |
--------------------------------------------------------------------------------
/src/DataTables.Unity/ProjectSettings/VFXManager.asset:
--------------------------------------------------------------------------------
1 | %YAML 1.1
2 | %TAG !u! tag:unity3d.com,2011:
3 | --- !u!937362698 &1
4 | VFXManager:
5 | m_ObjectHideFlags: 0
6 | m_IndirectShader: {fileID: 0}
7 | m_RenderPipeSettingsPath:
8 |
--------------------------------------------------------------------------------
/src/DataTables.Unity/ProjectSettings/VersionControlSettings.asset:
--------------------------------------------------------------------------------
1 | %YAML 1.1
2 | %TAG !u! tag:unity3d.com,2011:
3 | --- !u!890905787 &1
4 | VersionControlSettings:
5 | m_ObjectHideFlags: 0
6 | m_Mode: Visible Meta Files
7 | m_CollabEditorSettings:
8 | inProgressEnabled: 1
9 |
--------------------------------------------------------------------------------
/src/DataTables.Unity/ProjectSettings/XRSettings.asset:
--------------------------------------------------------------------------------
1 | {
2 | "m_SettingKeys": [
3 | "VR Device Disabled",
4 | "VR Device User Alert"
5 | ],
6 | "m_SettingValues": [
7 | "False",
8 | "False"
9 | ]
10 | }
--------------------------------------------------------------------------------
/src/DataTables/BinaryExtension.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.IO;
3 |
4 | namespace DataTables
5 | {
6 | public static class BinaryExtension
7 | {
8 | ///
9 | /// 从二进制流读取编码后的 32 位有符号整数。
10 | ///
11 | /// 要读取的二进制流。
12 | /// 读取的 32 位有符号整数。
13 | public static int Read7BitEncodedInt32(this BinaryReader binaryReader)
14 | {
15 | int value = 0;
16 | int shift = 0;
17 | byte b;
18 | do
19 | {
20 | if (shift >= 35)
21 | {
22 | throw new Exception("7 bit encoded int is invalid.");
23 | }
24 |
25 | b = binaryReader.ReadByte();
26 | value |= (b & 0x7f) << shift;
27 | shift += 7;
28 | } while ((b & 0x80) != 0);
29 |
30 | return value;
31 | }
32 |
33 | ///
34 | /// 向二进制流写入编码后的 32 位有符号整数。
35 | ///
36 | /// 要写入的二进制流。
37 | /// 要写入的 32 位有符号整数。
38 | public static void Write7BitEncodedInt32(this BinaryWriter binaryWriter, int value)
39 | {
40 | uint num = (uint)value;
41 | while (num >= 0x80)
42 | {
43 | binaryWriter.Write((byte)(num | 0x80));
44 | num >>= 7;
45 | }
46 |
47 | binaryWriter.Write((byte)num);
48 | }
49 |
50 | ///
51 | /// 从二进制流读取编码后的 32 位无符号整数。
52 | ///
53 | /// 要读取的二进制流。
54 | /// 读取的 32 位无符号整数。
55 | public static uint Read7BitEncodedUInt32(this BinaryReader binaryReader)
56 | {
57 | return (uint)Read7BitEncodedInt32(binaryReader);
58 | }
59 |
60 | ///
61 | /// 向二进制流写入编码后的 32 位无符号整数。
62 | ///
63 | /// 要写入的二进制流。
64 | /// 要写入的 32 位无符号整数。
65 | public static void Write7BitEncodedUInt32(this BinaryWriter binaryWriter, uint value)
66 | {
67 | Write7BitEncodedInt32(binaryWriter, (int)value);
68 | }
69 |
70 | ///
71 | /// 从二进制流读取编码后的 64 位有符号整数。
72 | ///
73 | /// 要读取的二进制流。
74 | /// 读取的 64 位有符号整数。
75 | public static long Read7BitEncodedInt64(this BinaryReader binaryReader)
76 | {
77 | long value = 0L;
78 | int shift = 0;
79 | byte b;
80 | do
81 | {
82 | if (shift >= 70)
83 | {
84 | throw new Exception("7 bit encoded int is invalid.");
85 | }
86 |
87 | b = binaryReader.ReadByte();
88 | value |= (b & 0x7fL) << shift;
89 | shift += 7;
90 | } while ((b & 0x80) != 0);
91 |
92 | return value;
93 | }
94 |
95 | ///
96 | /// 向二进制流写入编码后的 64 位有符号整数。
97 | ///
98 | /// 要写入的二进制流。
99 | /// 要写入的 64 位有符号整数。
100 | public static void Write7BitEncodedInt64(this BinaryWriter binaryWriter, long value)
101 | {
102 | ulong num = (ulong)value;
103 | while (num >= 0x80)
104 | {
105 | binaryWriter.Write((byte)(num | 0x80));
106 | num >>= 7;
107 | }
108 |
109 | binaryWriter.Write((byte)num);
110 | }
111 |
112 | ///
113 | /// 从二进制流读取编码后的 64 位无符号整数。
114 | ///
115 | /// 要读取的二进制流。
116 | /// 读取的 64 位无符号整数。
117 | public static ulong Read7BitEncodedUInt64(this BinaryReader binaryReader)
118 | {
119 | return (ulong)Read7BitEncodedInt64(binaryReader);
120 | }
121 |
122 | ///
123 | /// 向二进制流写入编码后的 64 位无符号整数。
124 | ///
125 | /// 要写入的二进制流。
126 | /// 要写入的 64 位无符号整数。
127 | public static void Write7BitEncodedUInt64(this BinaryWriter binaryWriter, ulong value)
128 | {
129 | Write7BitEncodedInt64(binaryWriter, (long)value);
130 | }
131 |
132 | public static T? ReadJson(this BinaryReader binaryReader)
133 | {
134 | var plain = binaryReader.ReadString();
135 | if (string.IsNullOrEmpty(plain))
136 | {
137 | return default;
138 | }
139 |
140 | #if NET7_0_OR_GREATER
141 | return System.Text.Json.JsonSerializer.Deserialize(plain);
142 | #elif UNITY_EDITOR
143 | return UnityEngine.JsonUtility.FromJson(plain);
144 | #else
145 | throw new NotImplementedException();
146 | #endif
147 | }
148 | }
149 | }
150 |
--------------------------------------------------------------------------------
/src/DataTables/DataRowBase.cs:
--------------------------------------------------------------------------------
1 | using System.IO;
2 |
3 | namespace DataTables
4 | {
5 | public abstract class DataRowBase : IDataRow
6 | {
7 | public abstract bool Deserialize(BinaryReader binaryReader);
8 | }
9 | }
10 |
--------------------------------------------------------------------------------
/src/DataTables/DataTableBase.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.IO;
3 |
4 | namespace DataTables
5 | {
6 | public abstract class DataTableBase
7 | {
8 | private readonly string m_Name;
9 |
10 | ///
11 | /// 初始化数据表基类的新实例。
12 | ///
13 | /// 数据表名称。
14 | public DataTableBase(string name)
15 | {
16 | m_Name = name;
17 | }
18 |
19 | ///
20 | /// 获取数据表名称。
21 | ///
22 | public string Name => m_Name;
23 |
24 | ///
25 | /// 获取数据表完整名称。
26 | ///
27 | public string FullName => Type.ToString();
28 |
29 | ///
30 | /// 获取数据表行的类型。
31 | ///
32 | public abstract Type Type
33 | {
34 | get;
35 | }
36 |
37 | ///
38 | /// 获取数据表行数。
39 | ///
40 | public abstract int Count
41 | {
42 | get;
43 | }
44 |
45 | ///
46 | /// 增加数据表行。
47 | ///
48 | /// 将要增加的数据表行的索引值。
49 | /// 要解析的数据表行二进制流。
50 | /// 是否增加数据表行成功。
51 | public abstract bool ParseDataRow(int index, BinaryReader reader);
52 |
53 | ///
54 | /// 配置表加载完成
55 | /// 可重载该方法以便自定义一些额外的操作
56 | ///
57 | public virtual void OnLoadCompleted() { }
58 |
59 | ///
60 | /// 清空所有数据表行。
61 | ///
62 | public virtual void RemoveAllDataRows()
63 | { }
64 |
65 | ///
66 | /// 关闭并清理数据表。
67 | ///
68 | internal virtual void Shutdown()
69 | { }
70 | }
71 | }
72 |
--------------------------------------------------------------------------------
/src/DataTables/DataTables.csproj:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | net8.0;net7.0
5 | DataTables
6 | DataTables
7 |
8 | Library
9 | False
10 | ChronosGames
11 | true
12 | 1701;1702;1705;1591
13 |
14 |
15 | DataTables.API
16 | $(Version)
17 | Numeric configuration table export tool for .NET Core and Unity.
18 | README.md
19 | database, embedded, inmemory, unity
20 | true
21 |
22 |
23 |
24 |
25 | $(ProjectDir)..\DataTables.Unity\Assets\Scripts\DataTables\
26 | $(ProjectDir)..\DataTables.Unity\Assets\Tests\
27 |
28 |
29 |
30 |
31 |
32 |
33 |
34 |
35 |
36 |
37 | <_Parameter1>Benchmark, PublicKey=0024000004800000940000000602000000240000525341310004000001000100158c9a06ce071a553739a9933ef692c40407e7bfdeedfc0657ed5316e2cc9608d8a362bc9a444aa39d1497bad2f9940a06ed7da3f011ea52ec8bcb3ed7999880f8a3afcf8005eef891a285c160f1b17c7ddf818fcb743320f49ae69cbcddd1d3a964d86aa9727c06da5d2bbf328cc1388fd3b60d68bedb2c4915b283b7afaaca
38 |
39 |
40 |
41 |
42 |
43 |
44 |
45 |
46 |
47 |
--------------------------------------------------------------------------------
/src/DataTables/DefaultDataTableHelper.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.IO;
3 |
4 | namespace DataTables
5 | {
6 | public class DefaultDataTableHelper : IDataTableHelper
7 | {
8 | private readonly string m_DataDir;
9 |
10 | public DefaultDataTableHelper(string dataDir)
11 | {
12 | m_DataDir = dataDir;
13 | }
14 |
15 | public void Read(string fileName, Action callback)
16 | {
17 | var raw = File.ReadAllBytes(Path.Combine(m_DataDir, fileName) + ".bytes");
18 | callback(raw);
19 | }
20 | }
21 | }
22 |
--------------------------------------------------------------------------------
/src/DataTables/IDataRow.cs:
--------------------------------------------------------------------------------
1 | using System.IO;
2 |
3 | namespace DataTables
4 | {
5 | ///
6 | /// 数据表行接口。
7 | ///
8 | public interface IDataRow
9 | {
10 | ///
11 | /// 解锁数据表行
12 | ///
13 | /// 要解析的数据表行二进制流
14 | /// 是否解析数据表行成功
15 | bool Deserialize(BinaryReader reader);
16 | }
17 | }
18 |
--------------------------------------------------------------------------------
/src/DataTables/IDataTable.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Linq;
4 |
5 | namespace DataTables
6 | {
7 | public interface IDataTable : IEnumerable where T : IDataRow
8 | {
9 | ///
10 | /// 获取数据表名称。
11 | ///
12 | string Name
13 | {
14 | get;
15 | }
16 |
17 | ///
18 | /// 获取数据表完整名称。
19 | ///
20 | string FullName
21 | {
22 | get;
23 | }
24 |
25 | ///
26 | /// 获取数据表行的类型。
27 | ///
28 | Type Type
29 | {
30 | get;
31 | }
32 |
33 | ///
34 | /// 获取数据表行数。
35 | ///
36 | int Count
37 | {
38 | get;
39 | }
40 |
41 | ///
42 | /// 检查是否存在数据表行。
43 | ///
44 | /// 要检查的条件。
45 | /// 是否存在数据表行。
46 | bool HasDataRow(Predicate condition);
47 |
48 | ///
49 | /// 获取符合条件的数据表行。
50 | ///
51 | /// 要检查的条件。
52 | /// 符合条件的数据表行。
53 | /// 当存在多个符合条件的数据表行时,仅返回第一个符合条件的数据表行。
54 | T? GetDataRow(Predicate condition);
55 |
56 | ///
57 | /// 获取符合条件的数据表行。
58 | ///
59 | /// 要检查的条件。
60 | /// 符合条件的数据表行。
61 | IEnumerable GetDataRows(Predicate condition);
62 |
63 | ///
64 | /// 获取符合条件的数据表行。
65 | ///
66 | /// 要检查的条件。
67 | /// 符合条件的数据表行。
68 | void GetDataRows(Predicate condition, List results);
69 |
70 | ///
71 | /// 获取排序后的数据表行。
72 | ///
73 | /// 要排序的条件。
74 | /// 排序后的数据表行。
75 | T[] GetDataRows(Comparison comparison);
76 |
77 | ///
78 | /// 获取排序后的数据表行。
79 | ///
80 | /// 要排序的条件。
81 | /// 排序后的数据表行。
82 | void GetDataRows(Comparison comparison, List results);
83 |
84 | ///
85 | /// 获取排序后的符合条件的数据表行。
86 | ///
87 | /// 要检查的条件。
88 | /// 要排序的条件。
89 | /// 排序后的符合条件的数据表行。
90 | IOrderedEnumerable GetDataRows(Predicate condition, Comparison comparison);
91 |
92 | ///
93 | /// 获取排序后的符合条件的数据表行。
94 | ///
95 | /// 要检查的条件。
96 | /// 要排序的条件。
97 | /// 排序后的符合条件的数据表行。
98 | void GetDataRows(Predicate condition, Comparison comparison, List results);
99 |
100 | ///
101 | /// 获取所有数据表行。
102 | ///
103 | /// 所有数据表行。
104 | T[] GetAllDataRows();
105 |
106 | ///
107 | /// 获取所有数据表行。
108 | ///
109 | /// 所有数据表行。
110 | void GetAllDataRows(List results);
111 |
112 | ///
113 | /// 清空所有数据表行。
114 | ///
115 | void RemoveAllDataRows();
116 | }
117 | }
118 |
--------------------------------------------------------------------------------
/src/DataTables/IDataTableHelper.cs:
--------------------------------------------------------------------------------
1 | using System;
2 |
3 | namespace DataTables
4 | {
5 | ///
6 | /// 数据表辅助器接口。
7 | ///
8 | public interface IDataTableHelper
9 | {
10 | void Read(string fileName, Action callback);
11 | }
12 | }
13 |
--------------------------------------------------------------------------------
/src/DataTables/IDataTableManager.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 |
4 | namespace DataTables
5 | {
6 | ///
7 | /// 数据表管理器接口。
8 | ///
9 | public interface IDataTableManager
10 | {
11 | ///
12 | /// 获取数据表数量。
13 | ///
14 | int Count
15 | {
16 | get;
17 | }
18 |
19 | ///
20 | /// 设置数据表辅助器。
21 | ///
22 | /// 数据表辅助器。
23 | void SetDataTableHelper(IDataTableHelper dataTableHelper);
24 |
25 | ///
26 | /// 是否存在数据表。
27 | ///
28 | /// 数据表的类型。
29 | /// 数据表名称。
30 | /// 是否存在数据表。
31 | bool HasDataTable(Type dataTableType, string name = "");
32 |
33 | ///
34 | /// 是否存在数据表。
35 | ///
36 | /// 数据表的类型。
37 | /// 数据表名称。
38 | /// 是否存在数据表。
39 | bool HasDataTable(string name = "") where T : DataTableBase;
40 |
41 | ///
42 | /// 获取数据表。
43 | ///
44 | /// 数据表的类型。
45 | /// 数据表名称。
46 | /// 要获取的数据表。
47 | T? GetDataTable(string name = "") where T : DataTableBase;
48 |
49 | ///
50 | /// 获取数据表。
51 | ///
52 | /// 数据表的类型。
53 | /// 数据表名称。
54 | /// 要获取的数据表。
55 | DataTableBase? GetDataTable(Type dataTableType, string name = "");
56 |
57 | ///
58 | /// 获取所有数据表。
59 | ///
60 | /// 所有数据表。
61 | DataTableBase[] GetAllDataTables();
62 |
63 | ///
64 | /// 获取所有数据表。
65 | ///
66 | /// 所有数据表。
67 | void GetAllDataTables(List results);
68 |
69 | ///
70 | /// 创建数据表。
71 | ///
72 | /// 数据表的类型。
73 | /// 数据表加载完成时回调。
74 | void CreateDataTable(Action onCompleted) where T : DataTableBase;
75 |
76 | ///
77 | /// 创建数据表。
78 | ///
79 | /// 数据表的类型。
80 | /// 数据表加载完成时回调。
81 | void CreateDataTable(Type dataTableType, Action onCompleted);
82 |
83 | ///
84 | /// 创建数据表。
85 | ///
86 | /// 数据表的类型。
87 | /// 数据表名称。
88 | /// 数据表加载完成时回调。
89 | void CreateDataTable(string name, Action onCompleted) where T : DataTableBase;
90 |
91 | ///
92 | /// 创建数据表。
93 | ///
94 | /// 数据表的类型。
95 | /// 数据表名称。
96 | /// 数据表加载完成时回调。
97 | void CreateDataTable(Type dataTableType, string name, Action onCompleted);
98 |
99 | ///
100 | /// 销毁数据表。
101 | ///
102 | /// 要销毁的数据表。
103 | /// 是否销毁数据表成功。
104 | bool DestroyDataTable(DataTableBase dataTable);
105 |
106 | ///
107 | /// 销毁数据表。
108 | ///
109 | /// 数据表的类型。
110 | /// 数据表名称。
111 | /// 是否销毁数据表成功。
112 | bool DestroyDataTable(string name = "") where T : DataTableBase;
113 |
114 | ///
115 | /// 销毁数据表。
116 | ///
117 | /// 数据表的类型。
118 | /// 数据表名称。
119 | /// 是否销毁数据表成功。
120 | bool DestroyDataTable(Type dataTableType, string name = "");
121 | }
122 | }
123 |
--------------------------------------------------------------------------------
/src/DataTables/TypeNamePair.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Runtime.CompilerServices;
3 | using System.Runtime.InteropServices;
4 |
5 | namespace DataTables
6 | {
7 | ///
8 | /// 类型和名称的组合值。
9 | ///
10 | [StructLayout(LayoutKind.Auto)]
11 | internal readonly struct TypeNamePair : IEquatable
12 | {
13 | private readonly Type m_Type;
14 | private readonly string m_Name;
15 |
16 | ///
17 | /// 初始化类型和名称的组合值的新实例。
18 | ///
19 | /// 类型。
20 | public TypeNamePair(Type type) : this(type, string.Empty)
21 | {
22 | }
23 |
24 | ///
25 | /// 初始化类型和名称的组合值的新实例。
26 | ///
27 | /// 类型。
28 | /// 名称。
29 | public TypeNamePair(Type type, string name)
30 | {
31 | if (type == null)
32 | {
33 | throw new Exception("Type is invalid.");
34 | }
35 |
36 | m_Type = type;
37 | m_Name = name ?? string.Empty;
38 | }
39 |
40 | ///
41 | /// 获取类型。
42 | ///
43 | public Type Type
44 | {
45 | get
46 | {
47 | return m_Type;
48 | }
49 | }
50 |
51 | ///
52 | /// 获取名称。
53 | ///
54 | public string Name
55 | {
56 | get
57 | {
58 | return m_Name;
59 | }
60 | }
61 |
62 | ///
63 | /// 获取类型和名称的组合值字符串。
64 | ///
65 | /// 类型和名称的组合值字符串。
66 | public override string ToString()
67 | {
68 | if (m_Type == null)
69 | {
70 | throw new Exception("Type is invalid.");
71 | }
72 |
73 | string typeName = m_Type.FullName!;
74 | return string.IsNullOrEmpty(m_Name) ? typeName : string.Format("{0}.{1}", typeName, m_Name);
75 | }
76 |
77 | ///
78 | /// 获取对象的哈希值。
79 | ///
80 | /// 对象的哈希值。
81 | [MethodImpl(MethodImplOptions.AggressiveInlining)]
82 | public override int GetHashCode()
83 | {
84 | return HashCode.Combine(m_Type, m_Name);
85 | }
86 |
87 | ///
88 | /// 比较对象是否与自身相等。
89 | ///
90 | /// 要比较的对象。
91 | /// 被比较的对象是否与自身相等。
92 | [MethodImpl(MethodImplOptions.AggressiveInlining)]
93 | public override bool Equals(object? obj)
94 | {
95 | return obj is TypeNamePair && Equals((TypeNamePair)obj);
96 | }
97 |
98 | ///
99 | /// 比较对象是否与自身相等。
100 | ///
101 | /// 要比较的对象。
102 | /// 被比较的对象是否与自身相等。
103 | [MethodImpl(MethodImplOptions.AggressiveInlining)]
104 | public bool Equals(TypeNamePair value)
105 | {
106 | return m_Type == value.m_Type && string.CompareOrdinal(m_Name, value.m_Name) == 0;
107 | }
108 |
109 | ///
110 | /// 判断两个对象是否相等。
111 | ///
112 | /// 值 a。
113 | /// 值 b。
114 | /// 两个对象是否相等。
115 | [MethodImpl(MethodImplOptions.AggressiveInlining)]
116 | public static bool operator ==(TypeNamePair a, TypeNamePair b)
117 | {
118 | return a.Equals(b);
119 | }
120 |
121 | ///
122 | /// 判断两个对象是否不相等。
123 | ///
124 | /// 值 a。
125 | /// 值 b。
126 | /// 两个对象是否不相等。
127 | [MethodImpl(MethodImplOptions.AggressiveInlining)]
128 | public static bool operator !=(TypeNamePair a, TypeNamePair b)
129 | {
130 | return !a.Equals(b);
131 | }
132 | }
133 | }
134 |
--------------------------------------------------------------------------------
/tests/DataTables.Tests/BinaryExtensionTest.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.IO;
3 | using Xunit;
4 |
5 | namespace DataTables.Tests;
6 |
7 | public class BinaryExtensionTest
8 | {
9 | [Theory]
10 | [InlineData(0, new byte[] { 0 })]
11 | [InlineData(127, new byte[] { 0x7F })] // 边界值:127
12 | [InlineData(128, new byte[] { 0x80, 0x01 })] // 边界值:128
13 | [InlineData(255, new byte[] { 0xFF, 0x01 })]
14 | [InlineData(16383, new byte[] { 0xFF, 0x7F })] // 边界值:16383
15 | [InlineData(16384, new byte[] { 0x80, 0x80, 0x01 })] // 边界值:16384
16 | [InlineData(int.MaxValue, new byte[] { 0xFF, 0xFF, 0xFF, 0xFF, 0x07 })] // 最大值
17 | [InlineData(1102011, new byte[] { 187, 161, 67 })] // 1102011
18 | public void Write7BitEncodedInt32_WritesCorrectly(int value, byte[] expectedBytes)
19 | {
20 | using var memoryStream = new MemoryStream();
21 | using var binaryWriter = new BinaryWriter(memoryStream);
22 | // 调用 Write7BitEncodedInt32 方法
23 | binaryWriter.Write7BitEncodedInt32(value);
24 |
25 | // 验证写入的数据是否正确
26 | Assert.Equal(expectedBytes, memoryStream.ToArray());
27 | }
28 |
29 | [Theory]
30 | [InlineData(new byte[] { 0 }, 0)]
31 | [InlineData(new byte[] { 0x7F }, 127)] // 边界值:127
32 | [InlineData(new byte[] { 0x80, 0x01 }, 128)] // 边界值:128
33 | [InlineData(new byte[] { 0xFF, 0x01 }, 255)]
34 | [InlineData(new byte[] { 0xFF, 0x7F }, 16383)] // 边界值:16383
35 | [InlineData(new byte[] { 0x80, 0x80, 0x01 }, 16384)] // 边界值:16384
36 | [InlineData(new byte[] { 0xFF, 0xFF, 0xFF, 0xFF, 0x07 }, int.MaxValue)] // 最大值
37 | [InlineData(new byte[] { 187, 161, 67 }, 1102011)] // 最大值
38 | public void Read7BitEncodedInt32_ReadsCorrectly(byte[] inputBytes, int expectedValue)
39 | {
40 | using var memoryStream = new MemoryStream(inputBytes);
41 | using var binaryReader = new BinaryReader(memoryStream);
42 |
43 | // 调用 Read7BitEncodedInt32 方法
44 | int actualValue = binaryReader.Read7BitEncodedInt32();
45 |
46 | // 验证读取的值是否正确
47 | Assert.Equal(expectedValue, actualValue);
48 | }
49 |
50 | [Fact]
51 | public void Read7BitEncodedInt32_ThrowsException_WhenInvalidData()
52 | {
53 | // 模拟无效的数据 (超过最大有效字节数的情况)
54 | byte[] invalidData = new byte[] { 0x80, 0x80, 0x80, 0x80, 0x80, 0x80 };
55 |
56 | using var memoryStream = new MemoryStream(invalidData);
57 | using var binaryReader = new BinaryReader(memoryStream);
58 |
59 | // 验证是否抛出异常
60 | Assert.Throws(() => binaryReader.Read7BitEncodedInt32());
61 | }
62 | }
63 |
--------------------------------------------------------------------------------
/tests/DataTables.Tests/BinarySearchTest.cs:
--------------------------------------------------------------------------------
1 | //using DataTables.Internal;
2 | //using MessagePack.Resolvers;
3 | //using System;
4 | //using System.Collections.Generic;
5 | //using System.Linq;
6 | //using System.Text;
7 | //using System.Threading.Tasks;
8 | //using FluentAssertions;
9 | //using Xunit;
10 | //using MessagePack;
11 |
12 | //namespace DataTables.Tests
13 | //{
14 | // public class BinarySearchTest
15 | // {
16 | // public BinarySearchTest()
17 | // {
18 | // MessagePackSerializer.DefaultOptions = MessagePackSerializer.DefaultOptions.WithResolver(MessagePackResolver.Instance);
19 | // }
20 |
21 | // [Fact]
22 | // public void Find()
23 | // {
24 | // var rand = new Random();
25 | // for (int iii = 0; iii < 30; iii++)
26 | // {
27 | // var seed = Enumerable.Range(1, 10);
28 | // var randomSeed = seed.Where(x => rand.Next() % 2 == 0);
29 |
30 | // var array = randomSeed.Concat(randomSeed).Concat(randomSeed).Concat(randomSeed)
31 | // .OrderBy(x => x)
32 | // .ToArray();
33 |
34 | // for (int i = 1; i <= 10; i++)
35 | // {
36 | // var firstIndex = Array.IndexOf(array, i);
37 | // var lastIndex = Array.LastIndexOf(array, i);
38 |
39 | // var f = BinarySearch.FindFirst(array, i, x => x, Comparer.Default);
40 | // var l = BinarySearch.LowerBound(array, 0, array.Length, i, x => x, Comparer.Default);
41 | // var u = BinarySearch.UpperBound(array, 0, array.Length, i, x => x, Comparer.Default);
42 |
43 | // // not found
44 | // if (firstIndex == -1)
45 | // {
46 | // f.Should().Be(-1);
47 | // l.Should().Be(-1);
48 | // u.Should().Be(-1);
49 | // continue;
50 | // }
51 |
52 | // array[f].Should().Be(i);
53 | // array[l].Should().Be(i);
54 | // array[u].Should().Be(i);
55 |
56 | // l.Should().Be(firstIndex);
57 | // u.Should().Be(lastIndex);
58 | // }
59 | // }
60 |
61 | // // and empty
62 | // var emptyArray = Enumerable.Empty().ToArray();
63 | // BinarySearch.FindFirst(emptyArray, 0, x => x, Comparer.Default).Should().Be(-1);
64 | // BinarySearch.LowerBound(emptyArray, 0, emptyArray.Length, 0, x => x, Comparer.Default).Should().Be(-1);
65 | // BinarySearch.UpperBound(emptyArray, 0, emptyArray.Length, 0, x => x, Comparer.Default).Should().Be(-1);
66 | // }
67 |
68 | // [Fact]
69 | // public void Closest()
70 | // {
71 | // // empty
72 | // var array = Enumerable.Empty().ToArray();
73 |
74 | // var near = BinarySearch.FindClosest(array, 0, 0, array.Length, x => x, Comparer.Default, false);
75 | // near.Should().Be(-1);
76 |
77 | // // mid
78 | // var source = new[]{
79 | // new { id = 0, bound = 0 },
80 | // new { id = 1, bound = 100 },
81 | // new { id = 2, bound = 200 },
82 | // new { id = 3, bound = 300 },
83 | // new { id = 4, bound = 500 },
84 | // new { id = 5, bound = 1000 },
85 | // };
86 |
87 | // BinarySearch.FindClosest(source, 0, source.Length, -100, x => x.bound, Comparer.Default, true).Should().Be(-1);
88 | //// BinarySearch.FindClosest(source, 0, source.Length, -100, x => x.bound, Comparer.Default, true).Should().Be(0);
89 | // BinarySearch.FindClosest(source, 0, source.Length, 0, x => x.bound, Comparer.Default, true).Should().Be(0);
90 | // BinarySearch.FindClosest(source, 0, source.Length, 10, x => x.bound, Comparer.Default, true).Should().Be(0);
91 | // BinarySearch.FindClosest(source, 0, source.Length, 50, x => x.bound, Comparer.Default, true).Should().Be(0);
92 |
93 | // source[BinarySearch.FindClosest(source, 0, source.Length, 100, x => x.bound, Comparer.Default, true)].id.Should().Be(1);
94 | // source[BinarySearch.FindClosest(source, 0, source.Length, 100, x => x.bound, Comparer.Default, false)].id.Should().Be(1);
95 |
96 | // source[BinarySearch.FindClosest(source, 0, source.Length, 150, x => x.bound, Comparer.Default, true)].id.Should().Be(1);
97 | // source[BinarySearch.FindClosest(source, 0, source.Length, 300, x => x.bound, Comparer.Default, true)].id.Should().Be(3);
98 | // source[BinarySearch.FindClosest(source, 0, source.Length, 999, x => x.bound, Comparer.Default, true)].id.Should().Be(4);
99 | // source[BinarySearch.FindClosest(source, 0, source.Length, 1000, x => x.bound, Comparer.Default, true)].id.Should().Be(5);
100 | // source[BinarySearch.FindClosest(source, 0, source.Length, 1001, x => x.bound, Comparer.Default, true)].id.Should().Be(5);
101 | // source[BinarySearch.FindClosest(source, 0, source.Length, 10000, x => x.bound, Comparer.Default, true)].id.Should().Be(5);
102 | //// source[BinarySearch.FindClosest(source, 0, source.Length, 10000, x => x.bound, Comparer.Default, false)].id.Should().Be(5);
103 |
104 | // BinarySearch.FindClosest(source, 0, source.Length, 10000, x => x.bound, Comparer.Default, false).Should().Be(6);
105 | // }
106 | // }
107 | //}
108 |
--------------------------------------------------------------------------------
/tests/DataTables.Tests/DataTableProcessTest.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Linq;
4 | using FluentAssertions;
5 | using Xunit;
6 |
7 | namespace DataTables.Tests
8 | {
9 | public class DataTableProcessTest
10 | {
11 | private static string ConvertToDigit(int num)
12 | {
13 | if (num < 26)
14 | {
15 | return Convert.ToString((char)('A' + num));
16 | }
17 | else
18 | {
19 | return ConvertToDigit(num / 26 - 1) + ConvertToDigit(num % 26);
20 | }
21 | }
22 |
23 | [Fact]
24 | public void ConvertNumberToLetterTest()
25 | {
26 | ConvertToDigit(0).Should().Be("A");
27 | ConvertToDigit(25).Should().Be("Z");
28 | ConvertToDigit(26).Should().Be("AA");
29 | ConvertToDigit(27).Should().Be("AB");
30 | ConvertToDigit(27 * 26).Should().Be("AAA");
31 | }
32 | }
33 | }
34 |
--------------------------------------------------------------------------------
/tests/DataTables.Tests/DataTables.Tests.csproj:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | net8.0
5 | false
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 | all
14 | runtime; build; native; contentfiles; analyzers; buildtransitive
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
--------------------------------------------------------------------------------
/tests/DataTables.Tests/IssueTest.cs:
--------------------------------------------------------------------------------
1 | //using FluentAssertions;
2 | //using DataTables.Tests.TestStructures;
3 | //using System;
4 | //using System.Collections.Generic;
5 | //using System.Linq;
6 | //using System.Text;
7 | //using Xunit;
8 |
9 | //namespace DataTables.Tests
10 | //{
11 | // public class IssueTest
12 | // {
13 | // //[Fact]
14 | // //public void Issue49()
15 | // //{
16 | // // var builder = new DatabaseBuilder().Append(new[]
17 | // // {
18 | // // new PersonModel { FirstName = "realname", LastName="reallast" },
19 | // // new PersonModel { FirstName = "fakefirst", LastName="fakelast" },
20 | // // });
21 |
22 | // // var data = builder.Build();
23 | // // var database = new MemoryDatabase(data);
24 |
25 | // // var entries = database.PersonModelTable.FindClosestByFirstNameAndLastName(("real", "real"), false);
26 | // // var firstEntry = entries.FirstOrDefault();
27 |
28 | // // var firstIs = firstEntry.FirstName;
29 |
30 | // //}
31 |
32 | // Sample[] CreateData()
33 | // {
34 | // // Id = Unique, PK
35 | // // FirstName + LastName = Unique
36 | // var data = new[]
37 | // {
38 | // new Sample { Id = 5, Age = 19, FirstName = "aaa", LastName = "foo" },
39 | // new Sample { Id = 6, Age = 29, FirstName = "bbb", LastName = "foo" },
40 | // new Sample { Id = 7, Age = 39, FirstName = "ccc", LastName = "foo" },
41 | // new Sample { Id = 8, Age = 49, FirstName = "ddd", LastName = "foo" },
42 | // new Sample { Id = 1, Age = 59, FirstName = "eee", LastName = "foo" },
43 | // new Sample { Id = 2, Age = 89, FirstName = "aaa", LastName = "bar" },
44 | // new Sample { Id = 3, Age = 79, FirstName = "be", LastName = "de" },
45 | // new Sample { Id = 4, Age = 89, FirstName = "aaa", LastName = "tako" },
46 | // new Sample { Id = 9, Age = 99, FirstName = "aaa", LastName = "ika" },
47 | // new Sample { Id = 10, Age = 9, FirstName = "eee", LastName = "baz" },
48 | // };
49 | // return data;
50 | // }
51 |
52 | // [Fact]
53 | // public void Issue57()
54 | // {
55 | // var builder = new DatabaseBuilder();
56 | // builder.Append(CreateData());
57 |
58 | // var bin = builder.Build();
59 | // var db = new MemoryDatabase(bin);
60 |
61 | // db.SampleTable.FindRangeByAge(2, 2).Select(x => x.Id).ToArray().Should().BeEquivalentTo(new int[] { });
62 | // db.SampleTable.FindRangeByAge(30, 50).Select(x => x.Id).ToArray().Should().BeEquivalentTo(new int[] { 7, 8 });
63 | // db.SampleTable.FindRangeByAge(100, 100).Select(x => x.Id).ToArray().Should().BeEquivalentTo(new int[] { });
64 | // }
65 |
66 | // }
67 | //}
68 |
--------------------------------------------------------------------------------
/tests/DataTables.Tests/MemoryKeyTest.cs:
--------------------------------------------------------------------------------
1 | //using Xunit;
2 | //using System.Linq;
3 | //using DataTables.Tests.Tables;
4 | //using FluentAssertions;
5 | //using MessagePack;
6 | //using System.Collections.Generic;
7 |
8 | //namespace DataTables.Tests
9 | //{
10 | // public class MemoryKeyMemoryTest
11 | // {
12 | // public MemoryKeyMemoryTest()
13 | // {
14 | // MessagePackSerializer.DefaultOptions = MessagePackSerializer.DefaultOptions.WithResolver(MessagePackResolver.Instance);
15 | // }
16 |
17 | // Sample[] CreateData()
18 | // {
19 | // // Id = Unique, PK
20 | // // FirstName + LastName = Unique
21 | // var data = new[]
22 | // {
23 | // new Sample { Id = 5, Age = 19, FirstName = "aaa", LastName = "foo" },
24 | // new Sample { Id = 6, Age = 29, FirstName = "bbb", LastName = "foo" },
25 | // new Sample { Id = 7, Age = 39, FirstName = "ccc", LastName = "foo" },
26 | // new Sample { Id = 8, Age = 49, FirstName = "ddd", LastName = "foo" },
27 | // new Sample { Id = 1, Age = 59, FirstName = "eee", LastName = "foo" },
28 | // new Sample { Id = 2, Age = 89, FirstName = "aaa", LastName = "bar" },
29 | // new Sample { Id = 3, Age = 79, FirstName = "be", LastName = "de" },
30 | // new Sample { Id = 4, Age = 89, FirstName = "aaa", LastName = "tako" },
31 | // new Sample { Id = 9, Age = 99, FirstName = "aaa", LastName = "ika" },
32 | // new Sample { Id = 10, Age = 9, FirstName = "eee", LastName = "baz" },
33 | // };
34 | // return data;
35 | // }
36 |
37 | // SampleTable CreateTable()
38 | // {
39 | // return new MemoryDatabase(new DatabaseBuilder().Append(CreateData()).Build()).SampleTable;
40 | // }
41 |
42 | // [Fact]
43 | // public void Unique()
44 | // {
45 | // var table = CreateTable();
46 |
47 | // table.FindById(8).Id.Should().Be(8);
48 | // Assert.Throws(() => table.FindById(100));
49 |
50 | // table.FindByIdAndAge((4, 89)).Id.Should().Be(4);
51 |
52 | // Assert.Throws(() => table.FindByIdAndAge((4, 899)));
53 | // Assert.Throws(() => table.FindByIdAndAge((5, 89)));
54 |
55 | // table.FindByIdAndAgeAndFirstName((6, 29, "bbb")).Id.Should().Be(6);
56 | // Assert.Throws(() => table.FindByIdAndAgeAndFirstName((6, 29, "bbbz")));
57 | // }
58 |
59 | // [Fact]
60 | // public void Range()
61 | // {
62 | // var table = CreateTable();
63 |
64 | // var test = table.FindByFirstName("eee");
65 |
66 | // table.FindByFirstName("eee").Select(x => x.Id).OrderBy(x => x).Should().BeEquivalentTo(new[] { 1, 10 });
67 | // table.FindByFirstName("eeee").Count.Should().Be(0);
68 |
69 | // table.FindClosestByFirstNameAndLastName(("aaa", "takz")).Id.Should().Be(4);
70 | // }
71 | // }
72 | //}
73 |
--------------------------------------------------------------------------------
/tests/DataTables.Tests/MessagePackResolver.cs:
--------------------------------------------------------------------------------
1 | //using MessagePack;
2 | //using MessagePack.Formatters;
3 | //using MessagePack.Resolvers;
4 | //using System;
5 | //using System.Collections.Generic;
6 | //using System.Text;
7 |
8 | //namespace DataTables.Tests
9 | //{
10 | // public class MessagePackResolver : IFormatterResolver
11 | // {
12 | // public static IFormatterResolver Instance = new MessagePackResolver();
13 |
14 | // MessagePackResolver()
15 | // {
16 |
17 | // }
18 |
19 | // public IMessagePackFormatter GetFormatter()
20 | // {
21 | // return MasterMemoryResolver.Instance.GetFormatter()
22 | // ?? GeneratedResolver.Instance.GetFormatter()
23 | // ?? StandardResolver.Instance.GetFormatter();
24 | // }
25 | // }
26 | //}
27 |
--------------------------------------------------------------------------------
/tests/DataTables.Tests/MetaTest.cs:
--------------------------------------------------------------------------------
1 | //using System;
2 | //using FluentAssertions;
3 | //using System.Collections.Generic;
4 | //using System.Text;
5 | //using Xunit;
6 |
7 | //namespace DataTables.Tests
8 | //{
9 | // public class MetaTest
10 | // {
11 | // [Fact]
12 | // public void Meta()
13 | // {
14 | // var metaDb = MemoryDatabase.GetMetaDatabase();
15 |
16 | // var sampleTable = metaDb.GetTableInfo("s_a_m_p_l_e");
17 |
18 | // sampleTable.TableName.Should().Be("s_a_m_p_l_e");
19 |
20 | // sampleTable.Properties[0].Name.Should().Be("Id");
21 | // sampleTable.Properties[0].NameLowerCamel.Should().Be("id");
22 | // sampleTable.Properties[0].NameSnakeCase.Should().Be("id");
23 |
24 | // sampleTable.Properties[2].Name.Should().Be("FirstName");
25 | // sampleTable.Properties[2].NameLowerCamel.Should().Be("firstName");
26 | // sampleTable.Properties[2].NameSnakeCase.Should().Be("first_name");
27 |
28 | // var primary = sampleTable.Indexes[0];
29 | // primary.IsUnique.Should().BeTrue();
30 | // primary.IndexProperties[0].Name.Should().Be("Id");
31 | // }
32 | // }
33 | //}
34 |
--------------------------------------------------------------------------------
/tests/DataTables.Tests/RangeViewTest.cs:
--------------------------------------------------------------------------------
1 | //using FluentAssertions;
2 | //using System;
3 | //using System.Collections;
4 | //using System.Collections.Generic;
5 | //using System.Linq;
6 | //using Xunit;
7 |
8 | //namespace DataTables.Tests
9 | //{
10 | // public class RangeViewTest
11 | // {
12 | // [Fact]
13 | // public void Range()
14 | // {
15 | // // 4 -> 8
16 | // {
17 | // var range = new RangeView(new[] { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 }, 4, 8, true);
18 |
19 | // range.Count.Should().Be(5);
20 | // range[0].Should().Be(4);
21 | // range[1].Should().Be(5);
22 | // range[2].Should().Be(6);
23 | // range[3].Should().Be(7);
24 | // range[4].Should().Be(8);
25 |
26 | // Assert.Throws(() => range[-1]);
27 | // Assert.Throws(() => range[5]);
28 |
29 | // var begin = 4;
30 | // foreach (var item in range)
31 | // {
32 | // item.Should().Be(begin++);
33 | // }
34 |
35 | // var xs = new int[10];
36 | // range.CopyTo(xs, 3);
37 | // xs[3].Should().Be(4);
38 | // xs[4].Should().Be(5);
39 | // xs[5].Should().Be(6);
40 | // xs[6].Should().Be(7);
41 | // xs[7].Should().Be(8);
42 | // xs[8].Should().Be(0);
43 |
44 | // range.IndexOf(5).Should().Be(1);
45 | // range.IndexOf(9).Should().Be(-1);
46 |
47 |
48 | // range.Contains(5).Should().BeTrue();
49 | // range.Contains(9).Should().BeFalse();
50 | // }
51 | // {
52 | // // 7 -> 2
53 | // var range = new RangeView(new[] { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 }, 2, 7, false);
54 |
55 | // range.Count.Should().Be(6);
56 | // range[0].Should().Be(7);
57 | // range[1].Should().Be(6);
58 | // range[2].Should().Be(5);
59 | // range[3].Should().Be(4);
60 | // range[4].Should().Be(3);
61 | // range[5].Should().Be(2);
62 |
63 | // Assert.Throws(() => range[-1]);
64 | // Assert.Throws(() => range[6]);
65 |
66 | // var begin = 7;
67 | // foreach (var item in range)
68 | // {
69 | // item.Should().Be(begin--);
70 | // }
71 |
72 | // var xs = new int[10];
73 | // range.CopyTo(xs, 3);
74 | // xs[3].Should().Be(7);
75 | // xs[4].Should().Be(6);
76 | // xs[5].Should().Be(5);
77 | // xs[6].Should().Be(4);
78 | // xs[7].Should().Be(3);
79 | // xs[8].Should().Be(2);
80 |
81 | // range.IndexOf(5).Should().Be(2);
82 | // range.IndexOf(9).Should().Be(-1);
83 |
84 | // range.Contains(5).Should().BeTrue();
85 | // range.Contains(9).Should().BeFalse();
86 | // }
87 |
88 | // var empty = new RangeView(Enumerable.Empty().ToArray(), 0, 0, true);
89 | // empty.Count.Should().Be(0);
90 |
91 | // var same = new RangeView(Enumerable.Range(1, 1000).ToArray(), 100, 100, true);
92 | // same.Count.Should().Be(1);
93 | // same[0].Should().Be(101);
94 | // }
95 | // }
96 | //}
97 |
--------------------------------------------------------------------------------
/tools/PostBuildUtility/PostBuildUtility.csproj:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | Exe
5 | net8.0
6 | Debug;Release;
7 | false
8 |
9 |
10 |
11 |
12 | all
13 | runtime; build; native; contentfiles; analyzers; buildtransitive
14 |
15 |
16 |
17 |
18 |
--------------------------------------------------------------------------------
/tools/PostBuildUtility/Program.cs:
--------------------------------------------------------------------------------
1 | using System.Collections.Generic;
2 | using System.IO;
3 | using System.Text;
4 | using ConsoleAppFramework;
5 |
6 | ConsoleApp.Run(args, (string directory) =>
7 | {
8 | const string GlobalUsingString = """
9 | using System;
10 | using System.Collections.Generic;
11 | using System.IO;
12 | using System.Linq;
13 | using System.Net.Http;
14 | using System.Threading;
15 | using System.Threading.Tasks;
16 |
17 | #nullable enable
18 |
19 | """;
20 |
21 | var replaceSet = new Dictionary
22 | {
23 | // to C# 9
24 | { "scoped ref", "ref" },
25 | { "scoped in", "in" },
26 | { "scoped Span", "Span" },
27 | { "scoped ReadOnlySpan", "ReadOnlySpan" },
28 | { "file static", "internal static" },
29 | // remove for IL2CPP safety
30 | { "Serialize", "Serialize" },
31 | { "", "" },
32 | { "", ">" },
34 | { "where TBufferWriter : class, IBufferWriter;", ";" },
35 | { "where TBufferWriter : class, IBufferWriter", "" },
36 | { "where TBufferWriter : IBufferWriter", "" },
37 | { "MemoryPackWriter", "MemoryPackWriter" },
38 | { "TBufferWriter", "IBufferWriter" },
39 | {
40 | "new MemoryPackWriter(ref bufferWriter",
41 | "new MemoryPackWriter(ref Unsafe.As>(ref bufferWriter)"
42 | },
43 | {
44 | "new MemoryPackWriter(ref tempBuffer",
45 | "new MemoryPackWriter(ref Unsafe.As>(ref tempBuffer)"
46 | },
47 | {
48 | "new MemoryPackWriter(ref state.BufferWriter",
49 | "new MemoryPackWriter(ref Unsafe.As>(ref state.BufferWriter)"
50 | },
51 | {
52 | "new MemoryPackWriter(ref compressor",
53 | "new MemoryPackWriter(ref Unsafe.As>(ref compressor)"
54 | },
55 | };
56 |
57 | System.Console.WriteLine("Start to modify code.");
58 | var noBomUtf8 = new UTF8Encoding(false);
59 |
60 | foreach (var path in Directory.EnumerateFiles(directory, "*.cs", SearchOption.AllDirectories))
61 | {
62 | var text = File.ReadAllText(path, Encoding.UTF8);
63 |
64 | // replace
65 | foreach (var item in replaceSet)
66 | {
67 | text = text.Replace(item.Key, item.Value);
68 | }
69 |
70 | // add namespace
71 | // if (Regex.Count(text, "namespace") == 1)
72 | // {
73 | // text = Regex.Replace(text, "(namespace.+);", "$1 {");
74 | // text += "\r\n}";
75 | // }
76 |
77 | // add implicit global using and nullable enable
78 | if (!text.StartsWith(GlobalUsingString))
79 | {
80 | text = GlobalUsingString + text;
81 | }
82 |
83 | File.WriteAllText(path, text, noBomUtf8);
84 | }
85 |
86 | System.Console.WriteLine("Copy complete.");
87 | });
88 |
--------------------------------------------------------------------------------