From: Jean-Philippe Bruyère Date: Tue, 2 Jun 2020 01:47:40 +0000 (+0200) Subject: search styles only in entry and crow assemblies and those having the CrowAttribute X-Git-Tag: v0.9.5-beta~113^2~20 X-Git-Url: https://git.osiis.dedyn.io/?a=commitdiff_plain;h=1297957606b5753bcf4ed39ee7968d008f873171;p=jp%2Fcrow.git search styles only in entry and crow assemblies and those having the CrowAttribute --- diff --git a/Crow/src/CrowAssemblyAttribute.cs b/Crow/src/CrowAssemblyAttribute.cs new file mode 100644 index 00000000..647a84fe --- /dev/null +++ b/Crow/src/CrowAssemblyAttribute.cs @@ -0,0 +1,17 @@ +// Copyright (c) 2013-2020 Jean-Philippe Bruyère +// +// This code is licensed under the MIT license (MIT) (http://opensource.org/licenses/MIT) +using System; +namespace Crow +{ + /// + /// Add this attribute to an assembly to have it search for Crow ressources (.style, images, templates,...) + /// + /// + /// By default, only the entry assembly and the crow assembly will be searched for resources. + /// + [AttributeUsage (AttributeTargets.Assembly)] + public class CrowAttribute : Attribute + { + } +} diff --git a/Crow/src/Interface.cs b/Crow/src/Interface.cs index adae26bc..e11d597b 100644 --- a/Crow/src/Interface.cs +++ b/Crow/src/Interface.cs @@ -52,6 +52,8 @@ namespace Crow } #endregion + internal static List crowAssemblies = new List (); + #region CTOR static Interface () { @@ -70,9 +72,13 @@ namespace Crow //ensure all assemblies are loaded, because IML could contains classes not instanciated in source foreach (string af in Directory.GetFiles (AppDomain.CurrentDomain.BaseDirectory, "*.dll")) { try { - Assembly.LoadFrom (af); + Assembly a =Assembly.LoadFrom (af); + if (a == Assembly.GetEntryAssembly () || a == Assembly.GetExecutingAssembly ()) + continue; + if (a.GetCustomAttribute (typeof (CrowAttribute)) != null) + crowAssemblies.Add (a); } catch { - System.Diagnostics.Debug.WriteLine ("{0} not loaded as assembly.", af); + Debug.WriteLine ("{0} not loaded as assembly.", af); } } @@ -453,6 +459,10 @@ namespace Crow //assembly, it's ignored. loadStylingFromAssembly (Assembly.GetEntryAssembly ()); loadStylingFromAssembly (Assembly.GetExecutingAssembly ()); + + foreach (Assembly a in crowAssemblies) { + loadStylingFromAssembly (a); + } } /// Search for .style resources in assembly protected void loadStylingFromAssembly (Assembly assembly) { diff --git a/Crow/src/styling/StyleReader.cs b/Crow/src/styling/StyleReader.cs index 218032e7..f7ccf224 100644 --- a/Crow/src/styling/StyleReader.cs +++ b/Crow/src/styling/StyleReader.cs @@ -150,21 +150,17 @@ namespace Crow throw new ParserException (line, column, "Unexpected end of statement", resId); ReadChar (); if (targetsClasses.Count == 0) { - //style constant - if (!iFace.StylingConstants.ContainsKey (currentProperty)) - iFace.StylingConstants.Add (currentProperty, token); + //style constants + iFace.StylingConstants[currentProperty] = token; curState = States.classNames; } else { foreach (string tc in targetsClasses) { if (!iFace.Styling.ContainsKey (tc)) iFace.Styling [tc] = new Style (); - else if (iFace.Styling [tc].ContainsKey (currentProperty)) - continue; iFace.Styling [tc] [currentProperty] = token; #if DESIGN_MODE styling [tc].Locations[currentProperty] = new FileLocation(resId, line, column - token.Length - 1, token.Length); #endif - //System.Diagnostics.Debug.WriteLine ("Style: {3} : {0}.{1} = {2}", tc, currentProperty, token, resId); } curState = States.members; }