Example #1
0
        /// <summary>
        /// 查找指定名称的功能块。
        /// </summary>
        /// <param name="name">功能块名称(不区分大小写)</param>
        /// <returns>指定名称的功能块。</returns>
        public virtual ViFirmBlockType GetPOU(string name)
        {
            // 先保证数据被更新了
            object _Children = this.Children;

            ViFirmBlockType blockType;

            // 先在子节点中查找
            name = name.ToUpper();
            if (this.Children != null && this.Children.Count > 0)
            {
                blockType = this.Children.Where(o => string.Compare(o.Name, name, true) == 0).FirstOrDefault() as ViFirmBlockType;

                if (blockType != null)
                {
                    return(blockType);
                }
            }

            if (this.RecursiveSearch)
            {
                // 在子节点中递归查找
                foreach (ViNamedObject child in this.Children)
                {
                    ViPouSource pouSource = child as ViPouSource;
                    if (pouSource == null)
                    {
                        continue;
                    }

                    blockType = pouSource.GetPOU(name);
                    if (blockType != null)
                    {
                        return(blockType);
                    }
                }
            }

            // 没有找到
            return(null);
        }