Click here to Skip to main content
15,116,354 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 2:17
mvePete O'Hanlon7-Dec-18 2:17 
GeneralRe: There is already an open DataReader associated with this Command which must be closed first. Pin
OriginalGriff7-Dec-18 2:40
mveOriginalGriff7-Dec-18 2:40 
QuestionDynamic alignment of winform controls Pin
george49864-Dec-18 18:52
professionalgeorge49864-Dec-18 18:52 
AnswerRe: Dynamic alignment of winform controls Pin
Dave Kreskowiak4-Dec-18 18:56
mveDave Kreskowiak4-Dec-18 18:56 
GeneralRe: Dynamic alignment of winform controls Pin
george49864-Dec-18 19:38
professionalgeorge49864-Dec-18 19:38 
AnswerRe: Dynamic alignment of winform controls Pin
Eddy Vluggen5-Dec-18 3:03
professionalEddy Vluggen5-Dec-18 3:03 
AnswerRe: Dynamic alignment of winform controls Pin
BillWoodruff5-Dec-18 15:44
mveBillWoodruff5-Dec-18 15:44 
QuestionReflection - from Type to Class (not instance of class) Pin
devvvy4-Dec-18 14:51
Memberdevvvy4-Dec-18 14: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 22:31
mveOriginalGriff4-Dec-18 22:31 
AnswerRe: Reflection - from Type to Class (not instance of class) Pin
F-ES Sitecore5-Dec-18 2:02
mveF-ES Sitecore5-Dec-18 2:02 
AnswerRe: Reflection - from Type to Class (not instance of class) Pin
Richard Deeming5-Dec-18 10:09
mveRichard Deeming5-Dec-18 10:09 
QuestionCode refactoring.. Pin
Simon_Whale4-Dec-18 3:49
professionalSimon_Whale4-Dec-18 3:49 
AnswerRe: Code refactoring.. Pin
lw@zi 4-Dec-18 4:29
professional lw@zi 4-Dec-18 4:29 
AnswerRe: Code refactoring.. Pin
Gerry Schmitz4-Dec-18 9:06
mveGerry Schmitz4-Dec-18 9:06 
AnswerRe: Code refactoring.. Pin
Luc Pattyn4-Dec-18 22:53
sitebuilderLuc Pattyn4-Dec-18 22:53 
QuestionRdlc reporting page break doesnt work- URGENT Pin
Member 132642683-Dec-18 19:40
MemberMember 132642683-Dec-18 19:40 
AnswerRe: Rdlc reporting page break doesnt work- URGENT Pin
Richard MacCutchan3-Dec-18 22:56
mveRichard MacCutchan3-Dec-18 22:56 
AnswerRe: Rdlc reporting page break doesnt work- URGENT Pin
OriginalGriff3-Dec-18 23:16
mveOriginalGriff3-Dec-18 23:16 
QuestionScan Barcode Get Product Image Pin
Kevin Marois2-Dec-18 13:02
professionalKevin Marois2-Dec-18 13:02 
AnswerRe: Scan Barcode Get Product Image Pin
Dave Kreskowiak2-Dec-18 17:27
mveDave Kreskowiak2-Dec-18 17:27 
AnswerRe: Scan Barcode Get Product Image Pin
OriginalGriff2-Dec-18 20:49
mveOriginalGriff2-Dec-18 20:49 
GeneralRe: Scan Barcode Get Product Image Pin
Kevin Marois3-Dec-18 7:43
professionalKevin Marois3-Dec-18 7:43 
QuestionWPF and C# - Passing Data and accessing Controls between Child Windows Pin
James Wyatt2-Dec-18 6:45
MemberJames Wyatt2-Dec-18 6:45 
AnswerRe: WPF and C# - Passing Data and accessing Controls between Child Windows Pin
OriginalGriff2-Dec-18 6:58
mveOriginalGriff2-Dec-18 6:58 
GeneralRe: WPF and C# - Passing Data and accessing Controls between Child Windows Pin
James Wyatt2-Dec-18 7:13
MemberJames Wyatt2-Dec-18 7: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.