Skip to content

Commit

Permalink
Adjust validation in ObjectExtensions.
Browse files Browse the repository at this point in the history
  • Loading branch information
I-RzR-I committed May 29, 2024
1 parent 669803a commit 068b57b
Showing 1 changed file with 10 additions and 0 deletions.
10 changes: 10 additions & 0 deletions src/DomainCommonExtensions/DataTypeExtensions/ObjectExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,9 @@ public static bool TryCast<T>(this object obj, out T result)
/// <param name="xmlDocument">The xml document</param>
public static void GetXmlParams(this object obj, ref XmlDocument xmlDocument)
{
if (obj.IsNull())
throw new ArgumentNullException(nameof(obj));

foreach (var prop in obj.GetType().GetProperties())
{
var xmlNode = xmlDocument.SelectSingleNode("//" + prop.Name);
Expand All @@ -103,6 +106,11 @@ public static void GetXmlParams(this object obj, ref XmlDocument xmlDocument)
/// <remarks></remarks>
public static void CopyPropertiesTo(this object fromObject, object toObject)
{
if (fromObject.IsNull())
throw new ArgumentNullException(nameof(fromObject));
if (toObject.IsNull())
throw new ArgumentNullException(nameof(toObject));

var toObjectProperties = toObject.GetType().GetProperties();
foreach (var propTo in toObjectProperties)
{
Expand Down Expand Up @@ -240,6 +248,8 @@ public static T To<T>(this object source)
[CodeSource("https://learn.microsoft.com/en-us/dotnet/api/system.runtime.serialization.datacontractserializer?view=netstandard-2.0", "", "MS", "2022-12-28", "Reference source")]
public static string SerializeToString(this object obj)
{
if (obj.IsNull()) return null;

using var memoryStream = new MemoryStream();
using var reader = new StreamReader(memoryStream);
var serializer = new DataContractSerializer(obj.GetType());
Expand Down

0 comments on commit 068b57b

Please sign in to comment.