/// <summary> /// Attempts to create a distribution's property. If the property doesn't /// qualify as a valid property to be shown in the automatic distribution /// description, the method fails and returns false. /// </summary> /// /// <param name="info">The property's reflection information.</param> /// <param name="owner">The distribution that should own this property.</param> /// <param name="property">The created distribution property.</param> /// /// <returns>True if the property could be created; false otherwise.</returns> /// public static bool TryParse(PropertyInfo info, DistributionViewModel owner, out PropertyViewModel property) { property = null; if (info.GetMethod.ReturnType != typeof(double)) return false; property = new PropertyViewModel(info, owner); return true; }
/// <summary> /// Attempts to create a distribution's property. If the property doesn't /// qualify as a valid property to be shown in the automatic distribution /// description, the method fails and returns false. /// </summary> /// /// <param name="info">The property's reflection information.</param> /// <param name="owner">The distribution that should own this property.</param> /// <param name="property">The created distribution property.</param> /// /// <returns>True if the property could be created; false otherwise.</returns> /// public static bool TryParse(PropertyInfo info, DistributionViewModel owner, out PropertyViewModel property) { property = null; if (info.GetMethod.ReturnType != typeof(double)) { return(false); } property = new PropertyViewModel(info, owner); return(true); }
private void OnDistributionChanged(DistributionViewModel value) { if (!value.IsInitialized) throw new Exception(); if (distribution != null) distribution.Updated -= distribution_DistributionUpdated; distribution = value; Probability = 0.5; updateInterval(); updateChart(); distribution.Updated += distribution_DistributionUpdated; }
/// <summary> /// Attempts to create a distribution's constructor. If the constructor /// parameter's aren't valid, this method fails and returns false. /// </summary> /// /// <param name="info">The constructor's reflection information.</param> /// <param name="distribution">The distribution that owns this constructor.</param> /// <param name="constructor">The created distribution constructor.</param> /// /// <returns>True if the constructor could be created; false otherwise.</returns> /// public static bool TryParse(ConstructorInfo info, DistributionViewModel distribution, out ConstructorViewModel constructor) { constructor = new ConstructorViewModel(info, distribution); foreach (var param in info.GetParameters()) { ParameterViewModel viewModel; if (!ParameterViewModel.TryParse(param, constructor, out viewModel)) { return(false); } constructor.Parameters.Add(viewModel); } return(true); }
private void OnDistributionChanged(DistributionViewModel value) { if (!value.IsInitialized) { throw new Exception(); } if (distribution != null) { distribution.Updated -= distribution_DistributionUpdated; } distribution = value; Probability = 0.5; updateInterval(); updateChart(); distribution.Updated += distribution_DistributionUpdated; }
/// <summary> /// Attempts to create a new DistributionViewModel from a given type. /// </summary> public static bool TryParse(MainViewModel owner, Type type, Dictionary <string, DocumentationViewModel> doc, out DistributionViewModel distribution) { distribution = new DistributionViewModel(owner); if (!typeof(IUnivariateDistribution).IsAssignableFrom(type) || !doc.ContainsKey(type.Name)) { return(false); } string name = DistributionManager.GetDistributionName(type); // Extract all properties with return value of double // var properties = new List <PropertyViewModel>(); foreach (PropertyInfo prop in type.GetProperties()) { PropertyViewModel property; if (PropertyViewModel.TryParse(prop, distribution, out property)) { properties.Add(property); } } // Extract buildable constructors. A constructor is // considered buildable if we can extract valid ranges // and default values from all of its parameters // var list = new List <ConstructorViewModel>(); foreach (var ctor in type.GetConstructors()) { ConstructorViewModel constructor; if (ConstructorViewModel.TryParse(ctor, distribution, out constructor)) { list.Add(constructor); } } if (list.Count == 0) { return(false); } // For the time being, just consider the buildable // constructor with the largest number of parameters. // var main = list.OrderByDescending(x => x.Parameters.Count).First(); // Extract some documentation var documentation = doc[type.Name]; documentation.Name = name; distribution.Constructor = main; distribution.Properties = new ObservableCollection <PropertyViewModel>(properties); distribution.Parameters = main.Parameters; distribution.Type = type; distribution.Name = name; distribution.Documentation = documentation; foreach (var parameter in distribution.Constructor.Parameters) { parameter.ValueChanged += distribution.distribution_OnParameterChanged; } distribution.Options = DistributionManager.GetFittingOptions(distribution.Type); return(true); }
private PropertyViewModel(PropertyInfo prop, DistributionViewModel distribution) { this.Property = prop; this.Owner = distribution; this.Name = DistributionManager.Normalize(prop.Name); }
private ConstructorViewModel(ConstructorInfo info, DistributionViewModel owner) { this.Owner = owner; this.Constructor = info; this.Parameters = new ObservableCollection <ParameterViewModel>(); }
/// <summary> /// Attempts to create a distribution's constructor. If the constructor /// parameter's aren't valid, this method fails and returns false. /// </summary> /// /// <param name="info">The constructor's reflection information.</param> /// <param name="distribution">The distribution that owns this constructor.</param> /// <param name="constructor">The created distribution constructor.</param> /// /// <returns>True if the constructor could be created; false otherwise.</returns> /// public static bool TryParse(ConstructorInfo info, DistributionViewModel distribution, out ConstructorViewModel constructor) { constructor = new ConstructorViewModel(info, distribution); foreach (var param in info.GetParameters()) { ParameterViewModel viewModel; if (!ParameterViewModel.TryParse(param, constructor, out viewModel)) return false; constructor.Parameters.Add(viewModel); } return true; }
private ConstructorViewModel(ConstructorInfo info, DistributionViewModel owner) { this.Owner = owner; this.Constructor = info; this.Parameters = new ObservableCollection<ParameterViewModel>(); }
/// <summary> /// Attempts to create a new DistributionViewModel from a given type. /// </summary> public static bool TryParse(MainViewModel owner, Type type, Dictionary<string, DocumentationViewModel> doc, out DistributionViewModel distribution) { distribution = new DistributionViewModel(owner); if (!typeof(IUnivariateDistribution).IsAssignableFrom(type) || !doc.ContainsKey(type.Name)) return false; string name = DistributionManager.GetDistributionName(type); // Extract all properties with return value of double // var properties = new List<PropertyViewModel>(); foreach (PropertyInfo prop in type.GetProperties()) { PropertyViewModel property; if (PropertyViewModel.TryParse(prop, distribution, out property)) properties.Add(property); } // Extract buildable constructors. A constructor is // considered buildable if we can extract valid ranges // and default values from all of its parameters // var list = new List<ConstructorViewModel>(); foreach (var ctor in type.GetConstructors()) { ConstructorViewModel constructor; if (ConstructorViewModel.TryParse(ctor, distribution, out constructor)) list.Add(constructor); } if (list.Count == 0) return false; // For the time being, just consider the buildable // constructor with the largest number of parameters. // var main = list.OrderByDescending(x => x.Parameters.Count).First(); // Extract some documentation var documentation = doc[type.Name]; documentation.Name = name; distribution.Constructor = main; distribution.Properties = new ObservableCollection<PropertyViewModel>(properties); distribution.Parameters = main.Parameters; distribution.Type = type; distribution.Name = name; distribution.Documentation = documentation; foreach (var parameter in distribution.Constructor.Parameters) parameter.ValueChanged += distribution.distribution_OnParameterChanged; distribution.Options = DistributionManager.GetFittingOptions(distribution.Type); return true; }