none
Cannot create Shim/Stub for the generic class

    Question

  • Hi,

    I am trying to create a stub/shim to a generic class that one of the types it gets is a struct. 

     public abstract class FileSystem<T> 
        where T : struct, IConvertible 

        {
            .... some implementation
        }

    I am not succeeding. Any ideas?

    Thanks

    Eli

        
    Saturday, December 15, 2012 3:08 PM

Answers

  • As of Visual Studio 2012 Update 1, Microsoft Fakes cannot generate stubs or shims for generic types with the "struct" constraint.

    • Marked as answer by eliTG Tuesday, December 18, 2012 7:07 AM
    Monday, December 17, 2012 5:18 PM

All replies

  • Hi Eli,

    I am trying to involve someone familiar with this topic to further look at this issue. There might be some time delay. Appreciate your patience.

    Best regards,


    Amanda Zhu [MSFT]
    MSDN Community Support | Feedback to us
    Develop and promote your apps in Windows Store
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    Monday, December 17, 2012 4:24 AM
    Moderator
  • As of Visual Studio 2012 Update 1, Microsoft Fakes cannot generate stubs or shims for generic types with the "struct" constraint.

    • Marked as answer by eliTG Tuesday, December 18, 2012 7:07 AM
    Monday, December 17, 2012 5:18 PM
  • Cannot make a generic fake for a class using object like
    Fakes.ShimDataServiceRepository<object>.AllInstances.GetEntitiesExpressionOfFuncOfT0Boolean = (instance, filter) =>
        {
        
        return null;
        
        }

    The call goes to actual code implementation.

    But when we specify the object type, it is working

    Fakes.ShimDataServiceRepository<Customer>.AllInstances.GetEntitiesExpressionOfFuncOfT0Boolean = (instance, filter) =>
        {
        
        return null;
        
        }

    But i need a general single fake for all objects so no need to repeat the code for each objects.

    My question is why the fake with `<object>` is not working?. As it is the parent of all the classes.

    Please any one help me :(

    Sunday, May 26, 2013 10:44 PM
  • Shabeer,

    Each instance of a generic class is a different .NET type. Fakes does not have an API that would allow detouring methods of multiple types at this time.

    Oleg

    Saturday, June 15, 2013 7:04 PM