@@ -65,6 +65,82 @@ dotnet test Presidio.slnx --configuration Release
6565
6666> We always run ` dotnet format ` before ` dotnet test ` to ensure consistent styling across the solution.
6767
68+ ### Usage Examples
69+
70+ The .NET APIs mirror the Python surface. The snippets below show the most common entry points.
71+
72+ #### Anonymizing raw text
73+
74+ ``` csharp
75+ using System .Collections .Generic ;
76+ using ManagedCode .Presidio .Anonymizer ;
77+ using ManagedCode .Presidio .Core ;
78+
79+ var recognizerResults = new []
80+ {
81+ new ManagedCode .Presidio .Core .RecognizerResult (" PERSON" , new TextSpan (11 , 16 ), 0 . 85 ),
82+ };
83+
84+ var anonymizer = new AnonymizerEngine ();
85+ var result = anonymizer .Anonymize (
86+ " My name is James Bond" ,
87+ recognizerResults ,
88+ new Dictionary <string , OperatorConfig >
89+ {
90+ [" PERSON" ] = new OperatorConfig (" replace" , new Dictionary <string , object ?>
91+ {
92+ [ReplaceOperator .NewValueKey ] = " Agent"
93+ })
94+ });
95+
96+ // result.Text == "My name is Agent Bond"
97+ ```
98+
99+ #### Working with collections (BatchAnonymizerEngine)
100+
101+ ``` csharp
102+ using System .Collections .Generic ;
103+ using ManagedCode .Presidio .Anonymizer ;
104+
105+ var batch = new BatchAnonymizerEngine (anonymizer );
106+
107+ var response = batch .AnonymizeDict (new []
108+ {
109+ new DictRecognizerResult (
110+ " names" ,
111+ new [] { " John" , " Jill" },
112+ new []
113+ {
114+ new [] { new ManagedCode .Presidio .Anonymizer .RecognizerResult (" PERSON" , 0 , 4 , 0 . 9 ) },
115+ new [] { new ManagedCode .Presidio .Anonymizer .RecognizerResult (" PERSON" , 0 , 4 , 0 . 9 ) },
116+ })
117+ });
118+
119+ // response["names"] == ["<PERSON>", "<PERSON>"]
120+ ```
121+
122+ #### Deanonymizing previously encrypted entities
123+
124+ ``` csharp
125+ using System .Collections .Generic ;
126+ using ManagedCode .Presidio .Anonymizer ;
127+
128+ var deanonymizer = new DeanonymizeEngine ();
129+
130+ var decrypted = deanonymizer .Deanonymize (
131+ cipherText : " My name is S184CMt9Drj7QaKQ21JTrpYzghnboTF9pn/neN8JME0=" ,
132+ entities : new [] { new OperatorResult (11 , 55 , " PERSON" ) },
133+ operators : new Dictionary <string , OperatorConfig >
134+ {
135+ [" DEFAULT" ] = new OperatorConfig (" decrypt" , new Dictionary <string , object ?>
136+ {
137+ [EncryptOperator .KeyParameter ] = " WmZq4t7w!z%C&F)J" ,
138+ })
139+ });
140+
141+ // decrypted.Text == "My name is Chloë"
142+ ```
143+
68144---
69145
70146## Python Reference Submodule
0 commit comments