c# - Can I refactor functions that have similar inputs but call different services into one generic function?What are the differences between Generics in C# and Java… and Templates in C++?How can I return NULL from a generic method in C#?In C#, what is the difference between public, private, protected, and having no access modifier?C# Generics RefactoringNHibernate 2.1.2 unsaved transient instanceHow to use render partial with webgrid?Can A Function Return An Instance Of Generic Class Of Unknown Type?Generic partial applied function in c#Convert object to generic object in C#get int value from XmlTextAttribute when deserialize xml to class in c#

Going to France with limited French for a day

I am 15 years old and do not go to a Yeshiva but would like to learn Talmud. A few rabbis near me said they could teach me. How should I start

Do we know the situation in Britain before Sealion (summer 1940)?

Line segments inside a square

Why is a road bike faster than a city bike with the same effort? & how much faster it can be?

Should I answer honestly if asked why I was late one day when I was actually in an interview?

Why does C++ have 'Undefined Behaviour' and other languages like C# or Java don't?

Symbol for function composition like a big sum

Do we have any particular tonal center in mind when we are NOT listening music?

Is it acceptable to say that a reviewer's concern is not going to be addressed because then the paper would be too long?

Why did UK NHS pay for homeopathic treatments?

Labview vs Matlab??Which one better for image processing?

How to clarify between imagined sensations and "real" fantasy events?

Why does (inf + 0j)*1 evaluate to inf + nanj?

Is it impolite to ask for an in-flight catalogue with no intention of buying?

Is the use of language other than English 'Reasonable Suspicion' for detention?

Can an integer optimization problem be convex?

Why are there two fundamental laws of logic?

How do pilots align the HUD with their eyeballs?

Is it allowed to buy a Probe Bahncard 50 repeatedly?

Comma Code - Automate the Boring Stuff with Python

How to see the previous "Accessed" date in Windows

What is the meaning of word 'crack' in chapter 33 of A Game of Thrones?

Fuel sender works when outside of tank, but not when in tank



c# - Can I refactor functions that have similar inputs but call different services into one generic function?


What are the differences between Generics in C# and Java… and Templates in C++?How can I return NULL from a generic method in C#?In C#, what is the difference between public, private, protected, and having no access modifier?C# Generics RefactoringNHibernate 2.1.2 unsaved transient instanceHow to use render partial with webgrid?Can A Function Return An Instance Of Generic Class Of Unknown Type?Generic partial applied function in c#Convert object to generic object in C#get int value from XmlTextAttribute when deserialize xml to class in c#






.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty margin-bottom:0;








0















I am looking for a way to combine x amount of very similar CRUD functions into one without having to use x amount of if else statements to check the type of a generic.



I have Web API controllers that I want to make calls from like this:



Service.Get<FooModel>(number, type, part, version); 


This is to prevent having to have an extremely similar function for 40+ API endpoints. The issue is when I receive this in my service, I have to check the type of the generic given and compare with those 40+ object types in the one function. All of the models currently inherit from a base inherited model.



Current generic function



(Create, Update, Delete functions are similar):



public T Get<T>(string documentNr, string type, string part, string version) where T : InheritedModel, new()

try

T model = new T();

if (typeof(T) == typeof(InheritedModel))

using (var repo = new InheritedModelConsumer(ref _helper))

model = (T)repo.Get(documentNr, type, part, version);


else if (typeof(T) == typeof(FooModel))

using (var repo = new FooModelConsumer(ref _helper))

model = (T)(object)repo.Get(documentNr, type, part, version);


else if (typeof(T) == typeof(ComponentModel))

using (var repo = new ComponentModelConsumer(ref _helper))

model = (T)(object)repo.Get(documentNr, type, part, version);


else if (typeof(T) == typeof(BarModel))

using (var repo = new BarModelConsumer(ref _helper))

model = (T)(object)repo.Get(documentNr, type, part, version);


... and so on
... and so on
...
else
throw new Exception("Type T structure not defined");

return model;

catch (Exception)


throw;

finally

_helper.Dispose();




This does work, but if it is possible I am looking for something where I can say at run time, "oh I have this object of Type T, and well since I know the functions all have the same inputs I'm going to instantiate this consumer of Type TConsumer, call consumer.Get(inputs), and then return an object of T to whatever API controller called me."



