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.
1
namespace
SimpleRest.Api
;
2
3
public
class
SimpleRestContentTypeParser
:
ISimpleRestContentTypeParser
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
}
SimpleRest.Api.SimpleRestContentTypeParser
Definition
SimpleRestContentTypeParser.cs:4
SimpleRest.Api.SimpleRestContentTypeParser.GetType< T >
string GetType< T >()
Converts a .NET or custom type into an http content type.
Definition
SimpleRestContentTypeParser.cs:24
SimpleRest.Api.SimpleRestContentTypeParser.ContentTypes
Dictionary< Type, string > ContentTypes
Definition
SimpleRestContentTypeParser.cs:20
SimpleRest.Api.ISimpleRestContentTypeParser
Definition
ISimpleRestContentTypeParser.cs:3
SimpleRest.Api
Definition
Enums.cs:1
Src
Default types
SimpleRestContentTypeParser.cs
Generated by
1.12.0