Blade.Utility.DataSourceHelper.ResolveDataSource C# (CSharp) Method

ResolveDataSource() public static method

Given a DataSource string (from the layout editor), resolves the item that refers to.
public static ResolveDataSource ( string dataSource, System.Item contextItem, IProviderSearchContext searchContext, bool assertSingleItem ) : System.Item
dataSource string The string data source passed to the presentation component.
contextItem System.Item The context item for relative paths and specifying the database from which to retrieve other items.
searchContext IProviderSearchContext The search context.
assertSingleItem bool If true, an exception will be thrown if more than one item matches the data source spec
return System.Item
        public static Item ResolveDataSource(string dataSource, Item contextItem, IProviderSearchContext searchContext, bool assertSingleItem)
        {
            var items = ResolveMultipleDataSource(dataSource, contextItem, searchContext);

            if (assertSingleItem && items.Count() > 1)
                    throw new Exception(string.Format("The data source {0} matches more than one item, and only a single item is expected.", dataSource));

            return items.FirstOrDefault();
        }

Same methods

DataSourceHelper::ResolveDataSource ( string dataSource, System.Item contextItem ) : System.Item
DataSourceHelper::ResolveDataSource ( string dataSource, System.Item contextItem, IProviderSearchContext searchContext ) : System.Item