Edit



Example of a simple consumer class in use




internal sealed class FooConsumer : RepositoryConsumer<Foo, FooRepository, FooFilter>

public FooConsumer(ref SqlHelper helper) : base(ref helper)

public List<Foo> GetAll(string token)

return _repo.Get().Where(x => Extensions.StringContainsToken(x.AccountName, token)).ToList();





Repository Consumer that all consumers inherit from .
T is the model, K is the Repository (custom ORM class), and O is Filter for the WHERE clause the ORM executes.





public abstract class RepositoryConsumer<T, K, O> : IDisposable, IRepositoryConsumer<T> where T : class, new() where K : Repository<T, O>, new() where O : QueryFilter, new()

/// <summary>
/// Repository instance
/// </summary>
protected K _repo;

/// <summary>
/// Only constructor avaialble. MUst pass SqlHelper instance for transaction support
/// </summary>
/// <param name="sql"></param>
public RepositoryConsumer(ref SqlHelper sql)

_repo = Activator.CreateInstance(typeof(K), new object[] sql ) as K;


/// <summary>
/// Allow consumer initializations in using statements
/// </summary>
public void Dispose()




/// <summary>
/// Create instance of T
/// </summary>
/// <param name="data"></param>
/// <returns></returns>
public virtual int Create(T data)

return _repo.Create(data);


/// <summary>
/// Bulk create instances of T
/// </summary>
/// <param name="contract"></param>
/// <returns></returns>
public virtual int Create(BaseBulkable<T> contract)

return _repo.BulkCreate(contract);


/// <summary>
/// Get an instance of T based on a single PK field id
/// </summary>
/// <param name="id"></param>
/// <returns></returns>
public virtual T Get(long id)

return _repo.Get(id);


/// <summary>
/// Gets all instances of T
/// </summary>
/// <returns></returns>
public virtual List<T> GetAll()

return _repo.Get();


/// <summary>
/// Updates an instance of T
/// </summary>
/// <param name="data"></param>
/// <returns></returns>
public virtual int Update(T data)

return _repo.Update(data);


/// <summary>
/// Updates an instance of T based on a single PK field id
/// </summary>
/// <param name="id"></param>
/// <param name="data"></param>
/// <returns></returns>
public virtual int Update(long id, T data)

return _repo.Update(id, data);


/// <summary>
/// Deletes an instance of T
/// </summary>
/// <param name="data"></param>
/// <returns></returns>
public virtual int Delete(T data)

return _repo.Delete(data);


/// <summary>
/// Deletes an instance of T based on a single PK field id
/// </summary>
/// <param name="id"></param>
/// <returns></returns>
public virtual int Delete(long id)

return _repo.Delete(id);












share|improve this question


























  • You could register your consumers in a dictionary by entity type. var repo = dict[typeof(T)];.

    – Olivier Jacot-Descombes
    Mar 28 at 16:55











  • What's unique about each consumer that separates it from a RepositoryConsumer<T>? If you can use the generic type T in your call to your DB or API you could just inject a RepositoryConsumer<T> or IRepositoryConsumer<T> and drop the if-else

    – JSteward
    Mar 28 at 17:00











  • Your RepositoryConsumer code can't be your actual code it doesn't even compile, a virtual function needs a body?

    – JSteward
    Mar 28 at 17:15











  • @JSteward Updated the question with the RepositoryConsumer code. The RepositoryConsumer actually takes 3 generic arguments each having to do with T, which is where I think I run into most of my problems with trying to slim down the service call, sorry. The RepositoryBase is from an internal Nuget package, my bad. So they do have function bodies it's just in an assembly.

    – ckifer
    Mar 28 at 17:17












  • @JSteward Updated with the correct code for RepositoryConsumer

    – ckifer
    Mar 28 at 17:41

















0















I am looking for a way to combine x amount of very similar CRUD functions into one without having to use x amount of if else statements to check the type of a generic.



I have Web API controllers that I want to make calls from like this:



Service.Get<FooModel>(number, type, part, version); 


