|
|
|
@ -10,19 +10,15 @@ namespace Connected.Data.Storage
|
|
|
|
|
{
|
|
|
|
|
public static void Bind(IStorageOperation operation, object entity)
|
|
|
|
|
{
|
|
|
|
|
List<PropertyInfo> properties = null;
|
|
|
|
|
if (operation is null || operation.Parameters is null)
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
foreach (var parameter in operation.Parameters)
|
|
|
|
|
{
|
|
|
|
|
if (parameter.Direction != ParameterDirection.ReturnValue && parameter.Direction != ParameterDirection.Output)
|
|
|
|
|
continue;
|
|
|
|
|
|
|
|
|
|
if (parameter.Value == DBNull.Value)
|
|
|
|
|
continue;
|
|
|
|
|
|
|
|
|
|
if (properties is null)
|
|
|
|
|
{
|
|
|
|
|
properties = new List<PropertyInfo>();
|
|
|
|
|
var properties = new List<PropertyInfo>();
|
|
|
|
|
|
|
|
|
|
var all = operation.GetType().GetProperties(BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance);
|
|
|
|
|
|
|
|
|
@ -31,12 +27,9 @@ namespace Connected.Data.Storage
|
|
|
|
|
if (prop.FindAttribute<ReturnValueAttribute>() is not null)
|
|
|
|
|
properties.Add(prop);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
PropertyInfo property = null;
|
|
|
|
|
PropertyInfo? property = null;
|
|
|
|
|
|
|
|
|
|
if (property is null)
|
|
|
|
|
{
|
|
|
|
|
foreach (var prop in properties)
|
|
|
|
|
{
|
|
|
|
|
if (string.Equals(prop.Name, parameter.Name, StringComparison.Ordinal))
|
|
|
|
@ -45,7 +38,6 @@ namespace Connected.Data.Storage
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (property is null)
|
|
|
|
|
{
|
|
|
|
@ -82,26 +74,28 @@ namespace Connected.Data.Storage
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (property is not null)
|
|
|
|
|
{
|
|
|
|
|
if (property is null)
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
var existingValue = property.GetValue(operation);
|
|
|
|
|
var overwriteAtt = property.FindAttribute<ReturnValueAttribute>();
|
|
|
|
|
|
|
|
|
|
if (overwriteAtt is null)
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
switch (overwriteAtt.ValueBehavior)
|
|
|
|
|
{
|
|
|
|
|
case PropertyValueBehavior.OverwriteDefault:
|
|
|
|
|
var defaultValue = property.PropertyType.GetDefault();
|
|
|
|
|
|
|
|
|
|
if (Equals(existingValue, defaultValue))
|
|
|
|
|
property.SetValue(operation, parameter.Value);
|
|
|
|
|
property.SetValue(entity, parameter.Value);
|
|
|
|
|
break;
|
|
|
|
|
case PropertyValueBehavior.AlwaysOverwrite:
|
|
|
|
|
property.SetValue(operation, parameter.Value);
|
|
|
|
|
property.SetValue(entity, parameter.Value);
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|