locked
Auto-implemented property with no delegate? (Foo -> SFoo with no IFoo) RRS feed

  • Question

  • 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
    Tuesday, February 2, 2010 9:37 PM

Answers

  • 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!
    Thursday, February 4, 2010 12:06 AM

All replies

  • I 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!
    Tuesday, February 2, 2010 11:31 PM
  • Thanks 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.
    Wednesday, February 3, 2010 8:02 PM
  • 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!
    Thursday, February 4, 2010 12:06 AM