From 6015aa261a7ae907918a04502ac5d259491cd2af Mon Sep 17 00:00:00 2001 From: kingces95 Date: Thu, 18 Jul 2019 02:43:26 -1000 Subject: [PATCH] opt-in init (#6149) --- Xamarin.Forms.Core/Registrar.cs | 46 ++++++++++++++--------------------------- 1 file changed, 15 insertions(+), 31 deletions(-) diff --git a/Xamarin.Forms.Core/Registrar.cs b/Xamarin.Forms.Core/Registrar.cs index aa97c0a..cf1cfe3 100644 --- a/Xamarin.Forms.Core/Registrar.cs +++ b/Xamarin.Forms.Core/Registrar.cs @@ -4,6 +4,7 @@ using System.ComponentModel; using System.Linq; using System.Reflection; using Xamarin.Forms.Internals; +using Xamarin.Forms.StyleSheets; namespace Xamarin.Forms { @@ -265,21 +266,21 @@ namespace Xamarin.Forms.Internals public static void RegisterStylesheets() { - var assembly = typeof(StyleSheets.StylePropertyAttribute).GetTypeInfo().Assembly; + var assembly = typeof(StylePropertyAttribute).GetTypeInfo().Assembly; #if NETSTANDARD2_0 - object[] styleAttributes = assembly.GetCustomAttributes(typeof(StyleSheets.StylePropertyAttribute), true); + object[] styleAttributes = assembly.GetCustomAttributes(typeof(StylePropertyAttribute), true); #else object[] styleAttributes = assembly.GetCustomAttributes(typeof(StyleSheets.StylePropertyAttribute)).ToArray(); #endif var stylePropertiesLength = styleAttributes.Length; for (var i = 0; i < stylePropertiesLength; i++) { - var attribute = (StyleSheets.StylePropertyAttribute)styleAttributes[i]; + var attribute = (StylePropertyAttribute)styleAttributes[i]; if (StyleProperties.TryGetValue(attribute.CssPropertyName, out var attrList)) attrList.Add(attribute); else - StyleProperties[attribute.CssPropertyName] = new List { attribute }; + StyleProperties[attribute.CssPropertyName] = new List { attribute }; } } @@ -340,13 +341,9 @@ namespace Xamarin.Forms.Internals continue; } - var length = attributes.Length; - for (var i = 0; i < length; i++) - { - var attribute = (HandlerAttribute)attributes[i]; - if (attribute.ShouldRegister()) - Registered.Register(attribute.HandlerType, attribute.TargetType, attribute.SupportedVisuals); - } + var handlerAttributes = new HandlerAttribute[attributes.Length]; + Array.Copy(attributes, handlerAttributes, attributes.Length); + RegisterRenderers(handlerAttributes); } string resolutionName = assembly.FullName; @@ -359,29 +356,16 @@ namespace Xamarin.Forms.Internals #else object[] effectAttributes = assembly.GetCustomAttributes(typeof(ExportEffectAttribute)).ToArray(); #endif - var exportEffectsLength = effectAttributes.Length; - for (var i = 0; i < exportEffectsLength; i++) - { - var effect = (ExportEffectAttribute)effectAttributes[i]; - Effects[resolutionName + "." + effect.Id] = effect.Type; - } + var typedEffectAttributes = new ExportEffectAttribute[effectAttributes.Length]; + Array.Copy(effectAttributes, typedEffectAttributes, effectAttributes.Length); + RegisterEffects(resolutionName, typedEffectAttributes); + Profile.FrameEnd(); -#if NETSTANDARD2_0 - object[] styleAttributes = assembly.GetCustomAttributes(typeof(StyleSheets.StylePropertyAttribute), true); -#else - object[] styleAttributes = assembly.GetCustomAttributes(typeof(StyleSheets.StylePropertyAttribute)).ToArray(); -#endif - var stylePropertiesLength = styleAttributes.Length; - for (var i = 0; i < stylePropertiesLength; i++) - { - var attribute = (StyleSheets.StylePropertyAttribute)styleAttributes[i]; - if (StyleProperties.TryGetValue(attribute.CssPropertyName, out var attrList)) - attrList.Add(attribute); - else - StyleProperties[attribute.CssPropertyName] = new List { attribute }; - } } + if ((flags & ActivationFlags.NoCss) == 0) + RegisterStylesheets(); + Profile.FramePartition("DependencyService.Initialize"); DependencyService.Initialize(assemblies); -- 2.7.4