Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Avoid SocketException scenario (Udp -- Mono) #387

Closed
wants to merge 161 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
161 commits
Select commit Hold shift + click to select a range
07dbbfc
adapted push script
kerryjiang Sep 25, 2013
5b46f4c
updated assembly version to 1.6.4
kerryjiang Sep 26, 2013
7c3f3f4
fixed the reference issue of SSSM SL Client
kerryjiang Oct 9, 2013
432272d
fixed a bug in TerminatorReceiveFilter that wrong prevMatched value u…
kerryjiang Oct 16, 2013
240c237
Removed unused exception parameter
kerryjiang Oct 24, 2013
53cbb83
improved the build scripts
kerryjiang Oct 24, 2013
f7d65ca
improved release making task file
kerryjiang Oct 27, 2013
61d9b38
upgrade assembly version for 1.6
kerryjiang Nov 8, 2013
4a0d1c2
fixed the bug that maxRequestLength only works in the case protocol p…
kerryjiang Nov 8, 2013
63251eb
improved the log4net config to set the file encoding to be utf8
kerryjiang Nov 19, 2013
3faba8a
added NuGet file
kerryjiang Dec 25, 2013
1991e92
added active connect function for UDP
kerryjiang Jan 2, 2014
f40c045
added command filter support for dynamic language commands
kerryjiang Jan 6, 2014
7be5003
made the command where there is exception occur also go through comma…
kerryjiang Jan 13, 2014
c7d2d04
fixed a critical bug that some data cannot be sent fully in case of t…
kerryjiang Jan 16, 2014
8db3fb0
fixed the bug that the SuperSocket cannot start because of the config…
kerryjiang Jan 21, 2014
2f8c93b
fixed a compatibility issue with latest changes in the websocket prot…
kerryjiang Jan 21, 2014
e0e7d11
fixed the bug that SuperSocket will still try to send data to the cli…
kerryjiang Jan 31, 2014
42da839
updated README.TXT
kerryjiang Feb 18, 2014
575a0f1
updared README.TXT
kerryjiang Feb 18, 2014
692164f
updated NuGet package configuration
kerryjiang Feb 22, 2014
ef8e1f1
implement TrySend API
kerryjiang Dec 27, 2013
be91dc4
upgraded assembly version to 1.6.2
kerryjiang Feb 27, 2014
39428a6
fixed a missed overwrite for websocket TrySend support
kerryjiang Mar 4, 2014
c25e97e
Support zero body length in the FixedHeaderReceiveFilter
kerryjiang Mar 4, 2014
80bfc08
fixed some typo in comments
kerryjiang Mar 12, 2014
8f31d0a
added the messed session's information back in the session connected log
kerryjiang Mar 15, 2014
f4b82eb
Added TimerInterval to PerformanceMonitor for update delay.
haylax Mar 13, 2014
7390645
Added public PerfMonitor to DefaultBootstrap.
haylax Mar 13, 2014
505ce6d
Added IPerformanceMonitor for public.
haylax Mar 13, 2014
64abad5
Improved variable names
haylax Mar 20, 2014
5fd5b8f
formated and fixed some typo in the commit of haylax
kerryjiang Mar 30, 2014
7380d7a
New restart command for managment.
haylax Mar 25, 2014
1b4ec9b
Temporary fix for m_ReadWritePool GC problem.
haylax Mar 25, 2014
f05cffd
removed useless included files in the SocketEngine file
kerryjiang Mar 30, 2014
e65b4f9
fixed missing files in the ServerManager server project
kerryjiang Mar 30, 2014
eedad4b
improved the code about logging sub commands
kerryjiang Mar 30, 2014
d08029e
improved the code about adding Restart menu item for the Silverlight …
kerryjiang Mar 30, 2014
fe21f0c
fixed a protocol resolving bug in the BeginEndMarkReceiveFilter: http…
kerryjiang Apr 19, 2014
ba599f5
changed the sending timeout's exception type to TimeoutException
kerryjiang Apr 29, 2014
b3ec48d
fixed a bug that the request token won't be cleaned from the session
kerryjiang May 3, 2014
85effbe
fixed the conflict issue for request token
kerryjiang May 3, 2014
5a0130b
Fixed some memory leak issues caused by event handler reference of So…
kerryjiang May 9, 2014
e39dc81
clean the session snapshot when the server is shutting down
kerryjiang May 10, 2014
bdcd39a
Clean SendingQueuePool when the server is shutting down
kerryjiang May 10, 2014
541dccb
fixed the bug that sometime the data in the sending queue cannot be s…
kerryjiang May 10, 2014
eab9634
still use a new SAE to send each time in UDP
kerryjiang May 13, 2014
5e58ec7
define more const variables for default configuration values
kerryjiang May 27, 2014
d0c9fee
improved the configuration extension to support configuration change …
kerryjiang May 27, 2014
e9250c4
support dynamic server instance loading
kerryjiang May 27, 2014
25b11a9
added one test case to cover adding server in the runtime
kerryjiang Jun 2, 2014
94de61c
Add KeyStorageFlags property in CertificateConfig
billybraga Jun 2, 2014
083b89b
added the support of keyStorageFlags for the security configuration node
kerryjiang Jun 3, 2014
e15ec49
fixed an exception that the socket session has been closed when sendi…
kerryjiang Jun 4, 2014
4fdd85a
updated version in the nuspec
kerryjiang Jun 14, 2014
1a55cff
fixed some compatible issues of .NET 3.5 projects
kerryjiang Jun 16, 2014
9d691a8
added nuget package jobs in the build tasks
kerryjiang Jun 17, 2014
cb48b6a
fixed a bug that subscribing an event by mistake, the original purpos…
kerryjiang Jun 24, 2014
4002b40
upgraded version to 1.6.3
kerryjiang Jun 26, 2014
992fe0a
fixed the log4net missing issue for the QuickStart project
kerryjiang Jun 26, 2014
90fd931
fixed a warning in the QuickStart project
kerryjiang Jun 26, 2014
5e139a0
fixed an exception when collect a server's status but it has been sto…
kerryjiang Jun 26, 2014
76657f4
improved the build task file
kerryjiang Jun 27, 2014
de52336
fixed a bug that can cause an exception in case of sending data when …
kerryjiang Jul 8, 2014
ab81243
upgraded the version of nuget package to 1.6.3
kerryjiang Jul 28, 2014
5ab34fc
fixed a bug about status data collecting which could cause the applic…
kerryjiang Aug 31, 2014
de25a6f
exposed the appsession instantiating as protected virtual method
kerryjiang Sep 11, 2014
47dabb9
upgraded assembly version number to 1.6.4
kerryjiang Sep 12, 2014
869468d
fixed a possible NullReferenceException when check there is any data …
kerryjiang Sep 26, 2014
c1506e1
added a obsolete message for GetAppSessionByID method
kerryjiang Sep 26, 2014
ab701f2
fixed a potential NullReferenceException issue which is caused in rac…
kerryjiang Sep 30, 2014
7fc1b0b
fixed the exception which is caused by OnSerializing method of one St…
kerryjiang Sep 30, 2014
c75610a
fixed a bug about reading cookie
kerryjiang Oct 8, 2014
9f5ec6e
updated the version number in nuspec to 1.6.4
kerryjiang Oct 19, 2014
1dade54
updated log4net to 1.2.13
kerryjiang Oct 28, 2014
650bb8f
tried to fix a cookie decoding exception
kerryjiang Nov 6, 2014
e111af4
updated log4net version in nuget package configuration file
kerryjiang Nov 7, 2014
b1166e9
fixed the bug the configuration intelligence cannot work with custom …
kerryjiang Nov 9, 2014
7648a50
go back to use Uri.UnescapeDataString for decode cookies
kerryjiang Nov 13, 2014
fb4edbf
prevent exceptions due to the session snapshot is reset
kerryjiang Nov 19, 2014
93930b0
fixed an issue which could cause a NullReference exception
kerryjiang Nov 19, 2014
347e685
excluded the nuget key file
kerryjiang Dec 2, 2014
2474f76
enable vertical scrolling
kerryjiang Dec 22, 2014
bc52802
Fix nuspec
darkl Feb 26, 2015
4ac9cc4
Merge pull request #22 from darkl/patch-1
kerryjiang Mar 4, 2015
4c6d1a7
support more SslPerotocol version provided by higher version dotnetfx
kerryjiang Mar 5, 2015
8c57fd6
upgraded version to 1.6.5
kerryjiang Mar 6, 2015
1a11909
support hot update for some configuration options
kerryjiang Apr 19, 2015
e8c5b86
updated websocket4net
kerryjiang Apr 19, 2015
682f98b
fixed the bug the predict was not in used
kerryjiang Apr 19, 2015
f44aa05
improved the config hot updating
kerryjiang Apr 21, 2015
ee2afca
improved the PushServer sample to demonstrate config hot updating
kerryjiang Apr 21, 2015
5f1cdd9
improved the PushServer sample to demonstrate config hot updating
kerryjiang Apr 21, 2015
7bec5f8
.travis.yml
kerryjiang May 5, 2015
04082e9
updated readme
kerryjiang May 5, 2015
9e07244
fixed a missing method implementation of WorkItemAgent
kerryjiang May 6, 2015
304fd8c
fixed a compiling error in Mono
kerryjiang May 6, 2015
e835572
fixed the SecurityException when access agent
kerryjiang May 18, 2015
90da5fa
fixed the missing solution files
kerryjiang May 18, 2015
311580c
added missing System.Configuration reference
kerryjiang May 18, 2015
9ee09f6
upgraded QuickStart solution file
kerryjiang May 18, 2015
5efa3ed
add missing reference of System.configuration
prime167 Jul 14, 2015
b9a27e7
Merge pull request #32 from skynetv/v1.6
kerryjiang Jul 14, 2015
5645efc
set sendingQueuePool if it is null, provide a chance to extend it
kerryjiang Jul 20, 2015
1cc2581
improved instances stop order
kerryjiang Jul 20, 2015
3431a73
improved instances stop order
kerryjiang Jul 20, 2015
9c3d21b
support unrecyclable SocketAsyncEventArgs
kerryjiang Jul 20, 2015
e816661
support local endpoint binding for active connect socket
kerryjiang Jul 31, 2015
da616f9
allowed socket address reuse for active connect socket
kerryjiang Aug 3, 2015
86b0ac2
improved the process isolation mode to support read to the other sect…
kerryjiang Aug 11, 2015
5db9e34
fixed the bug m_CurrentSourceCount was not updated in SmartPool
kerryjiang Aug 19, 2015
b62839a
fixed the SecurityException about remote bootstrap accessing
kerryjiang Oct 7, 2015
02324b3
fixed one unhandled exception of performance counter which may occur …
kerryjiang Oct 7, 2015
b1b059d
fixed one unhandled exception of performance counter which may occur …
kerryjiang Oct 9, 2015
d9d3626
check the server statement when received operation command
ishowfun007 Oct 23, 2015
e77399d
RestartCommand:sleeping and waiting for stop
ishowfun007 Oct 23, 2015
79654aa
Merge pull request #39 from ishowfun007/v1.6
kerryjiang Oct 23, 2015
6b49f0e
Update STOP.cs
kerryjiang Oct 23, 2015
3b525e8
Update RESTART.cs
kerryjiang Oct 23, 2015
00b6781
prepared new nuget spec configuration files
kerryjiang Oct 26, 2015
929ee25
improved the nuget packaging script
kerryjiang Oct 26, 2015
d77332f
fixed the exception happen when the bootstrap process go live again w…
kerryjiang Oct 28, 2015
f0ffb73
fixed the IndexOutOfIndex exception of the sending queue
kerryjiang Oct 31, 2015
fdca826
fixed some build script issues
kerryjiang Nov 3, 2015
765e8b2
added nuget icons
kerryjiang Nov 5, 2015
b8f3d71
prevent an unhandled exception caused by performance counter when sto…
kerryjiang Nov 5, 2015
58755a5
Merge branch 'v1.6' of https://github.com/kerryjiang/SuperSocket into…
kerryjiang Nov 5, 2015
0603991
fixed the wrong dependency name in the nuget package spec
kerryjiang Nov 6, 2015
fc5c6c1
updated SuperSocket.Engine's package version
kerryjiang Nov 6, 2015
748df67
updated package specs and readme
kerryjiang Nov 10, 2015
5dc7c75
Update README.md
kerryjiang Nov 10, 2015
9bc7ce1
updated README.md
kerryjiang Nov 10, 2015
f4ad8f1
fixed wrong close reason code when the client close the connection gr…
kerryjiang Nov 11, 2015
6ad2de6
tried to fixed a bug about the SAE object is not released after the s…
kerryjiang Nov 11, 2015
b44ff67
updated assembly version to 1.6.6
kerryjiang Nov 30, 2015
cb567c3
fixed the serialization issue about report config change in isolation…
kerryjiang Dec 13, 2015
515679a
fixed logfactory cannot load issue about DynamicBootstrap
kerryjiang Dec 13, 2015
38b020d
moved dynamic bootstrap's test case to base test class
kerryjiang Dec 15, 2015
57de2f1
removed unnecessary log4net reference
kerryjiang Dec 15, 2015
b573510
improved travis build script
kerryjiang Dec 15, 2015
705a7da
added assembly xml files into nuget package schema
kerryjiang Dec 15, 2015
2b4885d
fixed travis configuration issue
kerryjiang Dec 15, 2015
2ba9496
exposed the api about getting max request length
kerryjiang Dec 17, 2015
de2b282
made start timeout configurable
kerryjiang Dec 23, 2015
bf3b351
added the configuration autoStartAfterUnexpectedShutdown
kerryjiang Feb 5, 2016
53dc90d
removed nuget download times badges
kerryjiang Mar 20, 2016
dce59bf
added the missed broadcast feature from SuperWebSocket
kerryjiang Apr 4, 2016
dbf26a0
prevent an exception which will be thrown from performance monitor wh…
kerryjiang Apr 5, 2016
0a1662c
defined a new class BroadcastState to replace Tuple
kerryjiang Apr 6, 2016
9beaf9b
updated assembly version
kerryjiang Apr 6, 2016
7f46ef7
youzi1001 Apr 26, 2016
3d8e161
youzi1001 Apr 26, 2016
d72a972
Update SocketServiceInstaller.cs
youzi1001 Apr 26, 2016
3f984f6
Merge pull request #51 from youzi1001/v1.6
kerryjiang Apr 26, 2016
08110c6
formatted code
kerryjiang Apr 26, 2016
91280e7
added signature key for SuperSocket.WebSocket
kerryjiang May 23, 2016
dc32f42
cleaned the NuGet package for websocket
kerryjiang May 23, 2016
3487df3
Fixed the bug that some sessions cannot be closed properly (#55)
kerryjiang May 26, 2016
2599eda
upgraded the version number to 1.6.7
kerryjiang May 26, 2016
4af3f80
Avoid SocketException scenario caused due to incompatibility of using…
bluebycode Dec 3, 2016
6ede996
Update UdpSocketListener.cs
bluebycode Dec 5, 2016
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
63 changes: 63 additions & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
###############################################################################
# Set default behavior to automatically normalize line endings.
###############################################################################
* text=auto

###############################################################################
# Set default behavior for command prompt diff.
#
# This is need for earlier builds of msysgit that does not have it on by
# default for csharp files.
# Note: This is only used by command line
###############################################################################
#*.cs diff=csharp

###############################################################################
# Set the merge driver for project and solution files
#
# Merging from the command prompt will add diff markers to the files if there
# are conflicts (Merging from VS is not affected by the settings below, in VS
# the diff markers are never inserted). Diff markers may cause the following
# file extensions to fail to load in VS. An alternative would be to treat
# these files as binary and thus will always conflict and require user
# intervention with every merge. To do so, just uncomment the entries below
###############################################################################
#*.sln merge=binary
#*.csproj merge=binary
#*.vbproj merge=binary
#*.vcxproj merge=binary
#*.vcproj merge=binary
#*.dbproj merge=binary
#*.fsproj merge=binary
#*.lsproj merge=binary
#*.wixproj merge=binary
#*.modelproj merge=binary
#*.sqlproj merge=binary
#*.wwaproj merge=binary

###############################################################################
# behavior for image files
#
# image files are treated as binary by default.
###############################################################################
#*.jpg binary
#*.png binary
#*.gif binary

###############################################################################
# diff behavior for common document formats
#
# Convert binary document formats to text before diffing them. This feature
# is only available from the command line. Turn it on by uncommenting the
# entries below.
###############################################################################
#*.doc diff=astextplain
#*.DOC diff=astextplain
#*.docx diff=astextplain
#*.DOCX diff=astextplain
#*.dot diff=astextplain
#*.DOT diff=astextplain
#*.pdf diff=astextplain
#*.PDF diff=astextplain
#*.rtf diff=astextplain
#*.RTF diff=astextplain
5 changes: 5 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
language: csharp
script:
- xbuild SuperSocket.2013.sln
- xbuild SuperSocket.2013.NET40.sln
- xbuild SuperSocket.2010.NET35.sln
5 changes: 3 additions & 2 deletions Agent/Program.cs
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Reflection;
using System.Runtime.Remoting;
using System.Runtime.Remoting.Channels;
using System.Runtime.Remoting.Channels.Ipc;
using System.Reflection;
using System.Runtime.Serialization.Formatters;
using System.Text;
using System.Threading;
using SuperSocket.SocketBase;
Expand Down Expand Up @@ -65,7 +66,7 @@ static void Main(string[] args)

try
{
var serverChannel = new IpcServerChannel("IpcAgent", channelPort);
var serverChannel = new IpcServerChannel("IpcAgent", channelPort, new BinaryServerFormatterSinkProvider { TypeFilterLevel = TypeFilterLevel.Full });
var clientChannel = new IpcClientChannel();
ChannelServices.RegisterChannel(serverChannel, false);
ChannelServices.RegisterChannel(clientChannel, false);
Expand Down
29 changes: 28 additions & 1 deletion Agent/WorkItemAgent.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
using System.Linq;
using System.Runtime.Remoting.Lifetime;
using System.Text;
using SuperSocket.Common;
using SuperSocket.SocketBase;
using SuperSocket.SocketBase.Config;
using SuperSocket.SocketBase.Logging;
Expand Down Expand Up @@ -33,10 +34,15 @@ public WorkItemAgent()

}

public bool Setup(string serverType, string bootstrapUri, string assemblyImportRoot, IServerConfig config, ProviderFactoryInfo[] factories)
public bool Setup(string serverType, string bootstrapUri, string assemblyImportRoot, IServerConfig config, ProviderFactoryInfo[] factories, string startupConfigFile)
{
m_AssemblyImporter = new AssemblyImport(assemblyImportRoot);

if (!string.IsNullOrEmpty(startupConfigFile))
{
AppDomain.CurrentDomain.ResetConfiguration(startupConfigFile);
}

var serviceType = Type.GetType(serverType);
m_AppServer = (IWorkItem)Activator.CreateInstance(serviceType);

Expand Down Expand Up @@ -78,6 +84,15 @@ public void Stop()
m_AppServer.Stop();
}

/// <summary>
/// Reports the potential configuration change.
/// </summary>
/// <param name="config">The server config which may be changed.</param>
public void ReportPotentialConfigChange(IServerConfig config)
{
m_AppServer.ReportPotentialConfigChange(config);
}

/// <summary>
/// Gets the session count.
/// </summary>
Expand Down Expand Up @@ -131,5 +146,17 @@ public void TransferSystemMessage(string messageType, object messageData)
{
m_AppServer.TransferSystemMessage(messageType, messageData);
}


/// <summary>
/// Gets the server's config.
/// </summary>
/// <value>
/// The server's config.
/// </value>
public IServerConfig Config
{
get { return m_AppServer.Config; }
}
}
}
19 changes: 0 additions & 19 deletions Build.Net45.bat

