Interface constraints question

Hello,

If I have the following interface :

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public interface INodeDistributable {

    bool Filled{get; set;}
}

And a child class that implement it like this

using System.Collections;
using System.Collections.Generic;
using UnityEngine;


[System.Serializable]
public class NodeTile : NodeBase , INodeDistributable {

    public bool filled;
    public bool Filled
    {
        get
        {
            return filled;
        }
        set
        {
            filled = value;
        }
    }    
}

How do I access the base class fields Line 13 Below in a generic method

    public T[,] DrawFillT<T>( T[,] gridIn ) where T : INodeDistributable{

        //
        // Draw world rectangle
        Gizmos.DrawWireCube (transform.position, new Vector3 (gridWorldSize.x, 1, gridWorldSize.y));

        // Draw Q in rectangle
        if (gridIn != null && displayGridGizmos) {
            foreach (T n in gridIn) {
                Gizmos.color = (n.Filled== true)?Color.black:Color.white;
                Debug.Log (n.Filled);
                 Gizmos.DrawCube(n. nodeAttrBase.worldPosition, Vector3.one * (nodeDiameter));  ??????????
            }
        }

        // Return
        return gridIn;
    }

Thanks in advance for the help

you’d have to cast it, but there’s no guarantee that INodeDistributable IS a NodeBase.

If you expect T to be a NodeBase, than constrain it as a NodeBase instead.

Or if you expect all INodeDistributable’s to look like NodeBase’s, maybe consider including the NodeBase members in the INodeDistributable’s interface.

T will alway be a child class of NodeBase and INodeDistributanble will never be on just NodeBase but alway on a child class of NodeBase.

Do avoid all the casting I could create a grid per nodeType. So instead of having a single grid made from nodes that have for example have 2 properties ( worldPose and fill). I would have a gridFill and a grid that are the same size.

Im I using more memory this way. Is a 1 grid with 2 properties the same size a 2 grids with 1 property ?

Sorry to bug again but was wondering if you could show me how you would cast his. Do I have to use new() in the constraint ?

Actually your suggestion to include the member worked out great thanks so much