This is to prevent having to have an extremely similar function for 40+ API endpoints. The issue is when I receive this in my service, I have to check the type of the generic given and compare with those 40+ object types in the one function. All of the models currently inherit from a base inherited model.



Current generic function



(Create, Update, Delete functions are similar):



public T Get<T>(string documentNr, string type, string part, string version) where T : InheritedModel, new()

try

T model = new T();

if (typeof(T) == typeof(InheritedModel))

using (var repo = new InheritedModelConsumer(ref _helper))

model = (T)repo.Get(documentNr, type, part, version);


else if (typeof(T) == typeof(FooModel))

using (var repo = new FooModelConsumer(ref _helper))

model = (T)(object)repo.Get(documentNr, type, part, version);


else if (typeof(T) == typeof(ComponentModel))

using (var repo = new ComponentModelConsumer(ref _helper))

model = (T)(object)repo.Get(documentNr, type, part, version);


else if (typeof(T) == typeof(BarModel))

using (var repo = new BarModelConsumer(ref _helper))

model = (T)(object)repo.Get(documentNr, type, part, version);


... and so on
... and so on
...
else
throw new Exception("Type T structure not defined");

return model;

catch (Exception)


throw;

finally

_helper.Dispose();




This does work, but if it is possible I am looking for something where I can say at run time, "oh I have this object of Type T, and well since I know the functions all have the same inputs I'm going to instantiate this consumer of Type TConsumer, call consumer.Get(inputs), and then return an object of T to whatever API controller called me."



Edit



Example of a simple consumer class in use




internal sealed class FooConsumer : RepositoryConsumer<Foo, FooRepository, FooFilter>

public FooConsumer(ref SqlHelper helper) : base(ref helper)

public List<Foo> GetAll(string token)

return _repo.Get().Where(x => Extensions.StringContainsToken(x.AccountName, token)).ToList();





Repository Consumer that all consumers inherit from .
T is the model, K is the Repository (custom ORM class), and O is Filter for the WHERE clause the ORM executes.





public abstract class RepositoryConsumer<T, K, O> : IDisposable, IRepositoryConsumer<T> where T : class, new() where K : Repository<T, O>, new() where O : QueryFilter, new()

/// <summary>
/// Repository instance
/// </summary>
protected K _repo;

/// <summary>
/// Only constructor avaialble. MUst pass SqlHelper instance for transaction support
/// </summary>
/// <param name="sql"></param>
public RepositoryConsumer(ref SqlHelper sql)

_repo = Activator.CreateInstance(typeof(K), new object[] sql ) as K;


/// <summary>
/// Allow consumer initializations in using statements
/// </summary>
public void Dispose()




/// <summary>
/// Create instance of T
/// </summary>
/// <param name="data"></param>
/// <returns></returns>
public virtual int Create(T data)

return _repo.Create(data);


/// <summary>
/// Bulk create instances of T
/// </summary>
/// <param name="contract"></param>
/// <returns></returns>
public virtual int Create(BaseBulkable<T> contract)

return _repo.BulkCreate(contract);


/// <summary>
/// Get an instance of T based on a single PK field id
/// </summary>
/// <param name="id"></param>
/// <returns></returns>
public virtual T Get(long id)

return _repo.Get(id);


/// <summary>
/// Gets all instances of T
/// </summary>
/// <returns></returns>
public virtual List<T> GetAll()

return _repo.Get();


/// <summary>
/// Updates an instance of T
/// </summary>
/// <param name="data"></param>
/// <returns></returns>
public virtual int Update(T data)

return _repo.Update(data);


/// <summary>
/// Updates an instance of T based on a single PK field id
/// </summary>
/// <param name="id"></param>
/// <param name="data"></param>
/// <returns></returns>
public virtual int Update(long id, T data)

return _repo.Update(id, data);


/// <summary>
/// Deletes an instance of T
/// </summary>
/// <param name="data"></param>
/// <returns></returns>
public virtual int Delete(T data)

return _repo.Delete(data);


/// <summary>
/// Deletes an instance of T based on a single PK field id
/// </summary>
/// <param name="id"></param>
/// <returns></returns>
public virtual int Delete(long id)

return _repo.Delete(id);