This file was deleted.

9 changes: 9 additions & 0 deletions Build.bat
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,13 @@ FOR /F "tokens=*" %%G IN ('DIR /B /AD /S obj') DO RMDIR /S /Q "%%G"
%msbuild% SuperSocket.2010.NET35.sln /p:Configuration=Release /t:Clean;Rebuild /p:OutputPath=..\bin\Net35\Release
FOR /F "tokens=*" %%G IN ('DIR /B /AD /S obj') DO RMDIR /S /Q "%%G"

reg query "HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\.NETFramework\v4.0.30319\SKUs\.NETFramework,Version=v4.5" 2>nul
if errorlevel 0 (
%msbuild% SuperSocket.2013.sln /p:Configuration=Debug /t:Clean;Rebuild /p:OutputPath=..\bin\Net45\Debug
FOR /F "tokens=*" %%G IN ('DIR /B /AD /S obj') DO RMDIR /S /Q "%%G"

%msbuild% SuperSocket.2013.sln /p:Configuration=Release /t:Clean;Rebuild /p:OutputPath=..\bin\Net45\Release
FOR /F "tokens=*" %%G IN ('DIR /B /AD /S obj') DO RMDIR /S /Q "%%G"
)

pause
32 changes: 32 additions & 0 deletions BuildServerManager.bat
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
@echo off

