I want to pass generic(can be of any type) model/class to a method. How to pass that?
if(NewUser)
MethodA(User);
else
MethodA(UserReg);
Let me add some more code :
private void SetRegionDummy<T>(T obj)
{
foreach (var lookup in obj)
{
// but obj.(obj dot) does not give properties of PcvCompleteViewModel
}
}
//Call this method
SetRegionDummy(this.PcvCompleteViewModel);
[Serializable]
public class PcvCompleteViewModel : StepViewModelBase
{
#region Constructor
#endregion
#region Properties
public List<ChargeVolume> ChargeVolumes { get; set; }
public List<LookUpViewModel> LookUp { get; set; }
public List<ProductViewModel> Products { get; set; }
public List<ProductViewModel> PricingProducts { get; set; }
public List<RegionViewModel> Regions { get; set; }
public decimal ContractYears { get; set; }
public decimal? PropGrowthRate { get; set; }
public decimal? GnicsGrowthRate { get; set; }
}
The method is the same but how to pass a different object model?
UserandUserRegshare a common interface or base class? If not, you won't really benefit from generics here.PcvCompleteViewModelclass and any other class you want to use inside your method.