SimpleREST.NET 0.1
A simple and minimal api framework for .net base on Express.js
Loading...
Searching...
No Matches
SimpleRestContentTypeParser.cs
Go to the documentation of this file.
1namespace SimpleRest.Api;
2
4{
5 Dictionary<Type, string> contentTypes = new Dictionary<Type, string>
6 {
7 { typeof(string), "text/plain" },
8 { typeof(int), "text/plain" },
9 { typeof(float), "text/plain" },
10 { typeof(double), "text/plain" },
11 { typeof(decimal), "text/plain" },
12 { typeof(bool), "text/plain" },
13 { typeof(byte), "application/octet-stream" },
14 { typeof(byte[]), "application/octet-stream" },
15 { typeof(DateTime), "application/json" }, // Serialize dates as JSON
16 { typeof(Guid), "application/json" }, // Serialize GUIDs as JSON
17 { typeof(object), "application/json" }, // Serialize custom objects as JSON
18 };
19 public Dictionary<Type, string> ContentTypes
20 {
21 get => contentTypes;
22 }
23
24 public string GetType<T>()
25 {
26 if (contentTypes.ContainsKey(typeof(T)))
27 { return contentTypes[typeof(T)]; }
28
29 else
30 {
31 return contentTypes[typeof(object)];
32 }
33 }
34}
string GetType< T >()
Converts a .NET or custom type into an http content type.