From 7dc8e0b947d581cfe2fd2e902eeba3a53f553e26 Mon Sep 17 00:00:00 2001 From: Siegfried Pammer Date: Tue, 8 Sep 2009 19:09:07 +0000 Subject: [PATCH] - fixed bug in OptionBinding - ported Profiler option panels to new architecture git-svn-id: svn://svn.sharpdevelop.net/sharpdevelop/trunk@4898 1ccf3a8d-04fe-1044-b7c0-cef0b8235c61 --- .../Misc/Profiler/Frontend/AddIn/AddIn.csproj | 11 +-- .../AddIn/ICSharpCode.Profiler.AddIn.addin | 2 +- .../Src/Dialogs/ProfileExecutableForm.xaml.cs | 7 +- .../Src/Dialogs/ProfilerControlWindow.xaml.cs | 4 +- .../AddIn/Src/OptionPanels/General.cs | 31 +++++++ .../AddIn/Src/OptionPanels/General.xaml | 72 ++++++++++++++++ .../AddIn/Src/OptionPanels/OptionWrapper.cs | 53 ++++++++++++ .../AddIn/Src/OptionsPanels/General.cs | 82 ------------------- .../OptionsPanels/GeneralOptionsPanel.xaml | 53 ------------ .../OptionsPanels/GeneralOptionsPanel.xaml.cs | 81 ------------------ .../Frontend/AddIn/Src/ProfilerRunner.cs | 11 +-- src/AddIns/Misc/Profiler/Profiler.sln | 36 ++++---- .../OptionBinding.cs | 37 +++++++-- 13 files changed, 219 insertions(+), 261 deletions(-) create mode 100644 src/AddIns/Misc/Profiler/Frontend/AddIn/Src/OptionPanels/General.cs create mode 100644 src/AddIns/Misc/Profiler/Frontend/AddIn/Src/OptionPanels/General.xaml create mode 100644 src/AddIns/Misc/Profiler/Frontend/AddIn/Src/OptionPanels/OptionWrapper.cs delete mode 100644 src/AddIns/Misc/Profiler/Frontend/AddIn/Src/OptionsPanels/General.cs delete mode 100644 src/AddIns/Misc/Profiler/Frontend/AddIn/Src/OptionsPanels/GeneralOptionsPanel.xaml delete mode 100644 src/AddIns/Misc/Profiler/Frontend/AddIn/Src/OptionsPanels/GeneralOptionsPanel.xaml.cs diff --git a/src/AddIns/Misc/Profiler/Frontend/AddIn/AddIn.csproj b/src/AddIns/Misc/Profiler/Frontend/AddIn/AddIn.csproj index 5db5e2992c..e2ca2f972e 100644 --- a/src/AddIns/Misc/Profiler/Frontend/AddIn/AddIn.csproj +++ b/src/AddIns/Misc/Profiler/Frontend/AddIn/AddIn.csproj @@ -7,7 +7,6 @@ ICSharpCode.Profiler.AddIn ICSharpCode.Profiler.AddIn v4.0 - C:\Dokumente und Einstellungen\HP\Anwendungsdaten\ICSharpCode/SharpDevelop3.0\Settings.SourceAnalysis False False 4 @@ -63,12 +62,10 @@ Code - - - - GeneralOptionsPanel.xaml - Code + + General.xaml + @@ -84,7 +81,7 @@ MSBuild:Compile - + Designer MSBuild:Compile diff --git a/src/AddIns/Misc/Profiler/Frontend/AddIn/ICSharpCode.Profiler.AddIn.addin b/src/AddIns/Misc/Profiler/Frontend/AddIn/ICSharpCode.Profiler.AddIn.addin index d6a91a8ada..371d3819e6 100644 --- a/src/AddIns/Misc/Profiler/Frontend/AddIn/ICSharpCode.Profiler.AddIn.addin +++ b/src/AddIns/Misc/Profiler/Frontend/AddIn/ICSharpCode.Profiler.AddIn.addin @@ -84,7 +84,7 @@ diff --git a/src/AddIns/Misc/Profiler/Frontend/AddIn/Src/Dialogs/ProfileExecutableForm.xaml.cs b/src/AddIns/Misc/Profiler/Frontend/AddIn/Src/Dialogs/ProfileExecutableForm.xaml.cs index ad56e0fc1a..63d0463818 100644 --- a/src/AddIns/Misc/Profiler/Frontend/AddIn/Src/Dialogs/ProfileExecutableForm.xaml.cs +++ b/src/AddIns/Misc/Profiler/Frontend/AddIn/Src/Dialogs/ProfileExecutableForm.xaml.cs @@ -1,14 +1,13 @@ -using ICSharpCode.SharpDevelop; -using System; +using System; using System.Diagnostics; using System.Globalization; using System.IO; using System.Windows; + using ICSharpCode.Core; -using ICSharpCode.Profiler.AddIn.OptionsPanels; -using ICSharpCode.Profiler.AddIn.Views; using ICSharpCode.Profiler.Controller; using ICSharpCode.Profiler.Controller.Data; +using ICSharpCode.SharpDevelop; using ICSharpCode.SharpDevelop.Gui; using Microsoft.Win32; diff --git a/src/AddIns/Misc/Profiler/Frontend/AddIn/Src/Dialogs/ProfilerControlWindow.xaml.cs b/src/AddIns/Misc/Profiler/Frontend/AddIn/Src/Dialogs/ProfilerControlWindow.xaml.cs index e61928d14d..662c3c9260 100644 --- a/src/AddIns/Misc/Profiler/Frontend/AddIn/Src/Dialogs/ProfilerControlWindow.xaml.cs +++ b/src/AddIns/Misc/Profiler/Frontend/AddIn/Src/Dialogs/ProfilerControlWindow.xaml.cs @@ -39,7 +39,7 @@ namespace ICSharpCode.Profiler.AddIn.Dialogs try { this.runner.Profiler.EnableDataCollection(); } catch (Exception ex) { - MessageService.ShowError(ex); + MessageService.ShowException(ex); } } @@ -48,7 +48,7 @@ namespace ICSharpCode.Profiler.AddIn.Dialogs try { this.runner.Profiler.DisableDataCollection(); } catch (Exception ex) { - MessageService.ShowError(ex); + MessageService.ShowException(ex); } } diff --git a/src/AddIns/Misc/Profiler/Frontend/AddIn/Src/OptionPanels/General.cs b/src/AddIns/Misc/Profiler/Frontend/AddIn/Src/OptionPanels/General.cs new file mode 100644 index 0000000000..309e6e7a6b --- /dev/null +++ b/src/AddIns/Misc/Profiler/Frontend/AddIn/Src/OptionPanels/General.cs @@ -0,0 +1,31 @@ +// +// +// +// +// $Revision$ +// + +using System; +using System.Collections.Generic; +using System.Windows.Forms; +using System.Windows.Forms.Integration; + +using ICSharpCode.Core; +using ICSharpCode.Profiler.Controller; +using ICSharpCode.SharpDevelop; +using ICSharpCode.SharpDevelop.Gui; +using System.Windows.Threading; + +namespace ICSharpCode.Profiler.AddIn.OptionPanels +{ + /// + /// Description of General + /// + public partial class General : OptionPanel + { + public General() + { + InitializeComponent(); + } + } +} diff --git a/src/AddIns/Misc/Profiler/Frontend/AddIn/Src/OptionPanels/General.xaml b/src/AddIns/Misc/Profiler/Frontend/AddIn/Src/OptionPanels/General.xaml new file mode 100644 index 0000000000..f05abb37ea --- /dev/null +++ b/src/AddIns/Misc/Profiler/Frontend/AddIn/Src/OptionPanels/General.xaml @@ -0,0 +1,72 @@ + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/src/AddIns/Misc/Profiler/Frontend/AddIn/Src/OptionPanels/OptionWrapper.cs b/src/AddIns/Misc/Profiler/Frontend/AddIn/Src/OptionPanels/OptionWrapper.cs new file mode 100644 index 0000000000..86aaf4f61e --- /dev/null +++ b/src/AddIns/Misc/Profiler/Frontend/AddIn/Src/OptionPanels/OptionWrapper.cs @@ -0,0 +1,53 @@ +// +// +// +// +// $Revision$ +// +using ICSharpCode.Profiler.Controller; +using System; +using ICSharpCode.Core; + +namespace ICSharpCode.Profiler.AddIn.OptionPanels +{ + public static class OptionWrapper + { + static Properties properties = PropertyService.Get("ProfilerOptions", new Properties()); + + public static int SharedMemorySize { + get { return properties.Get("SharedMemorySize", ProfilerOptions.DefaultSharedMemorySize) / 1024 / 1024; } + set { properties.Set("SharedMemorySize", value * 1024 * 1024); } + } + + public static bool EnableDC { + get { return !properties.Get("EnableDC", true); } + set { properties.Set("EnableDC", !value); } + } + + public static bool DoNotProfileNetInternals { + get { return properties.Get("DoNotProfileNetInternals", false); } + set { properties.Set("DoNotProfileNetInternals", value); } + } + + public static bool CombineRecursiveCalls { + get { return properties.Get("CombineRecursiveFunction", false); } + set { properties.Set("CombineRecursiveFunction", value); } + } + + public static bool EnableDCAtStart { + get { return properties.Get("EnableDCAtStart", true); } + set { properties.Set("EnableDCAtStart", value); } + } + + public static ProfilerOptions CreateProfilerOptions() + { + return new ProfilerOptions( + properties.Get("EnableDC", true), + properties.Get("SharedMemorySize", ProfilerOptions.DefaultSharedMemorySize), + properties.Get("DoNotProfileNetInternals", false), + properties.Get("CombineRecursiveFunction", false), + properties.Get("EnableDCAtStart", true) + ); + } + } +} diff --git a/src/AddIns/Misc/Profiler/Frontend/AddIn/Src/OptionsPanels/General.cs b/src/AddIns/Misc/Profiler/Frontend/AddIn/Src/OptionsPanels/General.cs deleted file mode 100644 index 18e10ef37f..0000000000 --- a/src/AddIns/Misc/Profiler/Frontend/AddIn/Src/OptionsPanels/General.cs +++ /dev/null @@ -1,82 +0,0 @@ -// -// -// -// -// $Revision$ -// - -using System; -using System.Collections.Generic; -using System.Windows.Forms; -using System.Windows.Forms.Integration; - -using ICSharpCode.Core; -using ICSharpCode.Profiler.Controller; -using ICSharpCode.SharpDevelop; -using ICSharpCode.SharpDevelop.Gui; -using System.Windows.Threading; - -namespace ICSharpCode.Profiler.AddIn.OptionsPanels -{ - /// - /// Description of General - /// - public class General : OptionPanel - { - GeneralOptionsPanel panel; - - static Properties properties = PropertyService.Get("ProfilerOptions", new Properties()); - - public General() - { - panel = new GeneralOptionsPanel(); - } - - public override object Control { - get { - return panel; - } - } - - public override void LoadOptions() - { - try { - panel.SetOptionValue("EnableDC", !properties.Get("EnableDC", true)); - panel.SetOptionValue("SharedMemorySize", properties.Get("SharedMemorySize", ProfilerOptions.DefaultSharedMemorySize) / 1024 / 1024); - panel.SetOptionValue("DoNotProfileNetInternals", properties.Get("DoNotProfileNetInternals", false)); - panel.SetOptionValue("CombineRecursiveFunction", properties.Get("CombineRecursiveFunction", false)); - panel.SetOptionValue("EnableDCAtStart", properties.Get("EnableDCAtStart", true)); - base.LoadPanelContents(); - } catch (Exception e) { - MessageService.ShowError(e); - } - } - - public override bool SaveOptions() - { - try { - properties.Set("EnableDC", !panel.GetOptionValue("EnableDC")); - properties.Set("SharedMemorySize", (int)panel.GetOptionValue("SharedMemorySize") * 1024 * 1024); - properties.Set("DoNotProfileNetInternals", panel.GetOptionValue("DoNotProfileNetInternals")); - properties.Set("CombineRecursiveFunction", panel.GetOptionValue("CombineRecursiveFunction")); - properties.Set("EnableDCAtStart", panel.GetOptionValue("EnableDCAtStart")); - return base.StorePanelContents(); - } catch (Exception e) { - MessageService.ShowError(e); - } - - return false; - } - - public static ProfilerOptions CreateProfilerOptions() - { - return new ProfilerOptions( - properties.Get("EnableDC", true), - properties.Get("SharedMemorySize", ProfilerOptions.DefaultSharedMemorySize), - properties.Get("DoNotProfileNetInternals", false), - properties.Get("CombineRecursiveFunction", false), - properties.Get("EnableDCAtStart", true) - ); - } - } -} diff --git a/src/AddIns/Misc/Profiler/Frontend/AddIn/Src/OptionsPanels/GeneralOptionsPanel.xaml b/src/AddIns/Misc/Profiler/Frontend/AddIn/Src/OptionsPanels/GeneralOptionsPanel.xaml deleted file mode 100644 index f2f42e521c..0000000000 --- a/src/AddIns/Misc/Profiler/Frontend/AddIn/Src/OptionsPanels/GeneralOptionsPanel.xaml +++ /dev/null @@ -1,53 +0,0 @@ - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/src/AddIns/Misc/Profiler/Frontend/AddIn/Src/OptionsPanels/GeneralOptionsPanel.xaml.cs b/src/AddIns/Misc/Profiler/Frontend/AddIn/Src/OptionsPanels/GeneralOptionsPanel.xaml.cs deleted file mode 100644 index 11e942bfbe..0000000000 --- a/src/AddIns/Misc/Profiler/Frontend/AddIn/Src/OptionsPanels/GeneralOptionsPanel.xaml.cs +++ /dev/null @@ -1,81 +0,0 @@ -using ICSharpCode.Profiler.Interprocess; -using System; -using System.Collections.Generic; -using System.Text; -using System.Windows; -using System.Windows.Controls; -using System.Windows.Data; -using System.Windows.Documents; -using System.Windows.Input; -using System.Windows.Media; -using System.Windows.Media.Imaging; -using System.Windows.Navigation; -using System.Windows.Shapes; -using System.Management; -using System.Linq; - -namespace ICSharpCode.Profiler.AddIn.OptionsPanels -{ - /// - /// Interaction logic for GeneralOptionsPanel.xaml - /// - public partial class GeneralOptionsPanel : UserControl - { - public GeneralOptionsPanel() - { - InitializeComponent(); - } - - public T GetOptionValue(string name) - { - object o = null; - - switch (name) { - case "SharedMemorySize": - o = this.slSharedMemorySize.Value; - break; - case "EnableDC": - o = this.chkEnableDC.IsChecked; - break; - case "DoNotProfileNetInternals": - o = this.chkDoNotProfileNetInternals.IsChecked; - break; - case "CombineRecursiveFunction": - o = this.chkCombineRecursiveCalls.IsChecked; - break; - case "EnableDCAtStart": - o = this.chkEnableDCAtStartup.IsChecked; - break; - default: - throw new NotSupportedException("value '" + name + "' is not supported!"); - } - - return (T)o; - } - - public void SetOptionValue(string name, T value) - { - object o = value; - - switch (name) { - case "SharedMemorySize": - this.slSharedMemorySize.Value = (int)o; - break; - case "EnableDC": - this.chkEnableDC.IsChecked = (bool)o; - break; - case "DoNotProfileNetInternals": - this.chkDoNotProfileNetInternals.IsChecked = (bool)o; - break; - case "CombineRecursiveFunction": - this.chkCombineRecursiveCalls.IsChecked = (bool)o; - break; - case "EnableDCAtStart": - this.chkEnableDCAtStartup.IsChecked = (bool)o; - break; - default: - throw new NotSupportedException("value '" + name + "' is not supported!"); - } - } - } -} \ No newline at end of file diff --git a/src/AddIns/Misc/Profiler/Frontend/AddIn/Src/ProfilerRunner.cs b/src/AddIns/Misc/Profiler/Frontend/AddIn/Src/ProfilerRunner.cs index 7696b555f3..43c1fff79d 100644 --- a/src/AddIns/Misc/Profiler/Frontend/AddIn/Src/ProfilerRunner.cs +++ b/src/AddIns/Misc/Profiler/Frontend/AddIn/Src/ProfilerRunner.cs @@ -8,13 +8,10 @@ using System; using System.Diagnostics; using System.IO; -using System.Windows; -using System.Windows.Controls; -using System.Windows.Controls.Primitives; using ICSharpCode.Core; using ICSharpCode.Profiler.AddIn.Dialogs; -using ICSharpCode.Profiler.AddIn.OptionsPanels; +using ICSharpCode.Profiler.AddIn.OptionPanels; using ICSharpCode.Profiler.Controller.Data; using ICSharpCode.SharpDevelop.Gui; using ICSharpCode.SharpDevelop.Project; @@ -57,11 +54,11 @@ namespace ICSharpCode.Profiler.AddIn if (useTempFileDatabase) { this.database = new TempFileDatabase(); this.writer = writer; - this.profiler = new Controller.Profiler(startInfo, this.database.GetWriter(), General.CreateProfilerOptions()); + this.profiler = new Controller.Profiler(startInfo, this.database.GetWriter(), OptionWrapper.CreateProfilerOptions()); } else { this.database = null; this.writer = writer; - this.profiler = new Controller.Profiler(startInfo, writer, General.CreateProfilerOptions()); + this.profiler = new Controller.Profiler(startInfo, writer, OptionWrapper.CreateProfilerOptions()); } PrintProfilerOptions(); @@ -73,7 +70,7 @@ namespace ICSharpCode.Profiler.AddIn void PrintProfilerOptions() { - var options = General.CreateProfilerOptions(); + var options = OptionWrapper.CreateProfilerOptions(); LoggingService.Info("Profiler settings:"); LoggingService.Info("Shared memory size: " + options.SharedMemorySize + " (" + (options.SharedMemorySize / 1024 / 1024) + " MB)"); LoggingService.Info("Combine recursive calls: " + options.CombineRecursiveFunction); diff --git a/src/AddIns/Misc/Profiler/Profiler.sln b/src/AddIns/Misc/Profiler/Profiler.sln index b74ab6c5aa..287a5359ac 100644 --- a/src/AddIns/Misc/Profiler/Profiler.sln +++ b/src/AddIns/Misc/Profiler/Profiler.sln @@ -1,7 +1,7 @@  Microsoft Visual Studio Solution File, Format Version 11.00 # Visual Studio 10 -# SharpDevelop 4.0.0.4504 +# SharpDevelop 4.0.0.4879 Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution Items", "{5147BA25-8362-481D-8CF9-450096595B7A}" ProjectSection(SolutionItems) = preProject TODO.txt = TODO.txt @@ -13,6 +13,12 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Frontend", "Frontend", "{E0 ProjectSection(SolutionItems) = postProject EndProjectSection EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Controls", "Frontend\Controls\Controls.csproj", "{BDA49550-5ED1-4C6B-B648-657B2CACD8E0}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "AddIn", "Frontend\AddIn\AddIn.csproj", "{D294A12D-4B38-4F25-9AA6-3D4A6CE26E7B}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "BenchmarkRunner", "Frontend\BenchmarkRunner\BenchmarkRunner.csproj", "{DBEF953E-F7BC-4D54-8A27-B758EC875C49}" +EndProject Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Gui", "Frontend\Gui\Gui.csproj", "{FF09FBA1-86DA-4D8D-B549-A4FC70FC5AE9}" ProjectSection(ProjectDependencies) = postProject {D294A12D-4B38-4F25-9AA6-3D4A6CE26E7B} = {D294A12D-4B38-4F25-9AA6-3D4A6CE26E7B} @@ -21,25 +27,19 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Gui", "Frontend\Gui\Gui.csp {778BA9AE-EE77-444F-A0C9-D795BB977C1A} = {778BA9AE-EE77-444F-A0C9-D795BB977C1A} EndProjectSection EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "BenchmarkRunner", "Frontend\BenchmarkRunner\BenchmarkRunner.csproj", "{DBEF953E-F7BC-4D54-8A27-B758EC875C49}" -EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "AddIn", "Frontend\AddIn\AddIn.csproj", "{D294A12D-4B38-4F25-9AA6-3D4A6CE26E7B}" -EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Controls", "Frontend\Controls\Controls.csproj", "{BDA49550-5ED1-4C6B-B648-657B2CACD8E0}" -EndProject Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Tests", "Tests", "{791AE00B-AD96-410A-AAA8-957DDD83C57A}" ProjectSection(SolutionItems) = postProject EndProjectSection EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Benchmark", "Tests\Benchmark\Benchmark.csproj", "{F09B6132-5DF9-4E63-BA23-EE82D75CD5B9}" +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "UnicodeTest", "Tests\UnicodeTest\UnicodeTest.csproj", "{D336926C-6180-4F62-B88D-E366B240127B}" EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "HelloWorld", "Tests\HelloWorld\HelloWorld.csproj", "{778BA9AE-EE77-444F-A0C9-D795BB977C1A}" +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Profiler.Tests", "Tests\Profiler.Tests\Profiler.Tests.csproj", "{068F9531-5D29-49E0-980E-59982A3A0469}" EndProject Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "PauseTest", "Tests\PauseTest\PauseTest.csproj", "{650AEAA0-0678-4A75-A1CC-F46DC4E44D2A}" EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Profiler.Tests", "Tests\Profiler.Tests\Profiler.Tests.csproj", "{068F9531-5D29-49E0-980E-59982A3A0469}" +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "HelloWorld", "Tests\HelloWorld\HelloWorld.csproj", "{778BA9AE-EE77-444F-A0C9-D795BB977C1A}" EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "UnicodeTest", "Tests\UnicodeTest\UnicodeTest.csproj", "{D336926C-6180-4F62-B88D-E366B240127B}" +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Benchmark", "Tests\Benchmark\Benchmark.csproj", "{F09B6132-5DF9-4E63-BA23-EE82D75CD5B9}" EndProject Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "Hook", "Hook\Hook.vcproj", "{68D5EE3B-0C35-4DF1-BD29-6606851A02C1}" EndProject @@ -211,14 +211,14 @@ Global HideSolutionNode = FALSE EndGlobalSection GlobalSection(NestedProjects) = preSolution - {BDA49550-5ED1-4C6B-B648-657B2CACD8E0} = {E06867E9-6942-4DB6-89F5-DE0BF56C44DE} - {D294A12D-4B38-4F25-9AA6-3D4A6CE26E7B} = {E06867E9-6942-4DB6-89F5-DE0BF56C44DE} - {DBEF953E-F7BC-4D54-8A27-B758EC875C49} = {E06867E9-6942-4DB6-89F5-DE0BF56C44DE} {FF09FBA1-86DA-4D8D-B549-A4FC70FC5AE9} = {E06867E9-6942-4DB6-89F5-DE0BF56C44DE} - {D336926C-6180-4F62-B88D-E366B240127B} = {791AE00B-AD96-410A-AAA8-957DDD83C57A} - {068F9531-5D29-49E0-980E-59982A3A0469} = {791AE00B-AD96-410A-AAA8-957DDD83C57A} - {650AEAA0-0678-4A75-A1CC-F46DC4E44D2A} = {791AE00B-AD96-410A-AAA8-957DDD83C57A} - {778BA9AE-EE77-444F-A0C9-D795BB977C1A} = {791AE00B-AD96-410A-AAA8-957DDD83C57A} + {DBEF953E-F7BC-4D54-8A27-B758EC875C49} = {E06867E9-6942-4DB6-89F5-DE0BF56C44DE} + {D294A12D-4B38-4F25-9AA6-3D4A6CE26E7B} = {E06867E9-6942-4DB6-89F5-DE0BF56C44DE} + {BDA49550-5ED1-4C6B-B648-657B2CACD8E0} = {E06867E9-6942-4DB6-89F5-DE0BF56C44DE} {F09B6132-5DF9-4E63-BA23-EE82D75CD5B9} = {791AE00B-AD96-410A-AAA8-957DDD83C57A} + {778BA9AE-EE77-444F-A0C9-D795BB977C1A} = {791AE00B-AD96-410A-AAA8-957DDD83C57A} + {650AEAA0-0678-4A75-A1CC-F46DC4E44D2A} = {791AE00B-AD96-410A-AAA8-957DDD83C57A} + {068F9531-5D29-49E0-980E-59982A3A0469} = {791AE00B-AD96-410A-AAA8-957DDD83C57A} + {D336926C-6180-4F62-B88D-E366B240127B} = {791AE00B-AD96-410A-AAA8-957DDD83C57A} EndGlobalSection EndGlobal diff --git a/src/Main/ICSharpCode.Core.Presentation/OptionBinding.cs b/src/Main/ICSharpCode.Core.Presentation/OptionBinding.cs index b53c6b22ac..e4dbedc132 100644 --- a/src/Main/ICSharpCode.Core.Presentation/OptionBinding.cs +++ b/src/Main/ICSharpCode.Core.Presentation/OptionBinding.cs @@ -6,8 +6,10 @@ // using System; +using System.Linq; using System.ComponentModel; using System.Reflection; +using System.Text.RegularExpressions; using System.Windows; using System.Windows.Data; using System.Windows.Markup; @@ -35,6 +37,8 @@ namespace ICSharpCode.Core.Presentation { public string PropertyName { get; set; } + static readonly Regex regex = new Regex("^.+\\:.+\\..+$", RegexOptions.Compiled); + DependencyObject target; DependencyProperty dp; @@ -42,6 +46,9 @@ namespace ICSharpCode.Core.Presentation public OptionBinding(string propertyName) { + if (!regex.IsMatch(propertyName)) + throw new ArgumentException("parameter must have the following format: namespace:ClassName.FieldOrProperty", "propertyName"); + this.PropertyName = propertyName; } @@ -51,7 +58,7 @@ namespace ICSharpCode.Core.Presentation if (service == null) return null; - + target = service.TargetObject as DependencyObject; dp = service.TargetProperty as DependencyProperty; @@ -71,15 +78,23 @@ namespace ICSharpCode.Core.Presentation container.AddBinding(this); + object result = null; + if (this.propertyInfo is PropertyInfo) - return (propertyInfo as PropertyInfo).GetValue(null, null); + result = (propertyInfo as PropertyInfo).GetValue(null, null); else { this.propertyInfo = t.GetField(name[1]); if (this.propertyInfo is FieldInfo) - return (propertyInfo as FieldInfo).GetValue(null); + result = (propertyInfo as FieldInfo).GetValue(null); + } + + Type returnType = dp.PropertyType; + + if (dp.PropertyType.IsGenericType && dp.PropertyType.GetGenericTypeDefinition() == typeof(Nullable<>)) { + returnType = dp.PropertyType.GetGenericArguments().First(); } - return null; + return Convert.ChangeType(result, returnType); } IOptionBindingContainer TryFindContainer(FrameworkElement start) @@ -95,13 +110,23 @@ namespace ICSharpCode.Core.Presentation public bool Save() { + object value = target.GetValue(dp); + + Type returnType = null; + if (propertyInfo is PropertyInfo) + returnType = (propertyInfo as PropertyInfo).PropertyType; + if (propertyInfo is FieldInfo) + returnType = (propertyInfo as FieldInfo).FieldType; + + value = Convert.ChangeType(value, returnType); + if (propertyInfo is PropertyInfo) { - (propertyInfo as PropertyInfo).SetValue(null, target.GetValue(dp), null); + (propertyInfo as PropertyInfo).SetValue(null, value, null); return true; } if (propertyInfo is FieldInfo) { - (propertyInfo as FieldInfo).SetValue(null, target.GetValue(dp)); + (propertyInfo as FieldInfo).SetValue(null, value); return true; }