/// <summary> /// Helper to get the value of a static field inside a Type. /// </summary> /// <typeparam name="R">The Type of the return value you are expecting</typeparam> /// <param name="type">The type which contains the field you want to get.</param> /// <param name="fieldName">The name of the field to get</param> /// <returns>The value from the field if successful, and/or null.</returns> public static R GetField <R>(this Type type, string fieldName) => At.Internal_GetField <R>(type, fieldName, null);
//static void Test() //{ // //// if the member is definitely contained in this instance's type (and not inherited) // //var x = new Weapon().GetField<string>("m_someWeaponField"); // // if the member is inherited // var y = new Weapon().GetField<string, Item>("m_someItemField"); // // static fields will be fine as long as you use the correct type // var z = typeof(Item).GetField<string>("s_someStaticField"); //} // ========= field extensions /// <summary> /// Helper to get the value of a non-static field on an object instance. <br/><br/> /// If the field is <see langword="private"/>, it must be contained inside the <see cref="Type"/> of <typeparamref name="T"/>. /// </summary> /// <typeparam name="R">The Type of the return value you are expecting</typeparam> /// <typeparam name="T">The type which contains the field, can be inherited if not private.</typeparam> /// <param name="instance">The instance you want to get a field from</param> /// <param name="fieldName">The name of the field to get</param> /// <returns>The value from the field if successful, and/or null.</returns> public static R GetField <R, T>(this T instance, string fieldName) => At.Internal_GetField <R>(typeof(T), fieldName, instance);