Exemplo n.º 1
0
        public static void RegisterSerializationAssembly(AssemblySerializers assemblySerializers)
        {
            lock (Lock)
            {
                // Register it (so that we can get it back if unregistered)
                if (!AvailableAssemblySerializers.ContainsKey(assemblySerializers.Assembly))
                {
                    AvailableAssemblySerializers.Add(assemblySerializers.Assembly, assemblySerializers);
                }

                // Check if already loaded
                if (AssemblySerializers.Contains(assemblySerializers))
                {
                    return;
                }

                // Update existing SerializerSelector
                AssemblySerializers.Add(assemblySerializers);
            }

            // Run module ctor
            foreach (var module in assemblySerializers.Modules)
            {
                ModuleRuntimeHelpers.RunModuleConstructor(module);
            }

            lock (Lock)
            {
                RegisterSerializers(assemblySerializers);

                ++Version;

                // Invalidate each serializer selector (to force them to rebuild combined list of serializers)
                foreach (var weakSerializerSelector in SerializerSelectors)
                {
                    SerializerSelector serializerSelector;
                    if (weakSerializerSelector.TryGetTarget(out serializerSelector))
                    {
                        serializerSelector.Invalidate();
                    }
                }
            }
        }
Exemplo n.º 2
0
        private static void RegisterSerializers(AssemblySerializers assemblySerializers)
        {
            // Register serializers
            foreach (var assemblySerializerPerProfile in assemblySerializers.Profiles)
            {
                var profile = assemblySerializerPerProfile.Key;

                Dictionary <Type, AssemblySerializerEntry> dataSerializers;
                if (!DataSerializersPerProfile.TryGetValue(profile, out dataSerializers))
                {
                    dataSerializers = new Dictionary <Type, AssemblySerializerEntry>();
                    DataSerializersPerProfile.Add(profile, dataSerializers);
                }

                foreach (var assemblySerializer in assemblySerializerPerProfile.Value)
                {
                    if (!dataSerializers.ContainsKey(assemblySerializer.ObjectType))
                    {
                        dataSerializers.Add(assemblySerializer.ObjectType, assemblySerializer);
                    }
                }
            }
        }
Exemplo n.º 3
0
        private static void RegisterSerializers(AssemblySerializers assemblySerializers)
        {
            // Register data contract aliases
            foreach (var dataContractAliasEntry in assemblySerializers.DataContractAliases)
            {
                try
                {
                    // TODO: Warning, exception or override if collision? (currently exception)
                    dataContractAliasMapping.Add(dataContractAliasEntry.Key, dataContractAliasEntry.Value);
                }
                catch (Exception)
                {
                    throw new InvalidOperationException($"Two different classes have the same DataContract Alias [{dataContractAliasEntry.Key}]: {dataContractAliasEntry.Value} and {dataContractAliasMapping[dataContractAliasEntry.Key]}");
                }
            }

            // Register serializers
            foreach (var assemblySerializerPerProfile in assemblySerializers.Profiles)
            {
                var profile = assemblySerializerPerProfile.Key;

                Dictionary <Type, AssemblySerializerEntry> dataSerializers;
                if (!DataSerializersPerProfile.TryGetValue(profile, out dataSerializers))
                {
                    dataSerializers = new Dictionary <Type, AssemblySerializerEntry>();
                    DataSerializersPerProfile.Add(profile, dataSerializers);
                }

                foreach (var assemblySerializer in assemblySerializerPerProfile.Value)
                {
                    if (!dataSerializers.ContainsKey(assemblySerializer.ObjectType))
                    {
                        dataSerializers.Add(assemblySerializer.ObjectType, assemblySerializer);
                    }
                }
            }
        }