Remove ResetState and ApplyState temporary helpers

pull/5883/head
Mladen Macanovic 5 years ago
parent 1c0baa6ca6
commit 66d60024ed

@ -106,62 +106,5 @@ namespace System
return obj;
}
/// <summary>
/// Resets all fields of a given object to their default values.
/// </summary>
/// <typeparam name="T">Type of the object.</typeparam>
/// <param name="obj">An object</param>
/// <param name="customReset">Alternative custom method to reset the values.</param>
/// <returns>Returns the original object.</returns>
public static T ResetState<T>(this T obj, Action<T> customReset = null)
{
if (customReset != null)
{
customReset(obj);
}
else
{
var properties = typeof(T).GetProperties();
foreach (var property in properties)
{
if (!property.CanWrite)
{
continue;
}
property.SetValue(obj, null);
}
}
return obj;
}
/// <summary>
/// Applies all fields of a given object from it's counterpart.
/// </summary>
/// <typeparam name="T">Type of the object.</typeparam>
/// <param name="obj">An object.</param>
/// <param name="other">An object from which we copy the values.</param>
/// <returns>Returns the original object.</returns>
public static T ApplyState<T>(this T obj, T other)
{
// This code is not production ready and it should be removed once
// the proper validation in Blazorise is done!
var properties = typeof(T).GetProperties();
foreach (var property in properties)
{
if (!property.CanWrite)
{
continue;
}
property.SetValue(obj, typeof(T).GetProperty(property.Name).GetValue(other));
}
return obj;
}
}
}

Loading…
Cancel
Save