set fdir=%WINDIR%\Microsoft.NET\Framework64

if not exist %fdir% (
set fdir=%WINDIR%\Microsoft.NET\Framework
)

set msbuild=%fdir%\v4.0.30319\msbuild.exe

%msbuild% Management\Server\SuperSocket.ServerManager.Net40.csproj /p:Configuration=Debug /t:Clean;Rebuild /p:OutputPath=..\..\bin\Net40\Debug
FOR /F "tokens=*" %%G IN ('DIR /B /AD /S obj') DO RMDIR /S /Q "%%G"

%msbuild% Management\Server\SuperSocket.ServerManager.Net40.csproj /p:Configuration=Release /t:Clean;Rebuild /p:OutputPath=..\..\bin\Net40\Release
FOR /F "tokens=*" %%G IN ('DIR /B /AD /S obj') DO RMDIR /S /Q "%%G"

%msbuild% Management\Server\SuperSocket.ServerManager.Net35.csproj /p:Configuration=Debug /t:Clean;Rebuild /p:OutputPath=..\..\bin\Net35\Debug
FOR /F "tokens=*" %%G IN ('DIR /B /AD /S obj') DO RMDIR /S /Q "%%G"

%msbuild% Management\Server\SuperSocket.ServerManager.Net35.csproj /p:Configuration=Release /t:Clean;Rebuild /p:OutputPath=..\..\bin\Net35\Release
FOR /F "tokens=*" %%G IN ('DIR /B /AD /S obj') DO RMDIR /S /Q "%%G"

