Chainly icon indicating copy to clipboard operation
Chainly copied to clipboard

Bind properties to the chain interface

Open R2D221 opened this issue 8 years ago • 6 comments

Hi, I saw your library and thing it's an interesting idea! However, I think it's missing property chaining to be 100% useful.

Let's say I have a class Foo, with property Bar, but then I want to do: foo.Chain<IFooChain>.SetBar(bar). With your current examples, there seems to be no way to do it, but maybe it is possible since I haven't tested it on a project.

Either way, I think it needs to be done, because many fluent interfaces are used to set properties.

R2D221 avatar Dec 23 '16 00:12 R2D221

@R2D221 Great idea! Feel free to submit a PR if you have any suggestion on how to solve this. From your example I'm guessing that you would want to add a SetX-method for each property?

smatsson avatar Dec 23 '16 06:12 smatsson

Is this even possible? IFooChain would have to contain the SetX methods for the properties.

Does it make sense to have properties work like the Value() method works now?

natehitze avatar Dec 29 '16 04:12 natehitze

@laughinggoose that is actually a very good idea. There is basically no different between a void method with parameters and a property setter. I could update the code to check for a property or member if a method matching the signature was not found.

On mobile so sorry for formatting:

Interface TInterface { Tinterface Name(string value); }

Given the above interface Chainly could check for a property or member with the name "Name" given that a method does not exist. The interface method must have this signature for it to work: Tinterface PropertyName(TPropertyType value);

Any thoughts on this approach?

smatsson avatar Dec 29 '16 18:12 smatsson

Yeah, I think that makes sense.

natehitze avatar Jan 02 '17 04:01 natehitze

Sorry I haven't done a pull request or anything, I've been busy.

I think there are two possibilities: that we name the method either SetX or just X. I think SetX would be better because it would be clear it's a setter, and it works similar to Java and other languages. But X would be simpler, of course.

In any case, the library would check first if there's already an existing method, and if not then try to find a property.

R2D221 avatar Jan 07 '17 20:01 R2D221

Maybe I missunderstand your last sentence but I think that we should either go with X for methods and SetX for properties/members OR X for everything. My interpretation is that SetX should check for a method before checking for properties which does not make much sense.

Imo it's a matter of what makes most sense for the consumer of the library. SetX for properties/members might be better as it would make it clear that this is not a method that is executed but rather a value that is set.

smatsson avatar Jan 08 '17 12:01 smatsson