0

I am trying to debug the following line of code

binding.DataSource = this.bindingSource.DataSource;

and want to find out more information about binding.DataSource

In the immediate window the query ? binding.DataSource returns

Count = 1
[0]: {Contact Events}

I want to cast the binding.DataSource to something I can query with intellisense? What should I cast it to ?

[Update] The binding source was created as follows;

public BindingSource GetEventTypesBindingSource()
    {
        try
        {
          DbSet<ContactEventType> dset = base.Context.ContactEventTypes;
          IOrderedQueryable<ContactEventType> qry = dset.Where(p => p.Id > 0).OrderBy(x => x.Description);
            qry.Load();
            var bindingSource = new BindingSource();
            bindingSource.DataSource = dset.Local.ToBindingList();
            return bindingSource;
        }
        catch (Exception ex)
        {
            HandleException.Show(ex);
        }
        return null;
    }

[Update] I tried the following in the debugger

? (List<ContactEvent>) binding.DataSource.GetType() 

but get

The type or namespace name 'List' is not valid in this scope
4

2 回答 2

1

可能是List<ContactEvent>,但您可以使用调试器和/或反射来找出答案。

如果您在调试器的 Watch 窗口中查看变量,它将显示数据的类型。如果您在数据源上调用 GetType,它将返回对象的类型(您也可以在调试器中执行此操作,并在那里检查结果类型)。

于 2013-07-29T00:56:20.767 回答
1

首先它与答案无关,但在这种情况下您不必使用数据源(您不必使用数据成员属性)。您可以直接将其绑定到集合。集合的类型可以是来自实体框架程序集的自定义绑定列表实现。也许你看不到它的名字,因为它不是公开的,但转换为 IEnumerable 应该可以。如果我没记错的话,自定义实现是从 BindingList 派生的,那么 BindingList 也可以。

于 2013-07-29T09:28:51.647 回答