reg query "HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\.NETFramework\v4.0.30319\SKUs\.NETFramework,Version=v4.5" 2>nul
if errorlevel 0 (
%msbuild% Management\Server\SuperSocket.ServerManager.Net45.csproj /p:Configuration=Debug /t:Clean;Rebuild /p:OutputPath=..\..\bin\Net45\Debug
FOR /F "tokens=*" %%G IN ('DIR /B /AD /S obj') DO RMDIR /S /Q "%%G"

%msbuild% Management\Server\SuperSocket.ServerManager.Net45.csproj /p:Configuration=Release /t:Clean;Rebuild /p:OutputPath=..\..\bin\Net45\Release
FOR /F "tokens=*" %%G IN ('DIR /B /AD /S obj') DO RMDIR /S /Q "%%G"
)

pause
27 changes: 23 additions & 4 deletions Common/AssemblyUtil.cs
Original file line number Diff line number Diff line change
Expand Up @@ -187,19 +187,38 @@ public static T BinaryClone<T>(this T target)
}
#endif

private static object[] m_EmptyObjectArray = new object[] { };

/// <summary>
/// Copies the properties of one object to another object.
/// </summary>
/// <typeparam name="T"></typeparam>
/// <param name="source">The source.</param>
/// <param name="target">The target.</param>
/// <returns></returns>
public static T CopyPropertiesTo<T>(this T source, T target)
{
PropertyInfo[] properties = source.GetType().GetProperties(BindingFlags.Instance | BindingFlags.Public | BindingFlags.GetProperty);
return source.CopyPropertiesTo(p => true, target);
}

