/// <summary> /// Constructeur /// </summary> public DecisionCreateViewModel(IDecisionPersister decisionsStorage, IDomaineReference domaineReference) : base(decisionsStorage, domaineReference) { this.DecisionBuilder = new InstanceProperty <DecisionBuilder> { Value = new DecisionBuilder() }; this.Register(nameof(this.DecisionBuilder), this.DecisionBuilder); this.Register(nameof(this.IsEnabled), this.IsEnabled); this.DomaineAdd += (sender, domaine) => this.DecisionBuilder.Value.Domaines.Add(domaine); this.DomaineRemoved += (sender, domaine) => this.DecisionBuilder.Value.Domaines.Remove(domaine); }
private IEnumerable<PSAdaptedProperty> GetProperties(Instance instance) { yield return new PSAdaptedProperty("PSPath", new InstanceProperty { Type = typeof(string) }); var properties = instance.GetType().GetProperties(BindingFlags.DeclaredOnly | BindingFlags.Instance | BindingFlags.Public); foreach (var property in properties) { var tag = new InstanceProperty { Type = property.PropertyType, Property = property }; yield return new PSAdaptedProperty(property.Name, tag); } foreach (var keyValue in instance.AdditionalProperties) { var tag = new InstanceProperty { Type = keyValue.Value?.GetType() ?? typeof(object) }; yield return new PSAdaptedProperty(keyValue.Key, tag); } }
public void InitProperties(LogicalInstance logicalInstance) { Type type = GetType(logicalInstance.Type); var fields = type.GetFields(BindingFlags.Public | BindingFlags.Static); foreach (var field in fields.Where(item => item.FieldType == typeof(DependencyProperty))) { string propertyName = field.Name.Substring(0, field.Name.LastIndexOf("Property")); int count = logicalInstance.InstanceProperties.Count(property => property.Name == propertyName); if (count == 0) { InstanceProperty instanceProperty = new InstanceProperty { Name = propertyName, LogicalInstance = logicalInstance }; logicalInstance.InstanceProperties.Add(instanceProperty); } } }
private static void SetPropertyBindings(LogicalInstance logicalInstance, ObjectType objectType) { Type type = objectType.GetType(); var fields = type.GetFields(BindingFlags.Public | BindingFlags.Static); foreach (var field in fields) { if (field.FieldType == typeof(DependencyProperty)) { string propertyName = field.Name.Substring(0, field.Name.LastIndexOf("Property")); InstanceProperty instanceProperty = logicalInstance.InstanceProperties.Single(item => item.Name == propertyName); Binding binding = new Binding { Path = new PropertyPath("Value"), Mode = BindingMode.TwoWay, Source = instanceProperty }; DependencyProperty dependencyProperty = field.GetValue(objectType) as DependencyProperty; objectType.SetBinding(dependencyProperty, binding); } } }
void SetValue(ToolArgNode node, InstanceProperty pe) { if (node.Value != null) { if (pe.Property.PropertyType.Implements <IList>()) { if (pe.Value == null) { pe.Value = Activator.CreateInstance(pe.Property.PropertyType); } ((IList)pe.Value).Add(node.Value); } else { pe.Value = node.Value; } } else { pe.Value = true; } }
set => SetValue(InstanceProperty, value);