Skip to content

Commit

Permalink
Merge pull request #70 from NerosoftDev/develop
Browse files Browse the repository at this point in the history
Make ValuesDiffer overridable.
  • Loading branch information
Codespilot committed Jan 18, 2024
2 parents 1f7ad5b + 9e5095b commit b0ae1a4
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 10 deletions.
8 changes: 4 additions & 4 deletions Source/Euonia.Business/Core/BusinessObject.cs
Original file line number Diff line number Diff line change
Expand Up @@ -312,7 +312,7 @@ protected void PropertyHasChanged(string propertyName)
/// <summary>
/// Checks if the object has changed properties.
/// </summary>
public virtual bool HasChangedProperties => ChangedProperties.Any();
public virtual bool HasChangedProperties => ChangedProperties.Count > 0;

#endregion

Expand Down Expand Up @@ -670,7 +670,7 @@ private object LoadPropertyByReflection(string methodName, IPropertyInfo propert
/// <param name="oldValue"></param>
/// <typeparam name="TValue"></typeparam>
/// <returns></returns>
private static bool ValuesDiffer<TValue>(IPropertyInfo propertyInfo, TValue newValue, TValue oldValue)
protected virtual bool ValuesDiffer<TValue>(IPropertyInfo propertyInfo, TValue newValue, TValue oldValue)
{
bool valuesDiffer;
if (oldValue == null)
Expand All @@ -679,14 +679,14 @@ private static bool ValuesDiffer<TValue>(IPropertyInfo propertyInfo, TValue newV
}
else
{
// use reference equals for objects that inherit from CSLA base class
// use reference equals for objects that inherit from base class
if (typeof(IBusinessObject).IsAssignableFrom(propertyInfo.Type))
{
valuesDiffer = !(ReferenceEquals(oldValue, newValue));
}
else
{
valuesDiffer = !(oldValue.Equals(newValue));
valuesDiffer = !EqualityComparer<TValue>.Default.Equals(newValue, oldValue);
}
}

Expand Down
8 changes: 7 additions & 1 deletion Source/Euonia.Business/Core/EditableObject.cs
Original file line number Diff line number Diff line change
Expand Up @@ -373,14 +373,20 @@ protected void SetProperty<TValue>(string propertyName, ref TValue field, TValue
if (field == null)
{
if (newValue != null)
{
doChange = true;
}
}
else
{
if (typeof(TValue) == typeof(string) && newValue == null)
{
newValue = TypeHelper.CoerceValue<TValue>(typeof(string), string.Empty);
if (!field.Equals(newValue))
}
if (ValuesDiffer(propertyInfo, newValue, field))
{
doChange = true;
}
}

if (doChange)
Expand Down
3 changes: 1 addition & 2 deletions Source/Euonia.Business/Factory/BusinessObjectFactory.cs
Original file line number Diff line number Diff line change
Expand Up @@ -131,11 +131,10 @@ public async Task<TTarget> SaveAsync<TTarget>(TTarget target, CancellationToken
}

/// <inheritdoc/>
public async Task<TTarget> ExecuteAsync<TTarget>(TTarget command, CancellationToken cancellationToken = default)
public async Task<TTarget> ExecuteAsync<TTarget>(TTarget target, CancellationToken cancellationToken = default)
where TTarget : ICommandObject
{
var method = ObjectReflector.FindFactoryMethod<TTarget, FactoryExecuteAttribute>(new object[] { cancellationToken });
var target = GetObjectInstance<TTarget>();

try
{
Expand Down
4 changes: 2 additions & 2 deletions Source/Euonia.Business/Factory/IObjectFactory.cs
Original file line number Diff line number Diff line change
Expand Up @@ -80,13 +80,13 @@ public interface IObjectFactory
/// Invoke the execute method of an exists command object of <typeparamref name="TTarget"/>.
/// </summary>
/// <typeparam name="TTarget">Type of the target object.</typeparam>
/// <param name="command"></param>
/// <param name="target"></param>
/// <param name="cancellationToken"></param>
/// <returns></returns>
/// <remarks>
/// The method should named as Execute, ExecuteAsync, FactoryExecute, FactoryExecuteAsync, or attributed use <see cref="FactoryExecuteAttribute"/>.
/// </remarks>
Task<TTarget> ExecuteAsync<TTarget>(TTarget command, CancellationToken cancellationToken = default)
Task<TTarget> ExecuteAsync<TTarget>(TTarget target, CancellationToken cancellationToken = default)
where TTarget : ICommandObject;

/// <summary>
Expand Down
2 changes: 1 addition & 1 deletion project.props
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<Project>
<PropertyGroup>
<Version>8.1.19</Version>
<Version>8.1.20</Version>
<Authors>damon</Authors>
<Company>Nerosoft Ltd.</Company>
<Product>Euonia</Product>
Expand Down

0 comments on commit b0ae1a4

Please sign in to comment.