]> O.S.I.I.S - jp/crow.git/commitdiff
search styles only in entry and crow assemblies and those having the CrowAttribute
authorJean-Philippe Bruyère <jp_bruyere@hotmail.com>
Tue, 2 Jun 2020 01:47:40 +0000 (03:47 +0200)
committerJean-Philippe Bruyère <jp_bruyere@hotmail.com>
Tue, 2 Jun 2020 01:47:40 +0000 (03:47 +0200)
Crow/src/CrowAssemblyAttribute.cs [new file with mode: 0644]
Crow/src/Interface.cs
Crow/src/styling/StyleReader.cs

diff --git a/Crow/src/CrowAssemblyAttribute.cs b/Crow/src/CrowAssemblyAttribute.cs
new file mode 100644 (file)
index 0000000..647a84f
--- /dev/null
@@ -0,0 +1,17 @@
+// Copyright (c) 2013-2020  Jean-Philippe Bruyère <jp_bruyere@hotmail.com>
+//
+// This code is licensed under the MIT license (MIT) (http://opensource.org/licenses/MIT)
+using System;
+namespace Crow
+{
+       /// <summary>
+       /// Add this attribute to an assembly to have it search for Crow ressources (.style, images, templates,...)
+       /// </summary>
+       /// <remarks>
+       /// By default, only the entry assembly and the crow assembly will be searched for resources.
+       /// </remarks>
+       [AttributeUsage (AttributeTargets.Assembly)]
+       public class CrowAttribute : Attribute
+       {
+       }
+}
index adae26bc86352427b54fac23cbc6185b9ab529d2..e11d597b3142bc9f1db0b0eb02ed06d91f413f03 100644 (file)
@@ -52,6 +52,8 @@ namespace Crow
                }
                #endregion
 
+               internal static List<Assembly> crowAssemblies = new List<Assembly> ();
+
                #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);
+                       }
                }
                /// <summary> Search for .style resources in assembly </summary>
                protected void loadStylingFromAssembly (Assembly assembly) {
index 218032e7602c5f40ecf3ab848a5111cccbd3831d..f7ccf224fb4560e73f8528ccf12f37feda7f58bc 100644 (file)
@@ -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;
                                        }