From 69f54604420a61c6fb47fd578c29b848afb15c64 Mon Sep 17 00:00:00 2001 From: Andrew Welker Date: Sat, 4 Apr 2020 21:09:00 -0600 Subject: [PATCH] trying to fix JoinMapBaseAdvanced --- .../JoinMaps/JoinMapBase.cs | 35 ++++++++++++------- 1 file changed, 22 insertions(+), 13 deletions(-) diff --git a/essentials-framework/Essentials Core/PepperDashEssentialsBase/JoinMaps/JoinMapBase.cs b/essentials-framework/Essentials Core/PepperDashEssentialsBase/JoinMaps/JoinMapBase.cs index 82694610..68804b93 100644 --- a/essentials-framework/Essentials Core/PepperDashEssentialsBase/JoinMaps/JoinMapBase.cs +++ b/essentials-framework/Essentials Core/PepperDashEssentialsBase/JoinMaps/JoinMapBase.cs @@ -164,7 +164,7 @@ namespace PepperDash.Essentials.Core /// public abstract class JoinMapBaseAdvanced { - protected uint _joinOffset; + protected uint JoinOffset; /// /// The collection of joins and associated metadata @@ -175,11 +175,15 @@ namespace PepperDash.Essentials.Core { Joins = new Dictionary(); - _joinOffset = joinStart - 1; - + JoinOffset = joinStart - 1; } - protected void AddJoins() + protected JoinMapBaseAdvanced(uint joinStart, Type type):this(joinStart) + { + AddJoins(type); + } + + protected void AddJoins(Type type) { // Add all the JoinDataComplete properties to the Joins Dictionary and pass in the offset //Joins = this.GetType() @@ -193,21 +197,26 @@ namespace PepperDash.Essentials.Core // return join; // }); - var type = this.GetType(); + //type = this.GetType(); <- this wasn't working because 'this' was always the base class, never the derived class var cType = type.GetCType(); var fields = cType.GetFields(BindingFlags.Public | BindingFlags.Instance); + foreach (var field in fields) { - if (field.IsDefined(typeof(JoinNameAttribute), true)) - { - JoinDataComplete value = field.GetValue(this) as JoinDataComplete; + if (!field.IsDefined(typeof (JoinNameAttribute), true)) continue; - if (value != null) - { - value.SetJoinOffset(_joinOffset); - Joins.Add(value.GetNameAttribute(typeof(JoinDataComplete)), value); - } + var childClass = Convert.ChangeType(this, type, null); + + var value = field.GetValue(childClass) as JoinDataComplete; //this here is JoinMapBaseAdvanced, not the child class...which has no fields. + + if (value == null) + { + Debug.Console(0, "Unable to caset base class to {0}", type.Name); + continue; } + + value.SetJoinOffset(JoinOffset); + Joins.Add(value.GetNameAttribute(typeof(JoinDataComplete)), value); }