public T Prop = new Ctor(Method);
private K Method(U controller, V request);
I get that it can’t access Method here, because Method is required to be static. Why is this? Prop is not static.
Update: Here’s the actual signature:
public DataSource(Func<ControllerBase, AjaxDataTable.Request, Result> dataSelector)
And this is how the method used to be:
public AjaxDataTable<SourcesViewModel.Source.Channel>.DataSource AjaxData =
new AjaxDataTable<SourcesViewModel.Source.Channel>.DataSource(OnSelectData);
This wasn’t an issue because I didn’t need to reference this, so when I added this and it didn’t compile anymore, (the field wasn’t mine to begin with, someone else had done it like that, so don’t hate me for that). I changed it to the following:
private AjaxDataTable<SourcesViewModel.Source.Channel>.DataSource ajaxData;
public AjaxDataTable<SourcesViewModel.Source.Channel>.DataSource AjaxData
{
get
{
if (ajaxData == null)
{
ajaxData =
new AjaxDataTable<SourcesViewModel.Source.Channel>
.DataSource(OnDataSelector);
}
return ajaxData;
}
}
But then the ajaxData private field would always be null, which makes the data table be instanced again every time (this is appended into a concurrent dictionary, which causes an Exception on a duplicate key). I want to know how assigning to a field that doesn’t reference this works. Does that create something that is reused across all instances of an object?
This is due to section 10.5.5.2 of the C# 4 spec, which includes:
You’re effectively referencing
this, as your code is equivalent to:Now you can argue that this restriction is draconian, but that’s a different discussion. Note that you could put it into a constructor body:
(I’m assuming you wouldn’t really have a public field, and that you’d have sensible names, etc 🙂