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

Make ValuesDiffer overridable. #70

Merged
merged 1 commit into from
Jan 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
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
Loading