Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
N
netcoreplus
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
tsai
netcoreplus
Commits
dbf60efb
Commit
dbf60efb
authored
May 18, 2019
by
阿星Plus
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
序列化扩展
parent
b48125db
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
109 additions
and
7 deletions
+109
-7
Extensions.cs
Plus.Extensions.Serialization/Extensions.cs
+84
-0
Plus.Extensions.Serialization.csproj
...nsions.Serialization/Plus.Extensions.Serialization.csproj
+11
-0
Plus.sln
Plus.sln
+14
-7
No files found.
Plus.Extensions.Serialization/Extensions.cs
0 → 100644
View file @
dbf60efb
using
Newtonsoft.Json
;
using
System.IO
;
using
System.Runtime.Serialization.Formatters.Binary
;
using
System.Text
;
using
System.Xml.Serialization
;
/// <summary>
/// Extensions
/// </summary>
public
static
class
Extensions
{
public
static
string
SerializeBinary
<
T
>(
this
T
@this
)
{
BinaryFormatter
binaryFormatter
=
new
BinaryFormatter
();
using
(
MemoryStream
memoryStream
=
new
MemoryStream
())
{
binaryFormatter
.
Serialize
(
memoryStream
,
@this
);
return
Encoding
.
Default
.
GetString
(
memoryStream
.
ToArray
());
}
}
public
static
string
SerializeBinary
<
T
>(
this
T
@this
,
Encoding
encoding
)
{
BinaryFormatter
binaryFormatter
=
new
BinaryFormatter
();
using
(
MemoryStream
memoryStream
=
new
MemoryStream
())
{
binaryFormatter
.
Serialize
(
memoryStream
,
@this
);
return
encoding
.
GetString
(
memoryStream
.
ToArray
());
}
}
public
static
string
SerializeToJson
(
this
object
input
)
{
return
JsonConvert
.
SerializeObject
(
input
);
}
public
static
string
SerializeXml
(
this
object
@this
)
{
XmlSerializer
xmlSerializer
=
new
XmlSerializer
(
@this
.
GetType
());
using
(
StringWriter
stringWriter
=
new
StringWriter
())
{
xmlSerializer
.
Serialize
(
stringWriter
,
@this
);
using
(
StringReader
stringReader
=
new
StringReader
(
stringWriter
.
GetStringBuilder
().
ToString
()))
{
return
stringReader
.
ReadToEnd
();
}
}
}
public
static
T
DeserializeBinary
<
T
>(
this
string
@this
)
{
using
(
MemoryStream
serializationStream
=
new
MemoryStream
(
Encoding
.
Default
.
GetBytes
(
@this
)))
{
BinaryFormatter
binaryFormatter
=
new
BinaryFormatter
();
return
(
T
)
binaryFormatter
.
Deserialize
(
serializationStream
);
}
}
public
static
T
DeserializeBinary
<
T
>(
this
string
@this
,
Encoding
encoding
)
{
using
(
MemoryStream
serializationStream
=
new
MemoryStream
(
encoding
.
GetBytes
(
@this
)))
{
BinaryFormatter
binaryFormatter
=
new
BinaryFormatter
();
return
(
T
)
binaryFormatter
.
Deserialize
(
serializationStream
);
}
}
public
static
T
DeserializeFromJson
<
T
>(
this
string
input
)
{
return
JsonConvert
.
DeserializeObject
<
T
>(
input
);
}
public
static
T
DeserializeFromJson
<
T
>(
this
object
input
)
{
return
JsonConvert
.
DeserializeObject
<
T
>(
input
.
ToString
());
}
public
static
T
DeserializeXml
<
T
>(
this
string
@this
)
{
XmlSerializer
xmlSerializer
=
new
XmlSerializer
(
typeof
(
T
));
StringReader
textReader
=
new
StringReader
(
@this
);
return
(
T
)
xmlSerializer
.
Deserialize
(
textReader
);
}
}
\ No newline at end of file
Plus.Extensions.Serialization/Plus.Extensions.Serialization.csproj
0 → 100644
View file @
dbf60efb
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>netstandard2.0</TargetFramework>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Newtonsoft.Json" Version="12.0.2" />
</ItemGroup>
</Project>
Plus.sln
View file @
dbf60efb
...
...
@@ -17,19 +17,21 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "solution-items", "solution-
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Plus", "src\Plus\Plus.csproj", "{7C852EAF-CCB3-48D1-9F11-E8606C3D4A2D}"
EndProject
Project("{
FAE04EC0-301F-11D3-BF4B-00C04F79EFBC
}") = "Plus.EntityFramework", "src\Plus.EntityFramework\Plus.EntityFramework.csproj", "{6B20C811-655C-41DF-A97B-CA40A69B72AB}"
Project("{
9A19103F-16F7-4668-BE54-9A1E7A4F7556
}") = "Plus.EntityFramework", "src\Plus.EntityFramework\Plus.EntityFramework.csproj", "{6B20C811-655C-41DF-A97B-CA40A69B72AB}"
EndProject
Project("{
FAE04EC0-301F-11D3-BF4B-00C04F79EFBC
}") = "Plus.AutoMapper", "src\Plus.AutoMapper\Plus.AutoMapper.csproj", "{FA94B550-907C-4EAD-B668-BB9549FBE835}"
Project("{
9A19103F-16F7-4668-BE54-9A1E7A4F7556
}") = "Plus.AutoMapper", "src\Plus.AutoMapper\Plus.AutoMapper.csproj", "{FA94B550-907C-4EAD-B668-BB9549FBE835}"
EndProject
Project("{
FAE04EC0-301F-11D3-BF4B-00C04F79EFBC
}") = "Plus.Extensions", "src\Plus.Extensions\Plus.Extensions.csproj", "{57C2FEB2-A915-47CE-81CE-C1399C392C3B}"
Project("{
9A19103F-16F7-4668-BE54-9A1E7A4F7556
}") = "Plus.Extensions", "src\Plus.Extensions\Plus.Extensions.csproj", "{57C2FEB2-A915-47CE-81CE-C1399C392C3B}"
EndProject
Project("{
FAE04EC0-301F-11D3-BF4B-00C04F79EFBC
}") = "Plus.Log4Net", "src\Plus.Log4Net\Plus.Log4Net.csproj", "{F4631747-89D2-4EA8-8684-9217D463D4C6}"
Project("{
9A19103F-16F7-4668-BE54-9A1E7A4F7556
}") = "Plus.Log4Net", "src\Plus.Log4Net\Plus.Log4Net.csproj", "{F4631747-89D2-4EA8-8684-9217D463D4C6}"
EndProject
Project("{
FAE04EC0-301F-11D3-BF4B-00C04F79EFBC
}") = "Plus.MongoDB", "src\Plus.MongoDB\Plus.MongoDB.csproj", "{289760B5-2E69-4D9F-8F1F-2D80EA1FC36D}"
Project("{
9A19103F-16F7-4668-BE54-9A1E7A4F7556
}") = "Plus.MongoDB", "src\Plus.MongoDB\Plus.MongoDB.csproj", "{289760B5-2E69-4D9F-8F1F-2D80EA1FC36D}"
EndProject
Project("{
FAE04EC0-301F-11D3-BF4B-00C04F79EFBC
}") = "Plus.RedisCache", "src\Plus.RedisCache\Plus.RedisCache.csproj", "{BBCB7D18-8BA5-461A-B3B2-3E9A79EDA6FB}"
Project("{
9A19103F-16F7-4668-BE54-9A1E7A4F7556
}") = "Plus.RedisCache", "src\Plus.RedisCache\Plus.RedisCache.csproj", "{BBCB7D18-8BA5-461A-B3B2-3E9A79EDA6FB}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Plus.Dapper", "src\Plus.Dapper\Plus.Dapper.csproj", "{33696E1A-23DA-4FF2-9DD9-2FA8C6822606}"
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Plus.Dapper", "src\Plus.Dapper\Plus.Dapper.csproj", "{33696E1A-23DA-4FF2-9DD9-2FA8C6822606}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Plus.Extensions.Serialization", "Plus.Extensions.Serialization\Plus.Extensions.Serialization.csproj", "{209BF4EB-311F-45AD-AED6-F314A49D83C7}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
...
...
@@ -69,6 +71,10 @@ Global
{33696E1A-23DA-4FF2-9DD9-2FA8C6822606}.Debug|Any CPU.Build.0 = Debug|Any CPU
{33696E1A-23DA-4FF2-9DD9-2FA8C6822606}.Release|Any CPU.ActiveCfg = Release|Any CPU
{33696E1A-23DA-4FF2-9DD9-2FA8C6822606}.Release|Any CPU.Build.0 = Release|Any CPU
{209BF4EB-311F-45AD-AED6-F314A49D83C7}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{209BF4EB-311F-45AD-AED6-F314A49D83C7}.Debug|Any CPU.Build.0 = Debug|Any CPU
{209BF4EB-311F-45AD-AED6-F314A49D83C7}.Release|Any CPU.ActiveCfg = Release|Any CPU
{209BF4EB-311F-45AD-AED6-F314A49D83C7}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
...
...
@@ -82,6 +88,7 @@ Global
{289760B5-2E69-4D9F-8F1F-2D80EA1FC36D} = {CC63505F-AC28-4DCE-93F6-82062FA5EDC3}
{BBCB7D18-8BA5-461A-B3B2-3E9A79EDA6FB} = {CC63505F-AC28-4DCE-93F6-82062FA5EDC3}
{33696E1A-23DA-4FF2-9DD9-2FA8C6822606} = {CC63505F-AC28-4DCE-93F6-82062FA5EDC3}
{209BF4EB-311F-45AD-AED6-F314A49D83C7} = {CC63505F-AC28-4DCE-93F6-82062FA5EDC3}
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {44529F52-F5EE-4330-BB68-E09EB8B967E3}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment