pivotal -- Discuss impact of XContainer for GetResourceOrNull, GetJdfRootOrNull, GetJdfParentOrNull, and IsJdfElement


I have some duplicate code it is mostly because I need to accept a XContainer and not an XElement.

This syntax is required per the current spec

It should_find_DigitalPrintingParams = () => ticket.GetResourceLinkPoolResolvedItem("DigitalPrintingParams", ResourceUsage.Input).ShouldNotBeNull();

ticket is an XContainer and it doesn't seem natural to say ticket.Element.
Closed Jul 27, 2011 at 1:49 PM by tcabanski
Moved to pivotal


joefeser wrote Jul 12, 2011 at 5:50 PM

Example method with duplicate code:

element.JdfXPathSelectElement can't be refactored out to use GetResourceOrNull
    public static XElement GetResourceLinkPoolResolvedItem(this XContainer element, string resourceName, ResourceUsage usage) {
        ParameterCheck.ParameterRequired(element, "element");
        ParameterCheck.StringRequiredAndNotWhitespace(resourceName, "resourceName");

        if (!resourceName.EndsWith("Link")) {
            resourceName += "Link";
        var xpath = string.Format("//ResourceLinkPool/{0}[@Usage = '{1}']", resourceName, usage.ToString());
        var resourceLinkNode = element.JdfXPathSelectElement(xpath);
        if (resourceLinkNode != null) {
            var resourceLink = element.JdfXPathSelectElement(string.Format("//ResourcePool/*[@ID = '{0}']", resourceLinkNode.GetRefId()));
            if (resourceLink != null) {
                return resourceLink;
        return null;