/// <summary>
/// Copies the properties of one object to another object.
/// </summary>
/// <typeparam name="T"></typeparam>
/// <param name="source">The source.</param>
/// <param name="predict">The properties predict.</param>
/// <param name="target">The target.</param>
/// <returns></returns>
public static T CopyPropertiesTo<T>(this T source, Predicate<PropertyInfo> predict, T target)
{
PropertyInfo[] properties = source.GetType()
.GetProperties(BindingFlags.Instance | BindingFlags.Public | BindingFlags.GetProperty);

Dictionary<string, PropertyInfo> sourcePropertiesDict = properties.ToDictionary(p => p.Name);

PropertyInfo[] targetProperties = target.GetType().GetProperties(BindingFlags.Instance | BindingFlags.Public | BindingFlags.GetProperty);
PropertyInfo[] targetProperties = target.GetType()
.GetProperties(BindingFlags.Instance | BindingFlags.Public | BindingFlags.SetProperty)
.Where(p => predict(p)).ToArray();

for (int i = 0; i < targetProperties.Length; i++)
{
var p = targetProperties[i];
Expand All @@ -213,7 +232,7 @@ public static T CopyPropertiesTo<T>(this T source, T target)
if (!sourceProperty.PropertyType.IsSerializable)
continue;

p.SetValue(target, sourceProperty.GetValue(source, m_EmptyObjectArray), m_EmptyObjectArray);
p.SetValue(target, sourceProperty.GetValue(source, null), null);
}
}

Expand Down
Loading