Binda.TreeViewBindaStrategy.GetControlValue C# (CSharp) Method

GetControlValue() public method

public GetControlValue ( Control control ) : object
control System.Windows.Forms.Control
return object
        public override object GetControlValue(Control control)
        {
            var treeView = control as TreeView;
            if (treeView == null) return null;

            var firstNode = treeView.Nodes.Cast<TreeNode>().FirstOrDefault();
            if (firstNode == null) return null;

            var list = (IList)Activator.CreateInstance(typeof (List<>).MakeGenericType(firstNode.Tag.GetType()));

            foreach (TreeNode node in treeView.Nodes)
            {
                var item = node.Tag;
                list.Add(item);
            }
            return list;
        }