[Core] Allow Registrar.RegisterAll to be run multiple times (#215)
authorAlan McGovern <alan.mcgovern@gmail.com>
Wed, 8 Jun 2016 17:30:13 +0000 (18:30 +0100)
committerJason Smith <jason.smith@xamarin.com>
Wed, 8 Jun 2016 17:30:13 +0000 (10:30 -0700)
There are cases where we run RegisterAll manually to ensure all
assemblies have actually been registered. The `Registrar<T>` class
does not use the `Dictionary<K, V>.Add` method so it does not
throw if there's a clash/duplicate.

If we change the `Effect` registration to use the same pattern we
can remove errors like this:

System.ArgumentException: An item with the same key has already been added.
at ThrowArgumentException at offset 0 in file:line:column /Users/builder/data/lanes/2922/977921b7/source/maccore/_build/Library/Frameworks/Xamarin.iOS.framework/Versions/git/src/mono/external/referencesource/mscorlib/system/throwhelper.cs:72:0
at Insert at offset 142 in file:line:column /Users/builder/data/lanes/2922/977921b7/source/maccore/_build/Library/Frameworks/Xamarin.iOS.framework/Versions/git/src/mono/external/referencesource/mscorlib/system/collections/generic/dictionary.cs:336:0
at Add at offset 0 in file:line:column /Users/builder/data/lanes/2922/977921b7/source/maccore/_build/Library/Frameworks/Xamarin.iOS.framework/Versions/git/src/mono/external/referencesource/mscorlib/system/collections/generic/dictionary.cs:192:0
at RegisterAll at <unknown offset> in file:line:column <filename unknown>:0:0
at <unknown method> at <unknown offset> in file:line:column <filename unknown>:0:0
at Invoke at offset 56 in file:line:column /Users/builder/data/lanes/2922/977921b7/source/maccore/_build/Library/Frameworks/Xamarin.iOS.framework/Versions/git/src/mono/mcs/class/corlib/System.Reflection/MonoMethod.cs:295:0

Xamarin.Forms.Core/Registrar.cs

index 92c2e53..1224edf 100644 (file)
@@ -138,7 +138,7 @@ namespace Xamarin.Forms
                                        foreach (Attribute attribute in effectAttributes)
                                        {
                                                var effect = (ExportEffectAttribute)attribute;
-                                               Effects.Add(resolutionName + "." + effect.Id, effect.Type);
+                                               Effects [resolutionName + "." + effect.Id] = effect.Type;
                                        }
                                }
                        }