82794eccdcfd166294c960ed9849b8f233e02151
[mono.git] / mcs / class / referencesource / System.Data.Entity / System / Data / Common / CommandTrees / DbSetClause.cs
1 //---------------------------------------------------------------------
2 // <copyright file="DbSetClause.cs" company="Microsoft">
3 //      Copyright (c) Microsoft Corporation.  All rights reserved.
4 // </copyright>
5 //
6 // @owner  Microsoft
7 // @backupOwner Microsoft
8 //---------------------------------------------------------------------
9
10 using System;
11 using System.Collections.Generic;
12
13 using System.Data.Metadata.Edm;
14 using System.Data.Common.CommandTrees.Internal;
15 using System.Data.Common.Utils;
16 using System.Diagnostics;
17
18 namespace System.Data.Common.CommandTrees
19 {
20     /// <summary>
21     /// Specifies a clause in a modification operation setting the value of a property.
22     /// </summary>
23     [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Naming", "CA1709:IdentifiersShouldBeCasedCorrectly", MessageId = "Db")]
24     public sealed class DbSetClause : DbModificationClause
25     {
26         private DbExpression _prop;
27         private DbExpression _val;
28
29         internal DbSetClause(DbExpression targetProperty, DbExpression sourceValue)
30             : base()
31         {
32             EntityUtil.CheckArgumentNull(targetProperty, "targetProperty");
33             EntityUtil.CheckArgumentNull(sourceValue, "sourceValue");
34             _prop = targetProperty;
35             _val = sourceValue;
36         }
37
38         /// <summary>
39         /// Gets an <see cref="DbExpression"/> that specifies the property that should be updated.
40         /// </summary>
41         /// <remarks>
42         /// Constrained to be a <see cref="DbPropertyExpression"/>.
43         /// </remarks>
44         public DbExpression Property
45         {
46             get
47             {
48                 return _prop;
49             }
50         }
51         
52         /// <summary>
53         /// Gets an <see cref="DbExpression"/> that specifies the new value with which to update the property.
54         /// </summary>
55         /// <remarks>
56         /// Constrained to be a <see cref="DbConstantExpression"/> or <see cref="DbNullExpression"/>
57         /// </remarks>
58         public DbExpression Value
59         { 
60             get
61             {
62                 return _val;
63             }
64         }
65                 
66         internal override void DumpStructure(ExpressionDumper dumper)
67         {
68             dumper.Begin("DbSetClause");
69             if (null != this.Property)
70             {
71                 dumper.Dump(this.Property, "Property");
72             }
73             if (null != this.Value)
74             {
75                 dumper.Dump(this.Value, "Value");
76             }
77             dumper.End("DbSetClause");
78         }
79
80         internal override TreeNode Print(DbExpressionVisitor<TreeNode> visitor)
81         {
82             TreeNode node = new TreeNode("DbSetClause");
83             if (null != this.Property)
84             {
85                 node.Children.Add(new TreeNode("Property", this.Property.Accept(visitor)));
86             }
87             if (null != this.Value)
88             {
89                 node.Children.Add(new TreeNode("Value", this.Value.Accept(visitor)));
90             }
91             return node;
92         }
93     }
94 }