0

I have a case where it is returning objects of type T. My code looks like this.

public static T GetObjectsFromWebRequest<T>(string urlPath) where T : class
    {
        T modelObjects;
        try
        {

            //SaveServiceDataIntoTextFile(urlPath);
            WebRequest request = WebRequest.Create(urlPath);

            WebResponse ws = request.GetResponse();
            StreamReader responseStream = new StreamReader(ws.GetResponseStream());
            //Get the response of the webrequest into a string
            string response = responseStream.ReadToEnd();

            modelObjects = XMLSerializeDeserialize.ConvertXMLToModel<T>(response);
        }

        catch (Exception)
        {
            throw;
        }

        return modelObjects;
    }

In this case I don't have any option but add a default parameter like

public static T GetObjectsFromWebRequest<T>(string urlPath, T a = null) where T : class

Is there any other way I can resolve this violation?

Ignacio Soler Garcia
  • 21,122
  • 31
  • 128
  • 207
  • 4
    What does CA1006 `DoNotNestGenericTypesInMemberSignatures` got to do with this code? – adrianm Apr 24 '13 at 09:52
  • 1
    Looks like @Laxmi means [CA1004](http://msdn.microsoft.com/en-us/library/ms182150.aspx) – dtb Apr 24 '13 at 09:58
  • in the above case I have not used T as parameter. For resolving this, I have to use dummy parameter T a = null. Yes..it is CA1004 –  Apr 24 '13 at 09:58

1 Answers1

0

As suggested here, you could use an out parameter to convey your result:

public static void GetObjectsFromWebRequest<T>(string urlPath, out T objects) ...
Community
  • 1
  • 1
Dejan
  • 9,150
  • 8
  • 69
  • 117