@@ -20,6 +20,7 @@ module TypeProvider =
20
20
type CssClassesTypeProvider ( config : TypeProviderConfig ) as this =
21
21
inherit DisposableTypeProviderForNamespaces( config )
22
22
23
+ #if LOGGING_ ENABLED
23
24
do
24
25
IO.log ( sprintf " TypeProviderConfig.IsHostedExecution = %b " config.IsHostedExecution )
25
26
IO.log ( sprintf " TypeProviderConfig.IsInvalidationSupported = %b " config.IsInvalidationSupported )
@@ -40,6 +41,7 @@ module TypeProvider =
40
41
41
42
IO.log ( sprintf " Environment.CommandLine = %s " Environment.CommandLine )
42
43
IO.log ( sprintf " Environment.CurrentDirectory = %s " Environment.CurrentDirectory )
44
+ #endif
43
45
44
46
let ns = " Zanaptak.TypedCssClasses"
45
47
let asm = Assembly.GetExecutingAssembly()
@@ -51,6 +53,7 @@ module TypeProvider =
51
53
let source = args.[ 0 ] :?> string
52
54
let naming = args.[ 1 ] :?> Naming
53
55
let resolutionFolder = args.[ 2 ] :?> string
56
+ let getProperties = args.[ 3 ] :?> bool
54
57
55
58
let getSpec _ value =
56
59
@@ -75,6 +78,28 @@ module TypeProvider =
75
78
cssType.AddMember prop
76
79
)
77
80
81
+ if getProperties then
82
+ let rowType = ProvidedTypeDefinition( " Property" , Some( typeof< string[]>), hideObjectMethods = true )
83
+ let rowNameProp = ProvidedProperty( " Name" , typeof< string>, getterCode = fun ( Singleton row ) -> <@@ (%% row: string[]).[ 0 ] @@>)
84
+ rowNameProp.AddXmlDoc " Generated property name using specified naming strategy."
85
+ let rowValueProp = ProvidedProperty( " Value" , typeof< string>, getterCode = fun ( Singleton row ) -> <@@ (%% row: string[]).[ 1 ] @@>)
86
+ rowValueProp.AddXmlDoc " The underlying CSS class value."
87
+
88
+ rowType.AddMember rowNameProp
89
+ rowType.AddMember rowValueProp
90
+ cssType.AddMember rowType
91
+
92
+ let propsArray = cssClasses |> Seq.map ( fun p -> [| p.Name ; p.Value |] ) |> Seq.toArray
93
+ let usedNames = cssClasses |> Seq.map ( fun p -> p.Name ) |> Set.ofSeq
94
+ let methodName =
95
+ Seq.init 99 ( fun i -> " GetProperties" + if i = 0 then " " else " _" + string ( i + 1 ) )
96
+ |> Seq.find ( fun s -> usedNames |> Set.contains s |> not )
97
+ let staticMethod =
98
+ ProvidedMethod( methodName, [], typedefof< seq<_>>. MakeGenericType( rowType), isStatic = true ,
99
+ invokeCode = fun _ -> <@@ propsArray @@>)
100
+
101
+ cssType.AddMember staticMethod
102
+
78
103
{
79
104
GeneratedType = cssType
80
105
RepresentationType = cssType
@@ -88,18 +113,16 @@ module TypeProvider =
88
113
ProvidedStaticParameter( " source" , typeof< string >, parameterDefaultValue = " " )
89
114
ProvidedStaticParameter( " naming" , typeof< Naming >, parameterDefaultValue = Naming.Verbatim )
90
115
ProvidedStaticParameter( " resolutionFolder" , typeof< string >, parameterDefaultValue = " " )
116
+ ProvidedStaticParameter( " getProperties" , typeof< bool >, parameterDefaultValue = false )
91
117
]
92
118
93
119
let helpText = """
94
- <summary>Typed CSS classes.</summary>
120
+ <summary>Typed CSS classes. Provides generated properties representing CSS classes from a stylesheet. </summary>
95
121
<param name='source'>Location of a CSS stylesheet (file path or web URL), or a string containing CSS text.</param>
96
- <param name='naming'>Naming strategy for class name properties, specified by the Naming enum.
97
- Verbatim: (default) use class names verbatim from source CSS, requiring backtick-quotes for names with special characters.
98
- Underscores: replace all non-alphanumeric characters with underscores.
99
- CamelCase: convert to camel case names with all non-alphanumeric characters removed.
100
- PascalCase: convert to Pascal case names with all non-alphanumeric characters removed.
101
- </param>
122
+ <param name='naming'>Naming strategy for class name properties.
123
+ One of: Naming.Verbatim (default), Naming.Underscores, Naming.CamelCase, Naming.PascalCase.</param>
102
124
<param name='resolutionFolder'>A directory that is used when resolving relative file references.</param>
125
+ <param name='getProperties'>Adds a GetProperties() method that returns a seq of all generated property name/value pairs.</param>
103
126
"""
104
127
105
128
do parentType.AddXmlDoc helpText
0 commit comments