Example #1
0
        internal static unsafe NXNode ParseNode(NodeData *ptr, NXNode parent, NXFile file)
        {
            NodeData nd   = *ptr;
            string   name = file.GetString(nd.NodeNameID);
            NXNode   ret;

            switch (nd.Type)
            {
            case 0:
                ret = new NXNode(name, parent, file, nd.ChildCount, nd.FirstChildID);
                break;

            case 1:
                ret = new NXValuedNode <long>(name, parent, file, nd.Type1Data, nd.ChildCount, nd.FirstChildID);
                break;

            case 2:
                ret = new NXValuedNode <double>(name, parent, file, nd.Type2Data, nd.ChildCount, nd.FirstChildID);
                break;

            case 3:
                ret = new NXStringNode(name, parent, file, nd.TypeIDData, nd.ChildCount, nd.FirstChildID);
                break;

            case 4:
                ret = new NXValuedNode <Point>(name, parent, file, new Point(nd.Type4DataX, nd.Type4DataY), nd.ChildCount, nd.FirstChildID);
                break;

            case 5:
                ret = new NXCanvasNode(name, parent, file, nd.TypeIDData, nd.Type5Width, nd.Type5Height, nd.ChildCount, nd.FirstChildID);
                break;

            case 6:
                ret = new NXMP3Node(name, parent, file, nd.TypeIDData, nd.Type4DataY, nd.ChildCount, nd.FirstChildID);
                break;

            default:
                return(Util.Die <NXNode>(string.Format("NX node has invalid type {0}; dying", nd.Type)));
            }

            if ((file._flags & NXReadSelection.EagerParseFile) == NXReadSelection.EagerParseFile)
            {
                ret.CheckChild();
            }

            return(ret);
        }
Example #2
0
        /// <summary>
        ///   Tries to cast this NXNode to a <see cref="NXValuedNode{T}" /> and returns its value, or returns the default value if the cast is invalid.
        /// </summary>
        /// <typeparam name="T"> The type of the value to return. </typeparam>
        /// <param name="n"> This NXNode. </param>
        /// <param name="def"> The default value to return should the cast fail. </param>
        /// <returns> The contained value if the cast succeeds, or <paramref name="def" /> if the cast fails. </returns>
        public static T ValueOrDefault <T>(this NXNode n, T def)
        {
            NXValuedNode <T> nxvn = n as NXValuedNode <T>;

            return(nxvn != null ? nxvn.Value : def);
        }