Taxon.Taxa?
Why is there no Children property for a taxon object? Am I just missing it, or a using clause?
I need to be at a taxon, and flatten it and its children out to a List<Taxon>
By children are you not referring to Taxon.Taxa? because I believe that Taxa is the property for all child taxonomy types for a given taxon
Well HierachicalTaxonomy has a Taxa property, which i'm using to get the Taxon I want as my "Root"
var categories = manager.GetTaxonomies<HierarchicalTaxonomy>().SingleOrDefault(x => x.Title ==
"Categories"
);
var mfTaxa = categories.Taxa.SingleOrDefault(x => x.Title ==
"MF"
+ mfNumber && x.Parent ==
null
);
aha I gotcha now, and you're right there should be something in there to get a hierarchicaltaxon's taxa.
Looking at the HierarchicalTaxon type in JustDecompile it appears there is a virtual property Subtaxa that appears to return what you want, but I can't figure out how to actually get access to it...
I've sent an email to the Sitefinity devs for more info on this property and if indeed this is even the way to get at it, I will report back as soon as I've got something for you, thanks for the feedback!
EDIT: in the meantime it occurs to me that you could use the taxonManager to grab an instance of the HiearchicalTaxonomy type instead, using that HiearachicalTaxon.Id. It's the long way around but might let you move forward until I hear back from the team.
hope this is helpful!
AH JOSH! You struck the nail on the head...It needed a cast to HierarchicalTaxon!
var subunits = ((HierarchicalTaxon)mfTaxa).Subtaxa;
So knowing that now...I'd love it if you guys just PLOPPED this into the core SF code :) This is super handy as an extension...
public
static
class
TaxonExtensions
public
static
IEnumerable<HierarchicalTaxon> FlattenHierarchy(
this
HierarchicalTaxon parent)
foreach
(HierarchicalTaxon control
in
parent.Subtaxa)
yield
return
control;
foreach
(HierarchicalTaxon descendant
in
control.FlattenHierarchy())
yield
return
descendant;
I'm glad you got it worked out! strangely enough, it occred to me to suggest that you cast the Taxon to HierarchicalTaxon but I kept getting compile errors that the cast was invalid.
Turns out I was accidentally trying to cast to HiearchicalTaxonomy instead of Taxon, but you figured that out anyway :)
Did you try the extension method?
Doesn't even need to BE an extension method actually...but if it could be included that would be awesome since it helps facilitate .Contains Linq queries. We're just being totally ignored on the topic :)
(not by you clearly)