Click here to Skip to main content
15,908,175 members
Home / Discussions / C#
   

C#

 
GeneralRe: Serializing a Dictionary of Items where the Value member is a List of instances of an Interface Pin
Richard Deeming15-Sep-15 5:58
mveRichard Deeming15-Sep-15 5:58 
GeneralRe: Serializing a Dictionary of Items where the Value member is a List of instances of an Interface Pin
BillWoodruff16-Sep-15 0:22
professionalBillWoodruff16-Sep-15 0:22 
Thanks, Richard,

Of interest to me is that if you do use the technique of creating a field with a reference to the Type as Skeet suggests:
C#
// Assume 'BunchOfStuff is of Type: Dictionary<string, List<Stuff>>
private static readonly Type BunchType = typeof(BunchOfStuff);
While there's no problem using this as the 'Type argument to create a new 'serializer, if you are de-serializing, none of these will work:
C#
public static Dictionary<string, List<Stuff>> Read()
{
    using (FileStream reader = new FileStream(filepath, FileMode.Open, FileAccess.Read))
    {
        serializer = new DataContractSerializer(BunchType);
        
        // error 'field' but is used like a 'type
        // return (BunchType) serializer.ReadObject(reader);
        
        // error semi-colon expected
        // return (typeof(BunchType)) serializer.ReadObject(reader);
   
        // error semi-colon expected
        // return (BunchType.GetType()) serializer.ReadObject(reader);

        // only this works
        return (Dictionary<string, List<Stuff>>) serializer.ReadObject(reader);
}
So, that's two places you've got to use the 'naked' Type declaration.

Perhaps you are aware of another method to avoid writing the 'naked' Type ?

cheers, Bill
«I want to stay as close to the edge as I can without going over. Out on the edge you see all kinds of things you can't see from the center» Kurt Vonnegut.

GeneralRe: Serializing a Dictionary of Items where the Value member is a List of instances of an Interface Pin
Richard Deeming16-Sep-15 2:04
mveRichard Deeming16-Sep-15 2:04 
GeneralRe: Serializing a Dictionary of Items where the Value member is a List of instances of an Interface Pin
BillWoodruff16-Sep-15 7:37
professionalBillWoodruff16-Sep-15 7:37 
GeneralRe: Serializing a Dictionary of Items where the Value member is a List of instances of an Interface Pin
BillWoodruff15-Sep-15 6:58
professionalBillWoodruff15-Sep-15 6:58 
QuestionGridView Export to Excel keeping the date format Pin
Member 1180079714-Sep-15 3:34
Member 1180079714-Sep-15 3:34 
AnswerRe: GridView Export to Excel keeping the date format Pin
Richard MacCutchan14-Sep-15 6:31
mveRichard MacCutchan14-Sep-15 6:31 
QuestionWhat is it like working as a .NET developer? Pin
Jason Smith14-Sep-15 0:54
Jason Smith14-Sep-15 0:54 
AnswerRe: What is it like working as a .NET developer? Pin
Richard MacCutchan14-Sep-15 1:01
mveRichard MacCutchan14-Sep-15 1:01 
GeneralRe: What is it like working as a .NET developer? Pin
Jason Smith14-Sep-15 1:36
Jason Smith14-Sep-15 1:36 
QuestionHow to change a textbox text while the code is running Pin
Member 1191673513-Sep-15 20:29
Member 1191673513-Sep-15 20:29 
AnswerRe: How to change a textbox text while the code is running Pin
OriginalGriff13-Sep-15 21:03
mveOriginalGriff13-Sep-15 21:03 
AnswerRe: How to change a textbox text while the code is running Pin
BillWoodruff13-Sep-15 22:04
professionalBillWoodruff13-Sep-15 22:04 
GeneralRe: How to change a textbox text while the code is running Pin
Member 1191673514-Sep-15 23:54
Member 1191673514-Sep-15 23:54 
QuestionChange speech recognition language Pin
Member 1085025313-Sep-15 16:03
Member 1085025313-Sep-15 16:03 
AnswerRe: Change speech recognition language PinPopular
Dave Kreskowiak13-Sep-15 16:09
mveDave Kreskowiak13-Sep-15 16:09 
GeneralRe: Change speech recognition language Pin
Eddy Vluggen13-Sep-15 21:39
professionalEddy Vluggen13-Sep-15 21:39 
GeneralRe: Change speech recognition language Pin
Richard MacCutchan13-Sep-15 21:54
mveRichard MacCutchan13-Sep-15 21:54 
Questionmysql bracket Pin
abdujalilc12-Sep-15 16:50
abdujalilc12-Sep-15 16:50 
AnswerRe: mysql bracket Pin
Dave Kreskowiak12-Sep-15 16:56
mveDave Kreskowiak12-Sep-15 16:56 
AnswerRe: mysql bracket Pin
Wendelius12-Sep-15 18:28
mentorWendelius12-Sep-15 18:28 
AnswerRe: mysql bracket Pin
Richard Deeming14-Sep-15 2:44
mveRichard Deeming14-Sep-15 2:44 
QuestionC# Change Directory Function Pin
Erics Johnson12-Sep-15 10:59
Erics Johnson12-Sep-15 10:59 
AnswerRe: C# Change Directory Function Pin
Dave Kreskowiak12-Sep-15 16:52
mveDave Kreskowiak12-Sep-15 16:52 
AnswerRe: C# Change Directory Function Pin
BillWoodruff13-Sep-15 22:07
professionalBillWoodruff13-Sep-15 22:07 

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.