share|improve this question


























  • You could register your consumers in a dictionary by entity type. var repo = dict[typeof(T)];.

    – Olivier Jacot-Descombes
    Mar 28 at 16:55











  • What's unique about each consumer that separates it from a RepositoryConsumer<T>? If you can use the generic type T in your call to your DB or API you could just inject a RepositoryConsumer<T> or IRepositoryConsumer<T> and drop the if-else

    – JSteward
    Mar 28 at 17:00











  • Your RepositoryConsumer code can't be your actual code it doesn't even compile, a virtual function needs a body?

    – JSteward
    Mar 28 at 17:15











  • @JSteward Updated the question with the RepositoryConsumer code. The RepositoryConsumer actually takes 3 generic arguments each having to do with T, which is where I think I run into most of my problems with trying to slim down the service call, sorry. The RepositoryBase is from an internal Nuget package, my bad. So they do have function bodies it's just in an assembly.

    – ckifer
    Mar 28 at 17:17












  • @JSteward Updated with the correct code for RepositoryConsumer

    – ckifer
    Mar 28 at 17:41













0












0








0


0






I am looking for a way to combine x amount of very similar CRUD functions into one without having to use x amount of if else statements to check the type of a generic.



I have Web API controllers that I want to make calls from like this:



Service.Get<FooModel>(number, type, part, version); 


This is to prevent having to have an extremely similar function for 40+ API endpoints. The issue is when I receive this in my service, I have to check the type of the generic given and compare with those 40+ object types in the one function. All of the models currently inherit from a base inherited model.



Current generic function



(Create, Update, Delete functions are similar):



public T Get<T>(string documentNr, string type, string part, string version) where T : InheritedModel, new()

try

T model = new T();

if (typeof(T) == typeof(InheritedModel))

using (var repo = new InheritedModelConsumer(ref _helper))

model = (T)repo.Get(documentNr, type, part, version);


else if (typeof(T) == typeof(FooModel))

using (var repo = new FooModelConsumer(ref _helper))

model = (T)(object)repo.Get(documentNr, type, part, version);


else if (typeof(T) == typeof(ComponentModel))

using (var repo = new ComponentModelConsumer(ref _helper))

model = (T)(object)repo.Get(documentNr, type, part, version);


else if (typeof(T) == typeof(BarModel))

using (var repo = new BarModelConsumer(ref _helper))

model = (T)(object)repo.Get(documentNr, type, part, version);


... and so on
... and so on
...
else
throw new Exception("Type T structure not defined");

return model;

catch (Exception)


throw;

finally

_helper.Dispose();




This does work, but if it is possible I am looking for something where I can say at run time, "oh I have this object of Type T, and well since I know the functions all have the same inputs I'm going to instantiate this consumer of Type TConsumer, call consumer.Get(inputs), and then return an object of T to whatever API controller called me."



Edit



Example of a simple consumer class in use




internal sealed class FooConsumer : RepositoryConsumer<Foo, FooRepository, FooFilter>

public FooConsumer(ref SqlHelper helper) : base(ref helper)

public List<Foo> GetAll(string token)

return _repo.Get().Where(x => Extensions.StringContainsToken(x.AccountName, token)).ToList();





Repository Consumer that all consumers inherit from .
T is the model, K is the Repository (custom ORM class), and O is Filter for the WHERE clause the ORM executes.





public abstract class RepositoryConsumer<T, K, O> : IDisposable, IRepositoryConsumer<T> where T : class, new() where K : Repository<T, O>, new() where O : QueryFilter, new()

/// <summary>
/// Repository instance
/// </summary>
protected K _repo;

/// <summary>
/// Only constructor avaialble. MUst pass SqlHelper instance for transaction support
/// </summary>
/// <param name="sql"></param>
public RepositoryConsumer(ref SqlHelper sql)

_repo = Activator.CreateInstance(typeof(K), new object[] sql ) as K;


/// <summary>
/// Allow consumer initializations in using statements
/// </summary>
public void Dispose()




/// <summary>
/// Create instance of T
/// </summary>
/// <param name="data"></param>
/// <returns></returns>
public virtual int Create(T data)

return _repo.Create(data);


