/// <summary> /// This takes the name of another field in the model and that fields expected value. /// If the dependentProperty equals the targetValue then return valid. /// </summary> /// <param name="dependentProperty">The name of the field to check</param> /// <param name="targetValue">The expected value of the passed in field</param> public RequiredIfAttribute(object dependentProperty, object targetValue) { _innerAttribute = new RequiredAttribute(); this.DependentProperty = dependentProperty; this.TargetValue = targetValue; //If we have just a string then add it to an array. Otherwise if our object is already //an array then cast the object as an array if (DependentProperty.GetType().IsArray) { DependentPropertyArray = ((IEnumerable)DependentProperty).Cast <object>().Select(x => x.ToString()).ToArray(); } else if (DependentProperty.GetType().ToString() == "System.String") { String DependentPropertyString = (String)DependentProperty; DependentPropertyArray = new String[1] { DependentPropertyString }; } if (TargetValue.GetType().IsArray) { TargetValueArray = ((IEnumerable)TargetValue).Cast <object>().Select(x => x.ToString()).ToArray(); } else { TargetValueArray = new object[1] { TargetValue }; } }
public void AddDependentProperty(PropertyBinding.PropertyPath prop, Action handler) { var dependentProperty = new DependentProperty(prop, handler); dependentProperty.Prop.AddHandler(_value, dependentProperty.Handler); _dependents.Add(dependentProperty); }
public void AddDependentProperty(INPCBinding.PropertyPath prop, PropertyChangedEventHandler handler) { var dependentProperty = new DependentProperty(prop, handler); dependentProperty.Prop.AddHandler(_value, dependentProperty.Handler); _dependents.Add(dependentProperty); }
/// <summary> /// Adds a dependent property of a property; that is, a property whose changes will be monitored to refresh the <see cref="TransformedCollection"/>. /// </summary> public void AddDependentProperty(Func <T, INotifyPropertyChanged> selector, string propertyName) { var depProp = new DependentProperty(propertyName, selector, Item_PropertyChanged); this._depProps.Add(depProp); foreach (var item in this._source) { depProp.Register(item); } }
private object GetDependentPropertyValue(object container) { var currentType = container.GetType(); var value = container; foreach (string propertyName in DependentProperty.Split('.')) { var property = currentType.GetProperty(propertyName); value = property.GetValue(value, null); currentType = property.PropertyType; } return(value); }
private static IEnumerable <MemberDeclarationSyntax> GetGeneratedMember(DependentProperty p) { var source = string.Format(@" public {1} {0} => _value.{0}; private static readonly PropertyChangedEventArgs {0}Property = new PropertyChangedEventArgs(" + NameOf(p) + @"); ", p.Name, p.Type.WithoutTrivia().GetText().ToString()); var generatedNodes = CSharpSyntaxTree.ParseText(source) .GetRoot().ChildNodes() .OfType <MemberDeclarationSyntax>() .ToArray(); return(generatedNodes); }
private object GetDependentPropertyValue(object container) { if (container == null) { throw new ArgumentNullException(nameof(container)); } var currentType = container.GetType(); var value = container; foreach (string propertyName in DependentProperty.Split('.')) { var property = currentType.GetProperty(propertyName); if (property != null) { value = property.GetValue(value, null); currentType = property.PropertyType; } } return(value); }
private static string NameOf(DependentProperty p) => NameOf(p.Name, p.Options.IsCsharp6);