Example #1
0
        internal bool TryGetInstanceHierarchically(string instancePath, out T symbol)
        {
            if (instancePath == null)
            {
                throw new ArgumentNullException("instancePath");
            }
            if (instancePath.Length == 0)
            {
                throw new ArgumentException();
            }
            if ((this.mode == InstanceCollectionMode.Path) && this._pathDict.TryGetValue(instancePath, out symbol))
            {
                return(true);
            }
            bool flag = false;

            string[] destinationArray = null;
            if ((instancePath.Length > 0) && (instancePath[0] == '.'))
            {
                flag = true;
            }
            if (!flag)
            {
                char[] separator = new char[] { '.' };
                destinationArray = instancePath.Split(separator);
            }
            else
            {
                char[]   separator   = new char[] { '.' };
                string[] sourceArray = instancePath.Split(separator);
                if (sourceArray.Length > 1)
                {
                    sourceArray[1] = sourceArray[1].Insert(0, ".");
                }
                destinationArray = new string[sourceArray.Length - 1];
                Array.Copy(sourceArray, 1, destinationArray, 0, sourceArray.Length - 1);
            }
            return(InstanceCollection <T> .TryGetSubItem(this, destinationArray, 0, out symbol));
        }
Example #2
0
        internal static bool TryGetSubItem(IInstanceCollection <T> coll, string[] pathSplit, int splitIndex, out T symbol)
        {
            SymbolParser.ArrayIndexType type;
            T local = default(T);

            symbol = default(T);
            string        nameWithIndices = pathSplit[splitIndex];
            string        instanceName    = null;
            IList <int[]> jaggedIndices   = null;
            string        indicesStr      = null;
            bool          flag            = SymbolParser.TryParseArrayElement(nameWithIndices, out instanceName, out indicesStr, out jaggedIndices, out type);

            if (flag)
            {
                nameWithIndices = instanceName;
            }
            bool flag2 = nameWithIndices[nameWithIndices.Length - 1] == '^';

            if (flag2)
            {
                nameWithIndices = nameWithIndices.Substring(0, nameWithIndices.Length - 1);
            }
            IList <T> list2 = null;

            if (coll.TryGetInstanceByName(nameWithIndices, out list2))
            {
                local = list2[0];
                if (flag)
                {
                    ISymbol                  symbol2  = null;
                    IArrayInstance           instance = local as IArrayInstance;
                    IReferenceInstanceAccess access   = local as IReferenceInstanceAccess;
                    if (instance != null)
                    {
                        instance.TryGetElement(jaggedIndices, out symbol2);
                    }
                    else if (access != null)
                    {
                        access.TryGetElement(jaggedIndices, out symbol2);
                    }
                    local = (T)symbol2;
                }
                if ((local == null) || (splitIndex >= (pathSplit.Length - 1)))
                {
                    symbol = !((splitIndex == (pathSplit.Length - 1)) & flag2) ? local : ((ISymbolInternal)local).SubSymbolsInternal[0];
                }
                else
                {
                    ISymbol symbol3 = local as ISymbol;
                    if (symbol3.IsContainerType)
                    {
                        ISymbolCollection subSymbolsInternal = ((ISymbolInternal)symbol3).SubSymbolsInternal;
                        if (flag2)
                        {
                            subSymbolsInternal = ((ISymbolInternal)subSymbolsInternal[0]).SubSymbolsInternal;
                        }
                        if ((subSymbolsInternal != null) && (subSymbolsInternal.Count > 0))
                        {
                            T local2 = default(T);
                            splitIndex++;
                            if (InstanceCollection <T> .TryGetSubItem((IInstanceCollection <T>)subSymbolsInternal, pathSplit, splitIndex, out local2))
                            {
                                symbol = local2;
                            }
                            else
                            {
                                symbol = default(T);
                            }
                        }
                    }
                }
            }
            return(((T)symbol) != null);
        }