Rewrite ReturnValueBinder to properly bind return values
This commit is contained in:
		
							parent
							
								
									d92f0a6f82
								
							
						
					
					
						commit
						57a4f2fb05
					
				@ -10,19 +10,15 @@ namespace Connected.Data.Storage
 | 
				
			|||||||
	{
 | 
						{
 | 
				
			||||||
		public static void Bind(IStorageOperation operation, object entity)
 | 
							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)
 | 
								foreach (var parameter in operation.Parameters)
 | 
				
			||||||
			{
 | 
								{
 | 
				
			||||||
				if (parameter.Direction != ParameterDirection.ReturnValue && parameter.Direction != ParameterDirection.Output)
 | 
					 | 
				
			||||||
					continue;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
				if (parameter.Value == DBNull.Value)
 | 
									if (parameter.Value == DBNull.Value)
 | 
				
			||||||
					continue;
 | 
										continue;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
				if (properties is null)
 | 
									var properties = new List<PropertyInfo>();
 | 
				
			||||||
				{
 | 
					 | 
				
			||||||
					properties = new List<PropertyInfo>();
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
				var all = operation.GetType().GetProperties(BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance);
 | 
									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)
 | 
										if (prop.FindAttribute<ReturnValueAttribute>() is not null)
 | 
				
			||||||
						properties.Add(prop);
 | 
											properties.Add(prop);
 | 
				
			||||||
				}
 | 
									}
 | 
				
			||||||
				}
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
				PropertyInfo property = null;
 | 
									PropertyInfo? property = null;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
				if (property is null)
 | 
					 | 
				
			||||||
				{
 | 
					 | 
				
			||||||
				foreach (var prop in properties)
 | 
									foreach (var prop in properties)
 | 
				
			||||||
				{
 | 
									{
 | 
				
			||||||
					if (string.Equals(prop.Name, parameter.Name, StringComparison.Ordinal))
 | 
										if (string.Equals(prop.Name, parameter.Name, StringComparison.Ordinal))
 | 
				
			||||||
@ -45,7 +38,6 @@ namespace Connected.Data.Storage
 | 
				
			|||||||
						break;
 | 
											break;
 | 
				
			||||||
					}
 | 
										}
 | 
				
			||||||
				}
 | 
									}
 | 
				
			||||||
				}
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
				if (property is null)
 | 
									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 existingValue = property.GetValue(operation);
 | 
				
			||||||
				var overwriteAtt = property.FindAttribute<ReturnValueAttribute>();
 | 
									var overwriteAtt = property.FindAttribute<ReturnValueAttribute>();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
									if (overwriteAtt is null)
 | 
				
			||||||
 | 
										return;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
				switch (overwriteAtt.ValueBehavior)
 | 
									switch (overwriteAtt.ValueBehavior)
 | 
				
			||||||
				{
 | 
									{
 | 
				
			||||||
					case PropertyValueBehavior.OverwriteDefault:
 | 
										case PropertyValueBehavior.OverwriteDefault:
 | 
				
			||||||
						var defaultValue = property.PropertyType.GetDefault();
 | 
											var defaultValue = property.PropertyType.GetDefault();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
						if (Equals(existingValue, defaultValue))
 | 
											if (Equals(existingValue, defaultValue))
 | 
				
			||||||
								property.SetValue(operation, parameter.Value);
 | 
												property.SetValue(entity, parameter.Value);
 | 
				
			||||||
						break;
 | 
											break;
 | 
				
			||||||
					case PropertyValueBehavior.AlwaysOverwrite:
 | 
										case PropertyValueBehavior.AlwaysOverwrite:
 | 
				
			||||||
							property.SetValue(operation, parameter.Value);
 | 
											property.SetValue(entity, parameter.Value);
 | 
				
			||||||
						break;
 | 
											break;
 | 
				
			||||||
				}
 | 
									}
 | 
				
			||||||
			}
 | 
								}
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					 | 
				
			||||||
	}
 | 
					 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
				
			|||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user