ip2region_private/binding/csharp
Argo Zhang 75d944eaf7 doc: 增加类注释 2025-11-21 08:52:17 +08:00
..
IP2Region.Net doc: 增加类注释 2025-11-21 08:52:17 +08:00
IP2Region.Net.BenchMark chore: 更新 BenchMark 工程 2025-11-21 08:15:23 +08:00
IP2Region.Net.Test chore: 单元测试框架更改为 net10 2025-11-20 17:52:48 +08:00
.editorconfig chore: 增加 editorconfig 配置文件 2025-11-21 08:52:07 +08:00
.gitignore C# 版 2022-07-06 18:00:09 +08:00
CHANGELOG.md docs:support netstandard2.0 2023-07-30 17:54:14 +08:00
IP2Region.Net.slnx chore: 增加 editorconfig 配置文件 2025-11-21 08:52:07 +08:00
README.md doc: 更新 readme 文档 2025-10-19 17:37:09 +08:00

README.md

IP2Region.Net

.NET client library for IP2Region

Installation

Install the package with NuGet

Install-Package IP2Region.Net

Usage

using IP2Region.Net.Abstractions;
using IP2Region.Net.XDB;

ISearcher searcher = new Searcher(CachePolicy , "your xdb file path");

Cache Policy Description

Cache Policy Description Thread Safe
CachePolicy.Content Cache the entire xdb data. Yes
CachePolicy.VectorIndex Cache vecotorIndex to speed up queries and reduce system io pressure by reducing one fixed IO operation. Yes
CachePolicy.File Completely file-based queries Yes

XDB File Description

Generate using maker, or download pre-generated xdb files

ASP.NET Core Usage

services.AddIP2RegionService("your xdb file path", cachePolicy: CachePolicy.Content);

NET6/7

provider.GetRequiredService<ISearcher>()

NET8+ support keyed service

provider.GetRequiredKeyedService<ISearcher>("IP2Region.Net");

Performance

BenchmarkDotNet=v0.13.2, OS=macOS 13.4.1 (c) (22F770820d) [Darwin 22.5.0]
Apple M1, 1 CPU, 8 logical and 8 physical cores
.NET SDK=7.0.306
  [Host]     : .NET 6.0.20 (6.0.2023.32017), Arm64 RyuJIT AdvSIMD
  DefaultJob : .NET 6.0.20 (6.0.2023.32017), Arm64 RyuJIT AdvSIMD
Method Mean Error StdDev
CachePolicy_Content 58.32 ns 0.182 ns 0.170 ns
CachePolicy_File 16,417.56 ns 50.569 ns 47.302 ns
CachePolicy_VectorIndex 9,348.11 ns 38.492 ns 65.363 ns

Contributing

Pull requests are welcome. For major changes, please open an issue first to discuss what you would like to change.

Please make sure to update tests as appropriate.

License

Apache License 2.0