Click here to Skip to main content
15,886,422 members
Home / Discussions / C#
   

C#

 
QuestionRe: I wan to make USB Bolcker using vb.net or C# Pin
George Jonsson9-Oct-14 16:28
professionalGeorge Jonsson9-Oct-14 16:28 
AnswerRe: I wan to make USB Bolcker using vb.net or C# Pin
Deb0079-Oct-14 19:30
Deb0079-Oct-14 19:30 
GeneralRe: I wan to make USB Bolcker using vb.net or C# Pin
George Jonsson9-Oct-14 21:20
professionalGeorge Jonsson9-Oct-14 21:20 
AnswerRe: I wan to make USB Bolcker using vb.net or C# Pin
Sibeesh KV26-Sep-14 0:19
professionalSibeesh KV26-Sep-14 0:19 
Questionretrieving contents from word file using c# windows application Pin
Reshma Chandran24-Sep-14 18:31
Reshma Chandran24-Sep-14 18:31 
AnswerRe: retrieving contents from word file using c# windows application Pin
Sibeesh KV24-Sep-14 18:36
professionalSibeesh KV24-Sep-14 18:36 
QuestionPrintTicket in GetPrintJobInfoCollection? Pin
murali_utr24-Sep-14 18:28
murali_utr24-Sep-14 18:28 
QuestionRefactor 'switch/case' That Is Based Enum Value Pin
Matt U.24-Sep-14 9:48
Matt U.24-Sep-14 9:48 
While this project I'm on is MVC, this question isn't specific to MVC, so I felt like this was the right place. Anyhow, we are using the Repository pattern for data access. One particular entity type, e.g. SharedObj, has several other entity types that the SharedObj entity can be tied to. Each is an IEnumerable, like this:

C#
public class SharedObj
{
    IEnumerable<Obj1> Obj1s;
    IEnumerable<Obj2> Obj2s;
    IEnumerable<Obj3> Obj3s;
    // More entity collections
}


So when we add a child object to one of those collections of SharedObj, we have a method like this:

C#
// 'entity' is of type 'SharedObj'

public void AddObj(ObjType objType, int objId)
{
    switch (objType)
    {
        case ObjType.Obj1:
            entity.Obj1s.Add(GetRepository<Obj1>().GetByID(objId);
            break;
        case ObjType.Obj2:
            entity.Obj2s.Add(GetRepository<Obj2>().GetByID(objId);
            break;
        case ObjType.Obj3:
            entity.Obj3s.Add(GetRepository<Obj3>().GetByID(objId);
            break;
        // case/break for each remaining entity type
    }
}


"ObjType" is an enumeration of object types. The "GetRepository" method calls "DependencyResolver.Current.GetService<irepository<t>>();" and we use Unity for dependency injection.

Is there a way to make a more generic "Add" call based on the supplied "ObjType"? Or is this the only concept that can be applied in order to achieve what we're doing?
djj55: Nice but may have a permission problem
Pete O'Hanlon: He has my permission to run it.

AnswerRe: Refactor 'switch/case' That Is Based Enum Value Pin
Pete O'Hanlon24-Sep-14 10:07
mvePete O'Hanlon24-Sep-14 10:07 
AnswerRe: Refactor 'switch/case' That Is Based Enum Value Pin
PIEBALDconsult24-Sep-14 10:54
mvePIEBALDconsult24-Sep-14 10:54 
Questionintegrate any bill acceptor in my c# application Pin
MaurizioFiorentino24-Sep-14 7:19
MaurizioFiorentino24-Sep-14 7:19 
AnswerRe: integrate any bill acceptor in my c# application Pin
ZurdoDev24-Sep-14 10:05
professionalZurdoDev24-Sep-14 10:05 
GeneralRe: integrate any bill acceptor in my c# application Pin
MaurizioFiorentino30-Sep-14 6:47
MaurizioFiorentino30-Sep-14 6:47 
AnswerRe: integrate any bill acceptor in my c# application Pin
ZurdoDev30-Sep-14 7:15
professionalZurdoDev30-Sep-14 7:15 
QuestionCoding music rhythms Pin
Navid Abyazi24-Sep-14 5:27
professionalNavid Abyazi24-Sep-14 5:27 
QuestionRe: Coding music rhythms Pin
ZurdoDev24-Sep-14 5:53
professionalZurdoDev24-Sep-14 5:53 
AnswerRe: Coding music rhythms Pin
Navid Abyazi25-Sep-14 7:00
professionalNavid Abyazi25-Sep-14 7:00 
QuestionRe: Coding music rhythms Pin
ZurdoDev25-Sep-14 7:17
professionalZurdoDev25-Sep-14 7:17 
GeneralRe: Coding music rhythms Pin
PIEBALDconsult24-Sep-14 6:09
mvePIEBALDconsult24-Sep-14 6:09 
GeneralRe: Coding music rhythms Pin
BillWoodruff24-Sep-14 22:06
professionalBillWoodruff24-Sep-14 22:06 
GeneralRe: Coding music rhythms Pin
PIEBALDconsult25-Sep-14 6:22
mvePIEBALDconsult25-Sep-14 6:22 
GeneralRe: Coding music rhythms Pin
Navid Abyazi25-Sep-14 7:15
professionalNavid Abyazi25-Sep-14 7:15 
GeneralRe: Coding music rhythms Pin
PIEBALDconsult26-Sep-14 8:08
mvePIEBALDconsult26-Sep-14 8:08 
AnswerRe: Coding music rhythms Pin
Pete O'Hanlon24-Sep-14 8:40
mvePete O'Hanlon24-Sep-14 8:40 
GeneralRe: Coding music rhythms Pin
PIEBALDconsult24-Sep-14 8:44
mvePIEBALDconsult24-Sep-14 8:44 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.