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?