2010-11-24 11 views
6

here से निम्न कोड पर एक नज़र डालें।
यह डब्ल्यूसीएफ में क्रमबद्ध होने पर डेटाकंट्रैक्ट (ऑब्जेक्ट मॉडल, ऑब्जेक्ट ग्राफ़, डोमेन मॉडल) में परिपत्र संदर्भों को संरक्षित करने के बारे में है। पूर्ववर्ती CreateSerializer विधि और इसलिए भी -क्रमबद्धता पर कोड नमूने में अंतहीन पाश

class ReferencePreservingDataContractSerializerOperationBehavior 
     :DataContractSerializerOperationBehavior 
    { 
     public ReferencePreservingDataContractSerializerOperationBehavior(
      OperationDescription operationDescription) 
      : base(operationDescription) { } 

     public override XmlObjectSerializer CreateSerializer(
      Type type, string name, string ns, IList<Type> knownTypes) 
     { 
      return CreateDataContractSerializer(type, name, ns, knownTypes); 
     } 

     private static XmlObjectSerializer CreateDataContractSerializer(
      Type type, string name, string ns, IList<Type> knownTypes) 
     { 
      return CreateDataContractSerializer(type, name, ns, knownTypes); 
     } 

     public override XmlObjectSerializer CreateSerializer(
      Type type, XmlDictionaryString name, XmlDictionaryString ns, 
      IList<Type> knownTypes) 
     { 
      return new DataContractSerializer(type, name, ns, knownTypes, 
       0x7FFF /*maxItemsInObjectGraph*/, 
       false/*ignoreExtensionDataObject*/, 
       true/*preserveObjectReferences*/, 
       null/*dataContractSurrogate*/); 
     } 
    } 

एक अंतहीन लूप (stackoverflow) नहीं पैदा कर CreateDataContractSerializer है?

private static XmlObjectSerializer CreateDataContractSerializer(
      Type type, string name, string ns, IList<Type> knownTypes) 
     { 
      return CreateDataContractSerializer(type, name, ns, knownTypes); 
     } 

अब शायद ये विधियां उपयोग में नहीं हैं? मुझे यहां क्या समझ नहीं आ रहा है?

उत्तर

3

यह वास्तव में ऐसा प्रतीत होता है। तथ्य यह है कि यह काम करता है सुझाव देता है कि वर्तमान में केवल अंतिम अधिभार ही लागू किया जा रहा है। चूंकि इसमें शामिल विभिन्न पैरामीटर हैं, शायद स्थिर विधि (जो मदद नहीं कर रहा है) को खोना बेहतर होगा:

public override XmlObjectSerializer CreateSerializer(
    Type type, string name, string ns, IList<Type> knownTypes) 
{ 
    return new DataContractSerializer(type, name, ns, knownTypes, 
     0x7FFF /*maxItemsInObjectGraph*/, 
     false/*ignoreExtensionDataObject*/, 
     true/*preserveObjectReferences*/, 
     null/*dataContractSurrogate*/); 
} 

public override XmlObjectSerializer CreateSerializer(
    Type type, XmlDictionaryString name, XmlDictionaryString ns, 
    IList<Type> knownTypes) 
{ 
    return new DataContractSerializer(type, name, ns, knownTypes, 
     0x7FFF /*maxItemsInObjectGraph*/, 
     false/*ignoreExtensionDataObject*/, 
     true/*preserveObjectReferences*/, 
     null/*dataContractSurrogate*/); 
} 
संबंधित मुद्दे