/// <summary>
/// Bulk create instances of T
/// </summary>
/// <param name="contract"></param>
/// <returns></returns>
public virtual int Create(BaseBulkable<T> contract)

return _repo.BulkCreate(contract);


/// <summary>
/// Get an instance of T based on a single PK field id
/// </summary>
/// <param name="id"></param>
/// <returns></returns>
public virtual T Get(long id)

return _repo.Get(id);


/// <summary>
/// Gets all instances of T
/// </summary>
/// <returns></returns>
public virtual List<T> GetAll()

return _repo.Get();


/// <summary>
/// Updates an instance of T
/// </summary>
/// <param name="data"></param>
/// <returns></returns>
public virtual int Update(T data)

return _repo.Update(data);


/// <summary>
/// Updates an instance of T based on a single PK field id
/// </summary>
/// <param name="id"></param>
/// <param name="data"></param>
/// <returns></returns>
public virtual int Update(long id, T data)

return _repo.Update(id, data);


/// <summary>
/// Deletes an instance of T
/// </summary>
/// <param name="data"></param>
/// <returns></returns>
public virtual int Delete(T data)

return _repo.Delete(data);


/// <summary>
/// Deletes an instance of T based on a single PK field id
/// </summary>
/// <param name="id"></param>
/// <returns></returns>
public virtual int Delete(long id)

return _repo.Delete(id);












share|improve this question
















I am looking for a way to combine x amount of very similar CRUD functions into one without having to use x amount of if else statements to check the type of a generic.



I have Web API controllers that I want to make calls from like this:



Service.Get<FooModel>(number, type, part, version); 


This is to prevent having to have an extremely similar function for 40+ API endpoints. The issue is when I receive this in my service, I have to check the type of the generic given and compare with those 40+ object types in the one function. All of the models currently inherit from a base inherited model.



Current generic function



(Create, Update, Delete functions are similar):



public T Get<T>(string documentNr, string type, string part, string version) where T : InheritedModel, new()

try

T model = new T();

if (typeof(T) == typeof(InheritedModel))

using (var repo = new InheritedModelConsumer(ref _helper))

model = (T)repo.Get(documentNr, type, part, version);


else if (typeof(T) == typeof(FooModel))

using (var repo = new FooModelConsumer(ref _helper))

model = (T)(object)repo.Get(documentNr, type, part, version);


else if (typeof(T) == typeof(ComponentModel))

using (var repo = new ComponentModelConsumer(ref _helper))

model = (T)(object)repo.Get(documentNr, type, part, version);


else if (typeof(T) == typeof(BarModel))

using (var repo = new BarModelConsumer(ref _helper))

model = (T)(object)repo.Get(documentNr, type, part, version);


... and so on
... and so on
...
else
throw new Exception("Type T structure not defined");

return model;

catch (Exception)


throw;

finally

_helper.Dispose();




This does work, but if it is possible I am looking for something where I can say at run time, "oh I have this object of Type T, and well since I know the functions all have the same inputs I'm going to instantiate this consumer of Type TConsumer, call consumer.Get(inputs), and then return an object of T to whatever API controller called me."



Edit



Example of a simple consumer class in use




internal sealed class FooConsumer : RepositoryConsumer<Foo, FooRepository, FooFilter>

public FooConsumer(ref SqlHelper helper) : base(ref helper)

public List<Foo> GetAll(string token)

return _repo.Get().Where(x => Extensions.StringContainsToken(x.AccountName, token)).ToList();





Repository Consumer that all consumers inherit from .
T is the model, K is the Repository (custom ORM class), and O is Filter for the WHERE clause the ORM executes.





public abstract class RepositoryConsumer<T, K, O> : IDisposable, IRepositoryConsumer<T> where T : class, new() where K : Repository<T, O>, new() where O : QueryFilter, new()

/// <summary>
/// Repository instance
/// </summary>
protected K _repo;

/// <summary>
/// Only constructor avaialble. MUst pass SqlHelper instance for transaction support
/// </summary>
/// <param name="sql"></param>
public RepositoryConsumer(ref SqlHelper sql)

_repo = Activator.CreateInstance(typeof(K), new object[] sql ) as K;


