new() keyword in the base declaration statement in C# -
this question has answer here:
- what “where t : class, new()” mean? 11 answers
i wonder below new() keyword. new() in base declaration statement along idisposable c : dbcontext , idisposedtracker.
but wonder new() expression. anonymous base class declaration?
but notice couple of arrow marked next new(). curly brackets owned public class repositorybase, not new().
what new() here?
namespace personrepository { public class repositorybase<c> : idisposable c : dbcontext, idisposedtracker, new() ->{ public repositorybase() { datacontext.database.createifnotexists(); } private c _datacontext; public virtual c datacontext { { if (_datacontext == null || _datacontext.isdisposed) { _datacontext = new c(); allowserialization = true; //disable proxycreationdisabled prevent "in order serialize parameter, add type known types collection operation using serviceknowntypeattribute" error } return _datacontext; } } //partly omitted public void save() { datacontext.savechanges(); } public void dispose() { if (datacontext != null) datacontext.dispose(); } }<- }
the new() costraint ...it means c has class , has empty constructor
...
Comments
Post a Comment