public string GetSourcePropertyParameters(Context context, IAccessorCodeGenerator codeGenerator)
        {
            var isReadOnlyPropertyBindResult = this.readOnlyDependencyPropertyToNotificationEventResolver.Resolve(
                context.BindingSource.SourceType,
                codeGenerator.Name);

            if (isReadOnlyPropertyBindResult)
            {
                var delegateType = this.typeResolver.GetType(isReadOnlyPropertyBindResult.Value.NamespaceQualifiedDelegate);
                context.ExternAliases.TryAdd(delegateType);
                return(@$ "
                    (s, u) =>
                        {{
                            var h = new {delegateType.ToAliasQualifiedType()}((s, e) => u());
                            s.{isReadOnlyPropertyBindResult.Value.EventName} += h;
                            return h;
                        }},
Esempio n. 2
0
        public BindingMode GetBindingMode(BindingMode bindingMode, TargetValueCodeGenerator targetValueCodeGenerator, IAccessorCodeGenerator accessorCodeGenerator)
        {
            if (bindingMode == BindingMode.Default)
            {
                if (this.IsBindingOneWayPerDefault(targetValueCodeGenerator))
                {
                    bindingMode = BindingMode.OneWay;
                }
                else
                {
                    bindingMode = this.xamlPlatform == XamlPlatform.WPF ? BindingMode.TwoWay : BindingMode.OneWay;
                }
            }

            var sourceQualifiedProperty = accessorCodeGenerator.Accessor;

            switch (bindingMode)
            {
            case BindingMode.OneWay when !sourceQualifiedProperty.HasGetter:
                throw new NotSupportedException($"The source property {accessorCodeGenerator.Accessor.Type.ToNamespaceQualifiedType()}{sourceQualifiedProperty.Name} must have a getter");

            case BindingMode.OneTime when !sourceQualifiedProperty.HasGetter:
                throw new NotSupportedException($"The source property {sourceQualifiedProperty.Name} must have a getter");

            case BindingMode.OneWayToSource when !sourceQualifiedProperty.HasSetter:
                throw new NotSupportedException($"The source property {sourceQualifiedProperty.Name} must have a setter");

            case BindingMode.TwoWay when !sourceQualifiedProperty.HasGetter && !sourceQualifiedProperty.HasSetter:
                throw new NotSupportedException($"The source property {sourceQualifiedProperty.Name} must have a getter and/or setter");

            case BindingMode.TwoWay when sourceQualifiedProperty.HasGetter && !sourceQualifiedProperty.HasSetter:
                return(BindingMode.OneWay);

            case BindingMode.TwoWay when !sourceQualifiedProperty.HasGetter && sourceQualifiedProperty.HasSetter:
                return(BindingMode.OneWayToSource);
            }

            return(bindingMode);
        }