IAmfItemWriter GetAmfWriter(AmfWriterMap writerMap, Type type) { IAmfItemWriter amfWriter; // Use the writer specified within our dictionary, if it exists. if (writerMap.TryGetValue(type, out amfWriter)) { return(amfWriter); } // Try the lookup again but with the base type (so we can serialize enums and arrays, // for example). if (type.BaseType != null && writerMap.TryGetValue(type.BaseType, out amfWriter)) { return(amfWriter); } // No writer exists. Create and cache the default one so we don't need to go through this // expensive lookup again. lock (writerMap) { // Check inside lock since type may have been added since our initial check if (writerMap.TryGetValue(type, out amfWriter)) { return(amfWriter); } amfWriter = writerMap.DefaultWriter; writerMap.Add(type, amfWriter); return(amfWriter); } }
private static IAmfItemWriter GetAmfWriter(AmfWriterMap writerMap, Type type) { IAmfItemWriter amfItemWriter; if (writerMap.TryGetValue(type, out amfItemWriter) || type.BaseType != (Type)null && writerMap.TryGetValue(type.BaseType, out amfItemWriter)) { return(amfItemWriter); } lock (writerMap) { if (writerMap.TryGetValue(type, out amfItemWriter)) { return(amfItemWriter); } IAmfItemWriter local_0_1 = writerMap.DefaultWriter; writerMap.Add(type, local_0_1); return(local_0_1); } }