コード例 #1
0
 /// <summary>
 /// Gets the value of a field.
 /// </summary>
 /// <typeparam name="T">the type to get the field from</typeparam>
 /// <typeparam name="U">the type of the field (result casted)</typeparam>
 /// <param name="obj">the object instance to pull from</param>
 /// <param name="fieldName">the name of the field to read</param>
 /// <returns>the value of the field</returns>
 /// <exception cref="MissingFieldException">if <paramref name="fieldName"/> does not exist on <typeparamref name="T"/></exception>
 /// <seealso cref="FieldAccessor{T, U}.Get(ref T, string)"/>
 public static U GetField <U, T>(this T obj, string fieldName)
 => FieldAccessor <T, U> .Get(ref obj, fieldName);
コード例 #2
0
 /// <summary>
 /// Sets a field on the target object, as gotten from <typeparamref name="T"/>.
 /// </summary>
 /// <typeparam name="T">the type to get the field from</typeparam>
 /// <typeparam name="U">the type of the field to set</typeparam>
 /// <param name="obj">the object instance</param>
 /// <param name="fieldName">the field to set</param>
 /// <param name="value">the value to set it to</param>
 /// <exception cref="MissingFieldException">if <paramref name="fieldName"/> does not exist on <typeparamref name="T"/></exception>
 /// <seealso cref="FieldAccessor{T, U}.Set(ref T, string, U)"/>
 public static void SetField <T, U>(this T obj, string fieldName, U value)
 => FieldAccessor <T, U> .Set(ref obj, fieldName, value);