public static void PopulateJsonDelegateDictionary(
            Dictionary<Type, DataContract> dataContracts,                   // not modified
            Dictionary<DataContract, JsonReadWriteDelegates> jsonDelegates) // modified
        {
            for (int i = 0; i < JsonDelegatesList.Length; i++)
            {
                int mapIndex = JsonDelegatesList[i].DataContractMapIndex;
                Type userType = Type.GetTypeFromHandle(DataContractMap[mapIndex].UserCodeType.RuntimeTypeHandle);
                DataContract contract = dataContracts[userType];
                JsonReadWriteDelegates delegates;

                if (JsonDelegatesList[i].IsCollection)
                {
                    delegates = new JsonReadWriteDelegates
                    {
                        CollectionWriterDelegate = (JsonFormatCollectionWriterDelegate)DelegateFromIntPtr(typeof(JsonFormatCollectionWriterDelegate), JsonDelegatesList[i].WriterDelegate),
                        CollectionReaderDelegate = (JsonFormatCollectionReaderDelegate)DelegateFromIntPtr(typeof(JsonFormatCollectionReaderDelegate), JsonDelegatesList[i].ReaderDelegate),
                        GetOnlyCollectionReaderDelegate = (JsonFormatGetOnlyCollectionReaderDelegate)DelegateFromIntPtr(typeof(JsonFormatGetOnlyCollectionReaderDelegate), JsonDelegatesList[i].GetOnlyReaderDelegate),
                    };
                }
                else
                {
                    delegates = new JsonReadWriteDelegates
                    {
                        ClassWriterDelegate = (JsonFormatClassWriterDelegate)DelegateFromIntPtr(typeof(JsonFormatClassWriterDelegate), JsonDelegatesList[i].WriterDelegate),
                        ClassReaderDelegate = (JsonFormatClassReaderDelegate)DelegateFromIntPtr(typeof(JsonFormatClassReaderDelegate), JsonDelegatesList[i].ReaderDelegate),
                    };
                }
                jsonDelegates.Add(contract, delegates);
            }
        }
示例#2
0
        public static void PopulateJsonDelegateDictionary(
            Dictionary <Type, DataContract> dataContracts,                   // not modified
            Dictionary <DataContract, JsonReadWriteDelegates> jsonDelegates) // modified
        {
            for (int i = 0; i < JsonDelegatesList.Length; i++)
            {
                int                    mapIndex = JsonDelegatesList[i].DataContractMapIndex;
                Type                   userType = Type.GetTypeFromHandle(DataContractMap[mapIndex].UserCodeType.RuntimeTypeHandle);
                DataContract           contract = dataContracts[userType];
                JsonReadWriteDelegates delegates;

                if (JsonDelegatesList[i].IsCollection)
                {
                    delegates = new JsonReadWriteDelegates
                    {
                        CollectionWriterDelegate        = (JsonFormatCollectionWriterDelegate)DelegateFromIntPtr(typeof(JsonFormatCollectionWriterDelegate), JsonDelegatesList[i].WriterDelegate),
                        CollectionReaderDelegate        = (JsonFormatCollectionReaderDelegate)DelegateFromIntPtr(typeof(JsonFormatCollectionReaderDelegate), JsonDelegatesList[i].ReaderDelegate),
                        GetOnlyCollectionReaderDelegate = (JsonFormatGetOnlyCollectionReaderDelegate)DelegateFromIntPtr(typeof(JsonFormatGetOnlyCollectionReaderDelegate), JsonDelegatesList[i].GetOnlyReaderDelegate),
                    };
                }
                else
                {
                    delegates = new JsonReadWriteDelegates
                    {
                        ClassWriterDelegate = (JsonFormatClassWriterDelegate)DelegateFromIntPtr(typeof(JsonFormatClassWriterDelegate), JsonDelegatesList[i].WriterDelegate),
                        ClassReaderDelegate = (JsonFormatClassReaderDelegate)DelegateFromIntPtr(typeof(JsonFormatClassReaderDelegate), JsonDelegatesList[i].ReaderDelegate),
                    };
                }

                if (!jsonDelegates.ContainsKey(contract))
                {
                    jsonDelegates.Add(contract, delegates);
                }
            }
        }