Example #1
0
        public void RegisterAssembly(Assembly assembly, IAttributeRegistry attributeRegistry)
        {
            if (assembly == null)
            {
                throw new ArgumentNullException("assembly");
            }
            if (attributeRegistry == null)
            {
                throw new ArgumentNullException("attributeRegistry");
            }

            // Add automatically the assembly for lookup
            if (!DefaultLookupAssemblies.Contains(assembly) && !lookupAssemblies.Contains(assembly))
            {
                lookupAssemblies.Add(assembly);

                var types = new Type[0];

                // Register all tags automatically.
                foreach (var type in assembly.GetTypes())
                {
                    var tagAttribute = attributeRegistry.GetAttribute <YamlTagAttribute>(type);
                    if (tagAttribute != null && !string.IsNullOrEmpty(tagAttribute.Tag))
                    {
                        RegisterTagMapping(tagAttribute.Tag, type);
                    }

                    // Automatically register YamlSerializableFactory
                    if (typeof(IYamlSerializableFactory).IsAssignableFrom(type) && type.GetConstructor(types) != null)
                    {
                        try
                        {
                            SerializableFactories.Add((IYamlSerializableFactory)Activator.CreateInstance(type));
                        }
                        catch
                        {
                            // Registrying an assembly should not fail, so we are silently discarding a factory if
                            // we are not able to load it.
                        }
                    }
                }
            }
        }
Example #2
0
        public void RegisterAssembly(Assembly assembly, IAttributeRegistry attributeRegistry)
        {
            if (assembly == null) throw new ArgumentNullException("assembly");
            if (attributeRegistry == null) throw new ArgumentNullException("attributeRegistry");

            // Add automatically the assembly for lookup
            if (!DefaultLookupAssemblies.Contains(assembly) && !lookupAssemblies.Contains(assembly))
            {
                lookupAssemblies.Add(assembly);

                var types = new Type[0];

                // Register all tags automatically.
                foreach (var type in assembly.GetTypes())
                {
                    var tagAttribute = attributeRegistry.GetAttribute<YamlTagAttribute>(type);
                    if (tagAttribute != null && !string.IsNullOrEmpty(tagAttribute.Tag))
                    {
                        RegisterTagMapping(tagAttribute.Tag, type);
                    }

                    // Automatically register YamlSerializableFactory
                    if (typeof (IYamlSerializableFactory).IsAssignableFrom(type) && type.GetConstructor(types) != null)
                    {
                        try
                        {
                            SerializableFactories.Add((IYamlSerializableFactory)Activator.CreateInstance(type));
                        }
                        catch
                        {
                            // Registrying an assembly should not fail, so we are silently discarding a factory if
                            // we are not able to load it.
                        }
                    }
                }
            }
        }
        public void RegisterAssembly(Assembly assembly, IAttributeRegistry attributeRegistry)
        {
            if (assembly == null) throw new ArgumentNullException("assembly");
            if (attributeRegistry == null) throw new ArgumentNullException("attributeRegistry");

            // Add automatically the assembly for lookup
            if (!DefaultLookupAssemblies.Contains(assembly) && !lookupAssemblies.Contains(assembly))
            {
                lookupAssemblies.Add(assembly);

                // Register all tags automatically.
                foreach (var type in assembly.GetTypes())
                {
                    var tagAttribute = attributeRegistry.GetAttribute<YamlTagAttribute>(type);
                    if (tagAttribute != null && !string.IsNullOrEmpty(tagAttribute.Tag))
                    {
                        RegisterTagMapping(tagAttribute.Tag, type);
                    }
                }
            }
        }