Ejemplo n.º 1
0
            public ISID GetElement(COLLADA root, out string selector)
            {
                selector = null;
                string[]   parts  = Path.Split('/');
                string     idName = parts[0];
                List <IID> ids    = root.GetIDEntries(idName);

                if (ids.Count == 0)
                {
                    return(null);
                }
                if (ids.Count > 1)
                {
                    //Minor edge case which doesn't typically happen.
                    //TODO: determine which is which
                    throw new InvalidOperationException($"{ids.Count} ID entries named '{idName}'. Cannot determine which is which.");
                }
                ISIDAncestor ancestor = ids[0];

                for (int i = 1; i < parts.Length; ++i)
                {
                    string part          = parts[i];
                    int    selectorIndex = part.IndexOf('.');
                    if (selectorIndex >= 0)
                    {
                        selector = part.Substring(selectorIndex + 1);
                        part     = part.Substring(0, selectorIndex);
                    }
                    else
                    {
                        int dimSelector = part.IndexOf('(');
                        if (dimSelector >= 0)
                        {
                            selector = part.Substring(dimSelector);
                            part     = part.Substring(0, dimSelector);
                        }
                    }
                    ancestor = ancestor.SIDElementChildren.FirstOrDefault(x => string.Equals(x.SID, part, StringComparison.InvariantCulture));
                }
                return(ancestor as ISID);
            }