예제 #1
0
 private static void GenerateAttachedHelperMethods(RequestParser rp, CodeWriter cw)
 {
     cw.AppendLine($"public static {rp.NullableTargetType()} Get{rp.PropName}(System.Windows.DependencyObject obj) =>");
     cw.AppendLine($"    ({rp.NullableTargetType()})obj.GetValue({rp.ParentType()}.{rp.DependencyPropName()});");
     cw.AppendLine($"public static void Set{rp.PropName}(System.Windows.DependencyObject obj, {rp.NullableTargetType()} value) =>");
     cw.AppendLine($"    obj.SetValue({rp.ParentType()}.{rp.DependencyPropName()}, value);");
 }
예제 #2
0
 private static void GeneratePropertyDeclaration(RequestParser rp, CodeWriter cw)
 {
     cw.AppendLine($"public {rp.NullableTargetType()} {rp.PropName}");
     using var block = cw.CurlyBlock();
     cw.AppendLine($"get => ({rp.NullableTargetType()})this.GetValue({rp.ParentType()}.{rp.DependencyPropName()});");
     cw.AppendLine($"set => this.SetValue({rp.ParentType()}.{rp.DependencyPropName()}, value);");
 }
예제 #3
0
 private static string TypeOfArgument(RequestParser rp) =>
 rp.Type != null && rp.Type.IsValueType ? rp.NullableTargetType() : rp.TargetType();
        public static string ComputerChangeFunction(RequestParser rp)
        {
            var methodName = $"On{rp.PropName}Changed";
            var candidates = rp.ParentSymbol.GetMembers(methodName);

            foreach (var candidate in candidates.OfType <IMethodSymbol>())
            {
                if (!candidate.ReturnsVoid)
                {
                    continue;
                }
                if (candidate.IsStatic)
                {
                    if (candidate.VerifyParameterTypes(
                            "System.Windows.DependencyObject", "System.Windows.DependencyPropertyChangedEventArgs"))
                    {
                        return($", {rp.ParentType()}.{methodName}");
                    }
                    if (candidate.VerifyParameterTypes("System.Windows.DependencyObject", rp.NullableTargetType()))
                    {
                        return($", (i,j)=>{rp.ParentType()}.{methodName}(i, ({rp.NullableTargetType()})(j.NewValue))");
                    }
                    if (candidate.VerifyParameterTypes(
                            "System.Windows.DependencyObject", rp.NullableTargetType(), rp.NullableTargetType()))
                    {
                        return($", (i,j)=>{rp.ParentType()}.{methodName}(i, ({rp.NullableTargetType()})(j.OldValue), ({rp.NullableTargetType()})(j.NewValue))");
                    }

                    if (candidate.VerifyParameterTypes(
                            rp.ParentType(), "System.Windows.DependencyPropertyChangedEventArgs"))
                    {
                        return($", (i,j)=>{rp.ParentType()}.{methodName}((({rp.ParentType()})i),j)");
                    }
                    if (candidate.VerifyParameterTypes(null, rp.NullableTargetType()))
                    {
                        return($", (i,j)=>{rp.ParentType()}.{methodName}((({candidate.Parameters[0].Type.FullyQualifiedName()})i), ({rp.NullableTargetType()})(j.NewValue))");
                    }
                    if (candidate.VerifyParameterTypes(
                            null, rp.NullableTargetType(), rp.NullableTargetType()))
                    {
                        return($", (i,j)=>{rp.ParentType()}.{methodName}((({candidate.Parameters[0].Type.FullyQualifiedName()})i), ({rp.NullableTargetType()})(j.OldValue), ({rp.NullableTargetType()})(j.NewValue))");
                    }
                    return("");
                }
                // not static
                if (candidate.Parameters.Length == 0)
                {
                    return($", (i,j)=>(({rp.ParentType()})i).{methodName}()");
                }
                if (candidate.VerifyParameterTypes("System.Windows.DependencyPropertyChangedEventArgs"))
                {
                    return($", (i,j)=>(({rp.ParentType()})i).{methodName}(j)");
                }
                if (candidate.VerifyParameterTypes(rp.NullableTargetType()))
                {
                    return($", (i,j)=>(({rp.ParentType()})i).{methodName}(({rp.NullableTargetType()})(j.NewValue))");
                }
                if (candidate.VerifyParameterTypes(rp.NullableTargetType(), rp.NullableTargetType()))
                {
                    return($", (i,j)=>(({rp.ParentType()})i).{methodName}(({rp.NullableTargetType()})(j.OldValue), ({rp.NullableTargetType()})(j.NewValue))");
                }
            }
            return("");
        }