trying to fix JoinMapBaseAdvanced

This commit is contained in:
Andrew Welker
2020-04-04 21:09:00 -06:00
parent b32212083d
commit 69f5460442

View File

@@ -164,7 +164,7 @@ namespace PepperDash.Essentials.Core
/// </summary> /// </summary>
public abstract class JoinMapBaseAdvanced public abstract class JoinMapBaseAdvanced
{ {
protected uint _joinOffset; protected uint JoinOffset;
/// <summary> /// <summary>
/// The collection of joins and associated metadata /// The collection of joins and associated metadata
@@ -175,11 +175,15 @@ namespace PepperDash.Essentials.Core
{ {
Joins = new Dictionary<string, JoinDataComplete>(); Joins = new Dictionary<string, JoinDataComplete>();
_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 // Add all the JoinDataComplete properties to the Joins Dictionary and pass in the offset
//Joins = this.GetType() //Joins = this.GetType()
@@ -193,21 +197,26 @@ namespace PepperDash.Essentials.Core
// return join; // 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 cType = type.GetCType();
var fields = cType.GetFields(BindingFlags.Public | BindingFlags.Instance); var fields = cType.GetFields(BindingFlags.Public | BindingFlags.Instance);
foreach (var field in fields) foreach (var field in fields)
{ {
if (field.IsDefined(typeof(JoinNameAttribute), true)) if (!field.IsDefined(typeof (JoinNameAttribute), true)) continue;
{
JoinDataComplete value = field.GetValue(this) as JoinDataComplete;
if (value != null) var childClass = Convert.ChangeType(this, type, null);
{
value.SetJoinOffset(_joinOffset); var value = field.GetValue(childClass) as JoinDataComplete; //this here is JoinMapBaseAdvanced, not the child class...which has no fields.
Joins.Add(value.GetNameAttribute(typeof(JoinDataComplete)), value);
} 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);
} }