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

C#

 
GeneralRe: There is already an open DataReader associated with this Command which must be closed first. Pin
Pete O'Hanlon7-Dec-18 1:17
mvePete O'Hanlon7-Dec-18 1:17 
GeneralRe: There is already an open DataReader associated with this Command which must be closed first. Pin
OriginalGriff7-Dec-18 1:40
mveOriginalGriff7-Dec-18 1:40 
QuestionDynamic alignment of winform controls Pin
george49864-Dec-18 17:52
professionalgeorge49864-Dec-18 17:52 
AnswerRe: Dynamic alignment of winform controls Pin
Dave Kreskowiak4-Dec-18 17:56
mveDave Kreskowiak4-Dec-18 17:56 
GeneralRe: Dynamic alignment of winform controls Pin
george49864-Dec-18 18:38
professionalgeorge49864-Dec-18 18:38 
AnswerRe: Dynamic alignment of winform controls Pin
Eddy Vluggen5-Dec-18 2:03
professionalEddy Vluggen5-Dec-18 2:03 
AnswerRe: Dynamic alignment of winform controls Pin
BillWoodruff5-Dec-18 14:44
professionalBillWoodruff5-Dec-18 14:44 
QuestionReflection - from Type to Class (not instance of class) Pin
devvvy4-Dec-18 13:51
devvvy4-Dec-18 13:51 
hello guys,
How do I write something like this?
string json = null;
Type[] types = Assembly.GetExecutingAssembly().GetTypes();
var carTypes = (from type in types
                 where type.IsClass && type == typeof(Car)
                 select type);
foreach(var carType in carTypes )
{
    string typeName = carType .Name;
    string jsonFile = typeName + ".json";
    json = File.ReadAllText(jsonFile);

    // How can I not hardcode "Porche" here and instead use "carType"?
    IList<Porche> cars = Newtonsoft.Json.JsonConvert.DeserializeObject<List<Porche>>(json);
}

Here, Porche is a sub class of Car - Both "Porche" and "Car" are Class. In additional to Porche, we have Toyata, BMW, Tesla... I want to dynamically retrieve them via Reflection (avoid hardcoding)
"cars" is a list of instances of cars.

"carType" is Type.
How can I use "carType" in JsonConvert.DerserializeObject which take List<$CLASS$> as argument?

IList<someReflectionAPI(carType)> cars = Newtonsoft.Json.JsonConvert.DeserializeObject<list&lt;<b>someReflectionAPI(carType)>>(json);

Thanks
dev


modified 4-Dec-18 19:58pm.

AnswerRe: Reflection - from Type to Class (not instance of class) Pin
OriginalGriff4-Dec-18 21:31
mveOriginalGriff4-Dec-18 21:31 
AnswerRe: Reflection - from Type to Class (not instance of class) Pin
F-ES Sitecore5-Dec-18 1:02
professionalF-ES Sitecore5-Dec-18 1:02 
AnswerRe: Reflection - from Type to Class (not instance of class) Pin
Richard Deeming5-Dec-18 9:09
mveRichard Deeming5-Dec-18 9:09 
QuestionCode refactoring.. Pin
Simon_Whale4-Dec-18 2:49
Simon_Whale4-Dec-18 2:49 
AnswerRe: Code refactoring.. Pin
dan!sh 4-Dec-18 3:29
professional dan!sh 4-Dec-18 3:29 
AnswerRe: Code refactoring.. Pin
Gerry Schmitz4-Dec-18 8:06
mveGerry Schmitz4-Dec-18 8:06 
AnswerRe: Code refactoring.. Pin
Luc Pattyn4-Dec-18 21:53
sitebuilderLuc Pattyn4-Dec-18 21:53 
QuestionRdlc reporting page break doesnt work- URGENT Pin
Member 132642683-Dec-18 18:40
Member 132642683-Dec-18 18:40 
AnswerRe: Rdlc reporting page break doesnt work- URGENT Pin
Richard MacCutchan3-Dec-18 21:56
mveRichard MacCutchan3-Dec-18 21:56 
AnswerRe: Rdlc reporting page break doesnt work- URGENT Pin
OriginalGriff3-Dec-18 22:16
mveOriginalGriff3-Dec-18 22:16 
QuestionScan Barcode Get Product Image Pin
Kevin Marois2-Dec-18 12:02
professionalKevin Marois2-Dec-18 12:02 
AnswerRe: Scan Barcode Get Product Image Pin
Dave Kreskowiak2-Dec-18 16:27
mveDave Kreskowiak2-Dec-18 16:27 
AnswerRe: Scan Barcode Get Product Image Pin
OriginalGriff2-Dec-18 19:49
mveOriginalGriff2-Dec-18 19:49 
GeneralRe: Scan Barcode Get Product Image Pin
Kevin Marois3-Dec-18 6:43
professionalKevin Marois3-Dec-18 6:43 
QuestionWPF and C# - Passing Data and accessing Controls between Child Windows Pin
James Wyatt2-Dec-18 5:45
James Wyatt2-Dec-18 5:45 
AnswerRe: WPF and C# - Passing Data and accessing Controls between Child Windows Pin
OriginalGriff2-Dec-18 5:58
mveOriginalGriff2-Dec-18 5:58 
GeneralRe: WPF and C# - Passing Data and accessing Controls between Child Windows Pin
James Wyatt2-Dec-18 6:13
James Wyatt2-Dec-18 6:13 

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.