forked from fsprojects/FsXaml
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
dispose FileSystemWatcher in TP.Dispose() method
- Loading branch information
Vasily Kirichenko
authored and
Vasily Kirichenko
committed
Jun 11, 2014
1 parent
e4c4f93
commit cff5b83
Showing
2 changed files
with
17 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -227,7 +227,13 @@ type public XamlTypeProvider(config : TypeProviderConfig) as this = | |
let assembly = Assembly.GetExecutingAssembly() | ||
let nameSpace = this.GetType().Namespace | ||
let providerType = ProvidedTypeDefinition(assembly, nameSpace, "XAML", Some typeof<obj>, IsErased = false) | ||
let missingValue = "@@@missingValue###" | ||
let fileSystemWatcher: IDisposable option ref = ref None | ||
|
||
let disposeFileSystemWatcher() = | ||
!fileSystemWatcher |> Option.iter (fun x -> | ||
Diagnostics.Debug.WriteLine ("[FsXaml] Disposing FileSystemWatcher.") | ||
x.Dispose()) | ||
fileSystemWatcher := None | ||
|
||
let assemblies = | ||
config.ReferencedAssemblies | ||
|
@@ -260,21 +266,20 @@ type public XamlTypeProvider(config : TypeProviderConfig) as this = | |
instantiationFunction = (fun typeName parameterValues -> | ||
let resourcePath = string parameterValues.[0] | ||
let resolvedFileName = findConfigFile config.ResolutionFolder resourcePath | ||
watchForChanges this resolvedFileName | ||
disposeFileSystemWatcher() | ||
This comment has been minimized.
Sorry, something went wrong.
This comment has been minimized.
Sorry, something went wrong.
dsyme
|
||
Diagnostics.Debug.WriteLine ("[FsXaml] Creating FileSystemWatcher.") | ||
fileSystemWatcher := watchForChanges this resolvedFileName | ||
|
||
use reader = new StreamReader(resolvedFileName) | ||
let elements = XamlTypeUtils.readElements schemaContext reader resolvedFileName | ||
|
||
let root = List.head elements | ||
|
||
let ucType = typeof<System.Windows.Controls.UserControl> | ||
|
||
let outerType = | ||
let createFactoryType factoryType = | ||
let outertype = ProvidedTypeDefinition(assembly, nameSpace, typeName, Some(factoryType), IsErased = false) | ||
let ctor = ProvidedConstructor([]) | ||
ctor.BaseConstructorCall <- fun args -> factoryType.GetConstructors().[0], [Expr.Value(resourcePath)] | ||
ctor.InvokeCode <- fun args -> <@@ 0 @@> | ||
ctor.BaseConstructorCall <- fun _ -> factoryType.GetConstructors().[0], [Expr.Value(resourcePath)] | ||
ctor.InvokeCode <- fun _ -> <@@ 0 @@> | ||
outertype.AddMember ctor | ||
outertype | ||
match root.NodeType with | ||
|
@@ -298,5 +303,8 @@ type public XamlTypeProvider(config : TypeProviderConfig) as this = | |
|
||
this.AddNamespace(nameSpace, [ providerType ]) | ||
|
||
interface IDisposable with | ||
member __.Dispose() = disposeFileSystemWatcher() | ||
|
||
[<assembly:TypeProviderAssembly>] | ||
do() |
FWIW this logic isn't right - all watchers should be collected into a list of dispose actions, and all disposals done when the overall XamlTypeProvider object is disposed.