Silas2
asked on
c# generic syntax don't understand
Can anyone explain this to me...I'm too dumb! This is from the telerik mvc grid extensions, you make columns with
Grid.Columns(columns=>{
columns.Bound("xx");etc
}
I put a break in the Columns func, and its sig is:
Columns(Action<GridColumnF actory> configurator)
Now, I understand, Action<T> is a delegate void method, but what I don't understand is how columns=>{
columns.Bound("xx"); }is implicitly cast to GridColumnFactory?
(GridColumnFactory- a class which has params in its constructor )
Grid.Columns(columns=>{
columns.Bound("xx");etc
}
I put a break in the Columns func, and its sig is:
Columns(Action<GridColumnF
Now, I understand, Action<T> is a delegate void method, but what I don't understand is how columns=>{
columns.Bound("xx"); }is implicitly cast to GridColumnFactory?
(GridColumnFactory- a class which has params in its constructor )
ASKER
Ok, its in the function sig in the docs, but how does columns=>{ columns.bound("xx"; columns.bound("yy");} become acceptable as GridColumnFactory? it doesn't look anything like the factory.
columns (the left-hand operator version) is created at runtime implicitly based on the context. The runtime can figure out the type from the context.
So, in you case, columns will actually be an object of type GridColumnFactory<TModel>. Bound() is a method on the factory class.
Hope that makes some sense.
So, in you case, columns will actually be an object of type GridColumnFactory<TModel>. Bound() is a method on the factory class.
Hope that makes some sense.
ASKER
Most kind, yes Its certainly helping.
So when the param comes into the call it (the runtime) hasn't instanced the factory even though it's (or something is) in the call.
In the call , (which is on the GridBuilder obj), this is the first line:
configurator(new GridColumnFactory(Componen t, Context));
(configurator is the method param)
Aah, the penny (half) dropped as I was typing, so the configurator is an Action<GridColumnFactory<T >>, does that mean the default call is to make a new one? Factory I mean, so does that mean if x = Action<Type>, then x(new Type())?
So when the param comes into the call it (the runtime) hasn't instanced the factory even though it's (or something is) in the call.
In the call , (which is on the GridBuilder obj), this is the first line:
configurator(new GridColumnFactory(Componen
(configurator is the method param)
Aah, the penny (half) dropped as I was typing, so the configurator is an Action<GridColumnFactory<T
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
So, from the docs:
Action<string> messageTarget;
messageTarget = s => Console.WriteLine(s);
So with the grid:
Action<GridColumnFactory<T >> x;
x=>{ x.Bound(1); x.Bound(2); }
Ah, I think I get it, for each x.Bound call, its using the factory's bound call. So the call into 'Columns', is receiving the right param, not because its been explicitly sent, but because the receiving procedure but because of its signature.
Action<string> messageTarget;
messageTarget = s => Console.WriteLine(s);
So with the grid:
Action<GridColumnFactory<T
x=>{ x.Bound(1); x.Bound(2); }
Ah, I think I get it, for each x.Bound call, its using the factory's bound call. So the call into 'Columns', is receiving the right param, not because its been explicitly sent, but because the receiving procedure but because of its signature.
If you look at the documentation for the Columns() method, you'll see that it takes a parameter of type Action<GridColumnFactory<T