IDyna.cs 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. using System;
  2. namespace Quadarax.Foundation.Core.Object.Dynamic
  3. {
  4. /// <summary>
  5. /// Defines the interface for dynamic objects that support runtime property management.
  6. /// </summary>
  7. /// <remarks>
  8. /// This interface provides a contract for objects that can have their properties
  9. /// dynamically added, accessed, and modified at runtime.
  10. /// </remarks>
  11. public interface IDyna : ICloneable
  12. {
  13. /// <summary>
  14. /// Gets the value of a property as a specified type.
  15. /// </summary>
  16. /// <typeparam name="TValue">The type to convert the property value to.</typeparam>
  17. /// <param name="propertyName">The name of the property to get the value from.</param>
  18. /// <returns>The value of the property cast to the specified type, or null if the property value is null.</returns>
  19. /// <exception cref="ArgumentOutOfRangeException">Thrown when the property does not exist.</exception>
  20. TValue? GetValue<TValue>(string propertyName);
  21. /// <summary>
  22. /// Sets the value of a property.
  23. /// </summary>
  24. /// <typeparam name="TValue">The type of the value being set.</typeparam>
  25. /// <param name="propertyName">The name of the property to set.</param>
  26. /// <param name="value">The value to set the property to.</param>
  27. /// <exception cref="ArgumentOutOfRangeException">Thrown when the property does not exist.</exception>
  28. void SetValue<TValue>(string propertyName, TValue? value);
  29. /// <summary>
  30. /// Clears all property values, setting them to null.
  31. /// </summary>
  32. void Clear();
  33. /// <summary>
  34. /// Copies all property values from this instance to a target instance.
  35. /// </summary>
  36. /// <param name="target">The target instance to copy values to.</param>
  37. /// <remarks>
  38. /// This method only copies values for properties that exist in both instances.
  39. /// It does not create new properties in the target instance.
  40. /// </remarks>
  41. void CopyTo(IDyna target);
  42. }
  43. }