Node with CompositeNode convinience

Simple request.
Could the Node object have a property named “AsCompositeNode” that is null or just the node itself already cast as a CompositeNode.
This would allow avoiding having to recast the node.

Instead of :
var aCNode = (CompositeNode)aNode;
to be replaced with
var ACNode = aNode.AsCompositeNode;

Allowing:
if (aNode.IsComposite && aNode.AsCompositeNode.HasChildNodes) {…}

Thanks,
Andy Bay

Hi Andy,

Thanks for your inquiry. Please refer to the following article:
Aspose.Words Document Object Model

Unfortunately, your question isn't clear enough therefore we request you to please elaborate your inquiry further by providing complete details of your use case. This will help us to understand your scenario, and we will be in a better position to address your concerns accordingly.

I’m not sure how to elaborate more than above.
I just want to avoid recasting using
CompositeNode objCompositeNode = (CompositeNode)RandomNodeObject;
and instead have access to it through a property such as
CompositeNode objCompositeNode = RandomNodeObject.AsCompositeNode;
Thus avoiding ugly, distracting, and inconvenient parenthesis.

If the “RandomNodeObject” happens to not be a Composite Node, then the property is null.

Edit:
Feature Request:
Add to the Node Object:

public CompositeNode AsCompositeNode
{ get {
if (IsComposite) return (CompositeNode)this;
else return null;
}
};



Thanks,
Andy Bay

Hi Andy,

Thanks for sharing the detail. We have logged this feature request as WORDSNET-14550 in our issue tracking system. You will be notified via this forum thread once this feature is available. We apologize for your inconvenience.

It would be great if you please share the use case that will use the AsCompositeNode property.

Examples:

if (UpdateElement.IsComposite && UpdateElement.AsCompositeNode.GetChildNodes(NodeType.Table, true).Count > 0)
{…}

if (hayStack.IsComposite)
{
var kids = hayStack.AsCompositeNode.ChildNodes;

}




Previously, these two calls ended up needed ugly nested parenthesis:
IE
var kids = ((CompositeNode)hayStack).ChildNodes;



And, just for fun, an Extension Method that does it (because you can’t create extension properties.):
///


/// Add a helper functions to the ASPOSE Node object.
///

public static class NodeExtensions
{
///
/// Easier Access to the Composite Node of a Node.
///

/// Node that may be a Composite Node
/// Composite Node or Null
public static CompositeNode AsCompositeNode(this Node thisNode)
{
if (!thisNode.IsComposite)
return null;

return (CompositeNode)thisNode;
}
}

Hi Andy,

Thanks for sharing the detail.

Unfortunately, the use case is not clear from the shared code snippet. Please share the detail about your use case. We will inform you via this forum thread once this feature (WORDSNET-14550) is available.

There are a number of methods that return “Node” in some fashion such as GetChild, GetChildNodes, SelectNodes, SelectSingleNode, GetAncestor, NextPreOrder, PreviousPreOrder, NextSibling, and PreviousSibling.

The majority of nodes you are going to get are Composite Nodes. I am frequently having to recast Nodes into Composite Nodes. I just want a handy property that does this for me rather than ending up with clunky code that has nested parenthesis to recast and access CompositeNode properties in one-off statements.
((CompositeNode)node).GetChildNodes(…) is ugly.
node.AsCompositeNode.GetChildNodes(…) is clean looking.

Thank You,
Andy Bay

Hi Andy,

Thanks for sharing the detail.

We have logged this detail in our issue tracking system. You will be notified via this forum thread once this feature is available. Please let us know if you have any more queries.