Skip to content

Commit

Permalink
fix: Added examples of dictionaries usage.
Browse files Browse the repository at this point in the history
  • Loading branch information
hennadiilu authored May 7, 2024
1 parent 8484567 commit 14eb40f
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 0 deletions.
13 changes: 13 additions & 0 deletions src/Heleonix.Reflection/Reflector.Get.cs
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ public static partial class Reflector
/// a target value is not of type <typeparamref name="TReturn"/>.
/// </returns>
/// <example>
/// <code>
/// var success = Reflector.Get(DateTime.Now, null, "TimeOfDay.Hours", out int value);
///
/// // success == true;
Expand All @@ -60,6 +61,18 @@ public static partial class Reflector
///
/// // success == true;
/// // value == typeof(int).CustomAttributes.First().
///
/// or
///
/// var rec = new Record(new Dictionary&lt;string, string&gt; { { "K e y", "V a l u e" } });
///
/// var success = Reflector.Get(rec, null, "Dic[K e y].Length", out int value);
///
/// record class Record(Dictionary&lt;string, string&gt; Dic);
///
/// // success == true;
/// // value == rec.Dic["K e y"].Length;
/// </code>
/// </example>
public static bool Get<TReturn>(
object instance,
Expand Down
14 changes: 14 additions & 0 deletions src/Heleonix.Reflection/Reflector.Set.cs
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,8 @@ public static partial class Reflector
/// a target member or an intermediate member is neither <see cref="PropertyInfo"/> nor <see cref="FieldInfo"/>.
/// </returns>
/// <example>
/// This code demonstrates common scenarios.
/// <code>
/// public class Root
/// {
/// public Child Child { get; set; } = new Child();
Expand All @@ -60,6 +62,18 @@ public static partial class Reflector
/// // root.Child.Value == 111;
/// // root.Children[0].Value == 222;
/// // root.Children[1].Value == 333.
/// </code>
/// This code demonstrates usage of dictionaries.
/// <code>
/// var rec = new Record(new Dictionary&lt;string, string&gt; { { "K e y", "V a l u e" } });
///
/// var success = Reflector.Set(rec, null, "Dic[K e y]", "New Value");
///
/// record class Record(Dictionary&lt;string, string&gt; Dic);
///
/// // success == true;
/// // value == record.Dic["K e y"];
/// </code>
/// </example>
public static bool Set(
object instance,
Expand Down

0 comments on commit 14eb40f

Please sign in to comment.