Example #1
0
        private Set GetSetter(ElementBuilder eb, Property propertyClone, string varName)
        {
            Set setter      = eb.BuildSetter();
            If  ifStatement = eb.BuildIf(eb.OpNotEquals("value", varName));

            ifStatement.AddNode(eb.BuildAssignment(varName, "value"));
            ExpressionCollection args = new ExpressionCollection();

            args.Add(new SnippetExpression(CodeRush.StrUtil.AddQuotes(propertyClone.Name)));
            ExpressionCollection arguments = new ExpressionCollection();

            arguments.Add(eb.BuildThisReferenceExpression());
            arguments.Add(eb.BuildObjectCreationExpression("PropertyChangedEventArgs", args));
            if (CodeRush.Language.IsCSharp)
            {
                ifStatement.AddNode(eb.BuildMethodCall("PropertyChanged", arguments, null /* qualifier */));
            }
            else if (CodeRush.Language.IsBasic)
            {
                RaiseEvent raiseEvent = new RaiseEvent(eb.BuildMethodCallExpression("PropertyChanged", arguments));
                ifStatement.AddNode(raiseEvent);
            }
            setter.AddNode(ifStatement);
            return(setter);
        }
Example #2
0
        private Set GetOnPropertyChangedLambdaSetter(ElementBuilder eb, Property propertyClone, string varName)
        {
            Set setter      = eb.BuildSetter();
            If  ifStatement = eb.BuildIf(eb.OpNotEquals("value", varName));

            ifStatement.AddNode(eb.BuildAssignment(varName, "value"));
            ExpressionCollection args   = new ExpressionCollection();
            LambdaExpression     lambda = new LambdaExpression();
            var propAccess = new ElementReferenceExpression(propertyClone.Name);

            lambda.AddNode(propAccess);
            args.Add(lambda);
            var propChangedCall = eb.BuildMethodCall("RaisePropertyChanged", args, null);

            ifStatement.AddNode(propChangedCall);
            setter.AddNode(ifStatement);
            return(setter);
        }
Example #3
0
 private static void AddFieldDisposeBlock(ElementBuilder elementBuilder, If parentIfDisposingBlock, BaseVariable field)
 {
     If ifFieldIsAssignedBlock = new If();
       ifFieldIsAssignedBlock.Expression = CodeRush.Language.GetNullCheck(field.Name).Invert();
       elementBuilder.AddMethodCall(ifFieldIsAssignedBlock, field.Name + CodeRush.Language.MemberAccessOperator + STR_Dispose);
       if (!field.IsReadOnly)
       elementBuilder.AddAssignment(ifFieldIsAssignedBlock, field.Name, CodeRush.Language.GetNullReferenceExpression());
       parentIfDisposingBlock.AddNode(ifFieldIsAssignedBlock);
 }