public void MatchesReadAccess_False() { var binding = new PropertyInfoBinding(Property, AssociatedExpression); Assert.That(binding.MatchesReadAccess(Field), Is.False); }
public void MatchesReadAccess_False_WithGetter_IfWriteOnlyProperty() { var binding = new PropertyInfoBinding(WriteOnlyProperty, AssociatedExpression); Assert.That(binding.MatchesReadAccess(Property.GetGetMethod()), Is.False); }
public void MatchesReadAccess_True() { var binding = new PropertyInfoBinding(Property, AssociatedExpression); Assert.That(binding.MatchesReadAccess(Property), Is.True); }
public void MatchesReadAccess_False_WithOtherGetter() { var binding = new PropertyInfoBinding(Property, AssociatedExpression); Assert.That(binding.MatchesReadAccess(OtherProperty.GetGetMethod()), Is.False); }
private void AddCdWindow_Loaded(object sender, RoutedEventArgs e) { btnSave.Click += BtnSave_Click; btnCancel.Click += BtnCancel_Click; if (!string.IsNullOrWhiteSpace(DisplayText)) { ModelGrid.RowDefinitions.Add(new RowDefinition()); var label = new TextBlock() { VerticalAlignment = VerticalAlignment.Center, Margin = new Thickness(6), FontSize = 16, Text = DisplayText }; ModelGrid.Children.Add(label); Grid.SetRow(label, ModelGrid.RowDefinitions.Count - 1); Grid.SetColumn(label, 0); Grid.SetColumnSpan(label, 2); } var propertyInfos = ObjectType .GetProperties(BindingFlags.Public | BindingFlags.Instance) .Where(p => { var browsableAttribute = p.GetCustomAttribute <System.ComponentModel.BrowsableAttribute>(); if (browsableAttribute == null) { return(true); } else { return(browsableAttribute.Browsable); } }) .ToList(); _objectProperties = new PropertyInfoBinding[propertyInfos.Count]; for (int i = 0; i < propertyInfos.Count; i++) { ModelGrid.RowDefinitions.Add(new RowDefinition()); var label = new TextBlock() { VerticalAlignment = VerticalAlignment.Center, Margin = new Thickness(6), Text = GetName(propertyInfos[i]) }; ModelGrid.Children.Add(label); Grid.SetRow(label, ModelGrid.RowDefinitions.Count - 1); Grid.SetColumn(label, 0); TextBox textBox = null; // https://stackoverflow.com/a/863944/3492994 if (propertyInfos[i].PropertyType.IsPrimitive || propertyInfos[i].PropertyType.Equals(typeof(string))) { textBox = new TextBox() { VerticalAlignment = VerticalAlignment.Center, Margin = new Thickness(6) }; ModelGrid.Children.Add(textBox); Grid.SetRow(textBox, ModelGrid.RowDefinitions.Count - 1); Grid.SetColumn(textBox, 1); if (DefaultValuesObject != null) { textBox.Text = propertyInfos[i].GetValue(DefaultValuesObject) + ""; } } // TODO: Nullable types // TODO: Enums // TODO: Objects // TODO: Structs // TODO: Arrays _objectProperties[i] = new PropertyInfoBinding() { PropertyInfo = propertyInfos[i], TextBox = textBox }; } }