/[xmltv_parser]/trunk/libxmltv/Core/XMLTV.cs
ViewVC logotype

Diff of /trunk/libxmltv/Core/XMLTV.cs

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

--- trunk/libxmltv/Core/XMLTV.cs	2013/03/10 19:34:06	124
+++ trunk/libxmltv/Core/XMLTV.cs	2013/03/10 19:44:49	125
@@ -102,16 +102,34 @@
             BindingSource source = new BindingSource();
 
             IDataSourceBindable binder = (data as IDataSourceBindable);
-            if (binder == null)
-            {
-                throw new InvalidCastException(string.Format("Cannot cast: '{0}' to '{1}'", data.GetType().Name, typeof(IDataSourceBindable).Name));
-            }
-
+            if (binder == null) { throw new InvalidCastException(string.Format("Cannot cast: '{0}' to '{1}'", data.GetType().Name, typeof(IDataSourceBindable).Name)); }
             object bindable = binder.CreateBindableDataSource();
             source.DataSource = bindable;
             return source;
         }
 
+        public static BindingSource CreateFilterFromDataSource(object source, params string[] args)
+        {
+            if (source == null) { throw new ArgumentNullException("source", "cannot be null"); }
+            if (args == null) { throw new ArgumentNullException("args", "cannot be null"); }
+            IDataSourceFilterable filter = (source as IDataSourceFilterable);
+            if (filter == null) { throw new InvalidCastException(string.Format("Cannot cast: '{0}' to '{1}'", source.GetType().Name, typeof(IDataSourceFilterable).Name)); }
+            object filtered = filter.Filter(source,args);
+            BindingSource bound = new BindingSource();
+            bound.DataSource = filtered;
+            return bound;
+        }
+        public static BindingSource CreateSorterFromDataSource(object source, params string[] args)
+        {
+            if (source == null) { throw new ArgumentNullException("source", "cannot be null"); }
+            if (args == null) { throw new ArgumentNullException("args", "cannot be null"); }
+            IDataSourceSortable sorter = (source as IDataSourceSortable);
+            if (sorter == null) { throw new InvalidCastException(string.Format("Cannot cast: '{0}' to '{1}'", source.GetType().Name, typeof(IDataSourceSortable).Name)); }
+            object sorted = sorter.Sort(source, args);
+            BindingSource bound = new BindingSource();
+            bound.DataSource = sorted;
+            return bound;
+        }
         #endregion
         #endregion
 

 

  ViewVC Help
Powered by ViewVC 1.1.22