/// <summary>
/// Allow consumer initializations in using statements
/// </summary>
public void Dispose()




/// <summary>
/// Create instance of T
/// </summary>
/// <param name="data"></param>
/// <returns></returns>
public virtual int Create(T data)

return _repo.Create(data);


/// <summary>
/// Bulk create instances of T
/// </summary>
/// <param name="contract"></param>
/// <returns></returns>
public virtual int Create(BaseBulkable<T> contract)

return _repo.BulkCreate(contract);


/// <summary>
/// Get an instance of T based on a single PK field id
/// </summary>
/// <param name="id"></param>
/// <returns></returns>
public virtual T Get(long id)

return _repo.Get(id);


/// <summary>
/// Gets all instances of T
/// </summary>
/// <returns></returns>
public virtual List<T> GetAll()

return _repo.Get();


/// <summary>
/// Updates an instance of T
/// </summary>
/// <param name="data"></param>
/// <returns></returns>
public virtual int Update(T data)

return _repo.Update(data);


/// <summary>
/// Updates an instance of T based on a single PK field id
/// </summary>
/// <param name="id"></param>
/// <param name="data"></param>
/// <returns></returns>
public virtual int Update(long id, T data)

return _repo.Update(id, data);


/// <summary>
/// Deletes an instance of T
/// </summary>
/// <param name="data"></param>
/// <returns></returns>
public virtual int Delete(T data)

return _repo.Delete(data);


/// <summary>
/// Deletes an instance of T based on a single PK field id
/// </summary>
/// <param name="id"></param>
/// <returns></returns>
public virtual int Delete(long id)

return _repo.Delete(id);









c# generics design-patterns asp.net-web-api2 refactoring






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Mar 28 at 17:39







ckifer

















asked Mar 28 at 16:38









ckiferckifer

511 gold badge3 silver badges9 bronze badges




511 gold badge3 silver badges9 bronze badges















  • You could register your consumers in a dictionary by entity type. var repo = dict[typeof(T)];.

    – Olivier Jacot-Descombes
    Mar 28 at 16:55











  • What's unique about each consumer that separates it from a RepositoryConsumer<T>? If you can use the generic type T in your call to your DB or API you could just inject a RepositoryConsumer<T> or IRepositoryConsumer<T> and drop the if-else

    – JSteward
    Mar 28 at 17:00











  • Your RepositoryConsumer code can't be your actual code it doesn't even compile, a virtual function needs a body?

    – JSteward
    Mar 28 at 17:15











  • @JSteward Updated the question with the RepositoryConsumer code. The RepositoryConsumer actually takes 3 generic arguments each having to do with T, which is where I think I run into most of my problems with trying to slim down the service call, sorry. The RepositoryBase is from an internal Nuget package, my bad. So they do have function bodies it's just in an assembly.

    – ckifer
    Mar 28 at 17:17












  • @JSteward Updated with the correct code for RepositoryConsumer

    – ckifer
    Mar 28 at 17:41

















  • You could register your consumers in a dictionary by entity type. var repo = dict[typeof(T)];.

    – Olivier Jacot-Descombes
    Mar 28 at 16:55











  • What's unique about each consumer that separates it from a RepositoryConsumer<T>? If you can use the generic type T in your call to your DB or API you could just inject a RepositoryConsumer<T> or IRepositoryConsumer<T> and drop the if-else

    – JSteward
    Mar 28 at 17:00











  • Your RepositoryConsumer code can't be your actual code it doesn't even compile, a virtual function needs a body?

    – JSteward
    Mar 28 at 17:15











  • @JSteward Updated the question with the RepositoryConsumer code. The RepositoryConsumer actually takes 3 generic arguments each having to do with T, which is where I think I run into most of my problems with trying to slim down the service call, sorry. The RepositoryBase is from an internal Nuget package, my bad. So they do have function bodies it's just in an assembly.

    – ckifer
    Mar 28 at 17:17












  • @JSteward Updated with the correct code for RepositoryConsumer

    – ckifer
    Mar 28 at 17:41
















You could register your consumers in a dictionary by entity type. var repo = dict[typeof(T)];.

– Olivier Jacot-Descombes
Mar 28 at 16:55





