Auto-implemented property with no delegate? (Foo -> SFoo with no IFoo)
-
Tuesday, February 02, 2010 9:37 PM
Hi,
is there some subtle difference I'm missing here? This is with Pex 0.21 & 0.22 in VS 2010 Ultimate beta 2.
The following code snippet (from the mfcompare code base) with an auto-implemented property:
public class ShoppingCart { /// <summary> /// 'Red' state of the cart - indicates that something went wrong along the way. /// </summary> public virtual bool IsRed { get; set; } ... }does not give me the possibility to replace the IsRed property with a delegate.
However, if I instead use the "traditional" property construct with a private backing field:
public class ShoppingCart { private bool _isRed = false; /// <summary> /// 'Red' state of the cart - indicates that something went wrong along the way. /// </summary> public virtual bool IsRed { get { return _isRed; } set { _isRed = value; } } }the MolesGenerator produces a more interesting stub class with the appropriate delegates:
// // Summary: // Sets the stub of MockingFrameworksCompare.ShoppingCartSample.ShoppingCart.IsRed public MolesDelegates.Func<bool> IsRedGet; // // Summary: // Sets the stub of MockingFrameworksCompare.ShoppingCartSample.ShoppingCart.IsRed public MolesDelegates.Action<bool> IsRedSetBoolean;Regards
Answers
-
Thursday, February 04, 2010 12:06 AMOwner
In general, you do not want stubs for compiler generated stuff. The C# compiler generates all kinds of types for Linq which you don't care about. I guess auto-properties fell into that filter and we could refine it a bit.
Jonathan "Peli" de Halleux - Give us your input about Pex!- Marked As Answer by PeliMicrosoft Employee, Owner Monday, February 22, 2010 7:42 PM
All Replies
-
Tuesday, February 02, 2010 11:31 PMOwnerI suspect we skip it because that property is tagged as compler generated. I could probably relax that filtering for auto-properties. Do you really need to detour auto-properties?
Jonathan "Peli" de Halleux - Give us your input about Pex! -
Wednesday, February 03, 2010 8:02 PMThanks for the prompt reply. It was more of an observation when compared to "traditional" properties. Other frameworks seem to support it though, but I can't say I need it.
-
Thursday, February 04, 2010 12:06 AMOwner
In general, you do not want stubs for compiler generated stuff. The C# compiler generates all kinds of types for Linq which you don't care about. I guess auto-properties fell into that filter and we could refine it a bit.
Jonathan "Peli" de Halleux - Give us your input about Pex!- Marked As Answer by PeliMicrosoft Employee, Owner Monday, February 22, 2010 7:42 PM