예제 #1
0
        public Zchunk GetVars()
        {
            List <Zchunk> list = GetVars(this);
            List <Zchunk> funs = GetVars(this, new List <Type>()
            {
                typeof(Zfun),
            });

            if (list.Count > 0)
            {
                if (funs.Count > 0 && funs[0].IsStatic)
                {
                    for (int i = list.Count - 1; i >= 0; i--)
                    {
                        Zchunk chunk = list[i];
                        if (chunk.GetType().Name != typeof(ZfunArgs).Name)
                        {
                            if (chunk.IsStatic == false)
                            {
                                list.RemoveAt(i);
                            }
                        }
                    }
                }
                if (list.Count > 0)
                {
                    return(list[Tools.RandomNum(0, list.Count)]);
                }
            }
            return(null);
        }
예제 #2
0
        public List <Zchunk> GetVars(Zchunk curChunk, List <Type> types = null)
        {
            List <Zchunk> list = new List <Zchunk>();

            if (curChunk == null)
            {
                return(list);
            }
            if (types == null)
            {
                types = new List <Type>()
                {
                    typeof(Zvar),
                    typeof(Zattribute),
                    typeof(ZfunArgs)
                }
            }
            ;
            if (types.Contains(typeof(ZfunArgs)))
            {
                Zfun fun = curChunk as Zfun;
                if (fun != null && fun.Args != null)
                {
                    foreach (var arg in fun.Args)
                    {
                        list.Add(arg);
                    }
                }
                foreach (var chunk in curChunk.Allchunk)
                {
                    if (types.Contains(chunk.GetType()))
                    {
                        list.Add(chunk);
                    }
                }
            }
            else
            {
                if (types.Contains(curChunk.GetType()))
                {
                    list.Add(curChunk);
                }
            }
            if (curChunk.Parent != null)
            {
                list.AddRange(GetVars(curChunk.Parent, types));
            }
            return(list);
        }