You could register your consumers in a dictionary by entity type. var repo = dict[typeof(T)];.

– Olivier Jacot-Descombes
Mar 28 at 16:55













What's unique about each consumer that separates it from a RepositoryConsumer<T>? If you can use the generic type T in your call to your DB or API you could just inject a RepositoryConsumer<T> or IRepositoryConsumer<T> and drop the if-else

– JSteward
Mar 28 at 17:00





What's unique about each consumer that separates it from a RepositoryConsumer<T>? If you can use the generic type T in your call to your DB or API you could just inject a RepositoryConsumer<T> or IRepositoryConsumer<T> and drop the if-else

– JSteward
Mar 28 at 17:00













Your RepositoryConsumer code can't be your actual code it doesn't even compile, a virtual function needs a body?

– JSteward
Mar 28 at 17:15





Your RepositoryConsumer code can't be your actual code it doesn't even compile, a virtual function needs a body?

– JSteward
Mar 28 at 17:15













@JSteward Updated the question with the RepositoryConsumer code. The RepositoryConsumer actually takes 3 generic arguments each having to do with T, which is where I think I run into most of my problems with trying to slim down the service call, sorry. The RepositoryBase is from an internal Nuget package, my bad. So they do have function bodies it's just in an assembly.

– ckifer
Mar 28 at 17:17






@JSteward Updated the question with the RepositoryConsumer code. The RepositoryConsumer actually takes 3 generic arguments each having to do with T, which is where I think I run into most of my problems with trying to slim down the service call, sorry. The RepositoryBase is from an internal Nuget package, my bad. So they do have function bodies it's just in an assembly.

– ckifer
Mar 28 at 17:17














@JSteward Updated with the correct code for RepositoryConsumer

– ckifer
Mar 28 at 17:41





@JSteward Updated with the correct code for RepositoryConsumer

– ckifer
Mar 28 at 17:41












0






active

oldest

votes














Your Answer






StackExchange.ifUsing("editor", function ()
StackExchange.using("externalEditor", function ()
StackExchange.using("snippets", function ()
StackExchange.snippets.init();
);
);
, "code-snippets");

StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "1"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);

else
createEditor();

);

function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/4.0/"u003ecc by-sa 4.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);



);














draft saved

draft discarded
















StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55402776%2fc-sharp-can-i-refactor-functions-that-have-similar-inputs-but-call-different-s%23new-answer', 'question_page');

);

Post as a guest















Required, but never shown

























0






active

oldest

votes








0






active

oldest

votes









active

oldest

votes






active

oldest

votes
















draft saved

draft discarded















































Thanks for contributing an answer to Stack Overflow!


  • Please be sure to answer the question. Provide details and share your research!

But avoid


  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.

To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55402776%2fc-sharp-can-i-refactor-functions-that-have-similar-inputs-but-call-different-s%23new-answer', 'question_page');

);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

Kamusi Yaliyomo Aina za kamusi | Muundo wa kamusi | Faida za kamusi | Dhima ya picha katika kamusi | Marejeo | Tazama pia | Viungo vya nje | UrambazajiKuhusu kamusiGo-SwahiliWiki-KamusiKamusi ya Kiswahili na Kiingerezakuihariri na kuongeza habari

SQL error code 1064 with creating Laravel foreign keysForeign key constraints: When to use ON UPDATE and ON DELETEDropping column with foreign key Laravel error: General error: 1025 Error on renameLaravel SQL Can't create tableLaravel Migration foreign key errorLaravel php artisan migrate:refresh giving a syntax errorSQLSTATE[42S01]: Base table or view already exists or Base table or view already exists: 1050 Tableerror in migrating laravel file to xampp serverSyntax error or access violation: 1064:syntax to use near 'unsigned not null, modelName varchar(191) not null, title varchar(191) not nLaravel cannot create new table field in mysqlLaravel 5.7:Last migration creates table but is not registered in the migration table

은진 송씨 목차 역사 본관 분파 인물 조선 왕실과의 인척 관계 집성촌 항렬자 인구 같이 보기 각주 둘러보기 메뉴은진 송씨세종실록 149권, 지리지 충청도 공주목 은진현