public void SettingPropertiesBeforeAddingToPlotter() { var types = GetAllCharts(); var properties = from type in types let typeProperties = type.GetProperties(BindingFlags.Public | BindingFlags.Instance) let ownProperties = from prop in typeProperties where prop.CanWrite && prop.CanRead where testedAssemblies.Contains(prop.DeclaringType.Assembly) select prop select new { Type = type, Properties = ownProperties.ToArray() }; var propertiesList = properties.ToList(); var charts = (from item in propertiesList let instance = Activator.CreateInstance(item.Type) select new { Instance = instance, Properties = item.Properties }).ToList(); PropertySetSystem system = new PropertySetSystem(); // setting custom values foreach (var chart in charts) { var instance = chart.Instance; foreach (var property in chart.Properties) { system.TrySetValue(instance, property); } } ChartPlotter plotter = new ChartPlotter(); plotter.Children.Clear(); foreach (var chart in charts) { plotter.Children.Add(chart.Instance as IPlotterElement); } foreach (var chart in charts) { var instance = chart.Instance; foreach (var property in chart.Properties) { system.TrySetValue(instance, property); } } }
public void SettingSameValueAsWasGot() { var types = GetAllExportedClasses(); var properties = from type in types let typeProperties = type.GetProperties(BindingFlags.Public | BindingFlags.Instance) let ownProperties = from prop in typeProperties where prop.CanWrite && prop.CanRead where testedAssemblies.Contains(prop.DeclaringType.Assembly) select prop select new { Type = type, Properties = ownProperties.ToArray() }; var propertiesList = properties.ToList(); var charts = (from item in propertiesList where !item.Type.IsDefined(typeof(SkipPropertyCheckAttribute), false) let instance = Activator.CreateInstance(item.Type) select new { Instance = instance, Properties = item.Properties }).ToList(); // setting the same value to property as was stored in it foreach (var chart in charts) { var instance = chart.Instance; foreach (var property in chart.Properties) { try { var value = property.GetValue(instance, null); property.SetValue(instance, value, null); } catch (ArgumentNullException) { } catch (TargetInvocationException) { } catch (NotImplementedException) { } } } PropertySetSystem system = new PropertySetSystem(); // setting custom values foreach (var chart in charts) { var instance = chart.Instance; foreach (var property in chart.Properties) { system.TrySetValue(instance, property); } } }
public void TestSettingPropertiesBeforeAddingToPlotter() { var types = GetAllCharts(); var properties = from type in types let typeProperties = type.GetProperties(BindingFlags.Public | BindingFlags.Instance) let ownProperties = from prop in typeProperties where prop.CanWrite && prop.CanRead where testedAssemblies.Contains(prop.DeclaringType.Assembly) select prop select new { Type = type, Properties = ownProperties.ToArray() }; var propertiesList = properties.ToList(); var charts = (from item in propertiesList let instance = Activator.CreateInstance(item.Type) select new { Instance = instance, Properties = item.Properties }).ToList(); PropertySetSystem system = new PropertySetSystem(); // setting custom values foreach (var chart in charts) { var instance = chart.Instance; foreach (var property in chart.Properties) { system.TrySetValue(instance, property); } } ChartPlotter plotter = new ChartPlotter(); plotter.Children.Clear(); foreach (var chart in charts) { plotter.Children.Add(chart.Instance as IPlotterElement); } foreach (var chart in charts) { var instance = chart.Instance; foreach (var property in chart.Properties) { system.TrySetValue(instance, property); } } }
public void TestSettingSameValueAsWasGot() { var types = GetAllExportedClasses(); var properties = from type in types let typeProperties = type.GetProperties(BindingFlags.Public | BindingFlags.Instance) let ownProperties = from prop in typeProperties where prop.CanWrite && prop.CanRead where testedAssemblies.Contains(prop.DeclaringType.Assembly) select prop select new { Type = type, Properties = ownProperties.ToArray() }; var propertiesList = properties.ToList(); var charts = (from item in propertiesList where !item.Type.IsDefined(typeof(SkipPropertyCheckAttribute), false) let instance = Activator.CreateInstance(item.Type) select new { Instance = instance, Properties = item.Properties }).ToList(); // setting the same value to property as was stored in it foreach (var chart in charts) { var instance = chart.Instance; foreach (var property in chart.Properties) { try { property.SetValue(instance, property.GetValue(instance, null), null); } catch (ArgumentNullException) { } catch (TargetInvocationException) { } } } PropertySetSystem system = new PropertySetSystem(); // setting custom values foreach (var chart in charts) { var instance = chart.Instance; foreach (var property in chart.Properties) { system.TrySetValue(instance, property); } } }