public PropertyBinding(InitializerObject source, string propertyname) { //Type sourcetype = source.GetType(); if (!source.GetType().IsClass) { throw new NotSupportedException(); } if (source is INotifyPropertyChanged) { ((INotifyPropertyChanged)source).PropertyChanged += HandleChangedEvent; } _source = source; _propertyname = propertyname; }
private void ResolveAttributes(InitializerObject instance, XAttribute attribute) { string propertyname = attribute.Name.LocalName; if (attribute.IsNamespaceDeclaration && !_assemblyKeys.ContainsKey(propertyname)) { if (NamespaceDeclaration.Resolve(propertyname, attribute.Value, out NamespaceDeclaration declaration)) { _assemblyKeys.Add(propertyname, declaration); } } else { int count = NestedArgument.ResolveNestedParenthesses(attribute.Value, '{', '}', out IEnumerable <NestedArgument> nestedargument); if (!instance.GetProperty(propertyname, out InitializerProperty property)) { _debug?.Pass(this, "initializer/instance/noproperty", (s) => string.Format(s, propertyname, instance, instance.GetType())); } else if (count > 1) { _debug?.Pass(this, "initializer/format/chained", (s) => string.Format(s, attribute.Value)); } else if (count == 1) { NestedArgument argument = nestedargument.First(); if (ResolveExtension(argument, property.Type, out object obj)) { if (obj is PropertyBinding binding) { property.Register(binding); } else if (obj != null) { property.SetValue(obj); } } else { _debug?.Pass(this, "initializer/extension/failed", (s) => string.Format(argument.Scope)); } } else if (count == 0 && SaveChangeType(property.Type, attribute.Value, out object obj)) { property.SetValue(obj); } } }