Please see following methods.
public static ProductsCollection GetDummyData(int? customerId, int? supplierId)
{
try
{
if (customerId != null && customerId > 0)
{
Filter.Add(Customres.CustomerId == customerId);
}
if (supplierId != null && supplierId > 0)
{
Filter.Add(Suppliers.SupplierId == supplierId);
}
ProductsCollection products = new ProductsCollection();
products.FetchData(Filter);
return products;
}
catch
{
throw;
}
}
public static ProductsCollection GetDummyData(int? customerId)
{
return ProductsCollection GetDummyData(customerId, (int?)null);
}
public static ProductsCollection GetDummyData()
{
return ProductsCollection GetDummyData((int?)null);
}
1- Please advice how can I make overloads for both CustomerId and SupplierId because only one overload can be created with GetDummyData(int? ). Should I add another argument to mention that first argument is CustomerId or SupplierId for example GetDummyData(int?, string). OR should I use enum as 2nd argument and mention that first argument is CustoemId or SupplierId.
2- Is this condition is correct or just checking > 0 is sufficient -> if (customerId != null && customerId > 0)
3- Using Try/catch like this is correct?
4- Passing (int?)null is correct or any other better approach.
Edit:
I have found some other posts like this and because I have no knowledge of Generics that is why I am facing this problem. Am I right? Following is the post.
Why not just create separate
GetCustomerData(int)andGetSupplierData(int)methods?(Along with
GetData()andGetData(int,int)if you need them.)If you change your method arguments to
intrather thanint?then you only need to check (at your discretion) that they’re greater than 0.There’s no need for the
try...catchin this situation. If all you’re doing is re-throwing the exception then don’t bother catching it in the first place.See 1 and 2 above.
EDIT: Maybe something like this…