Updates referencesource to .NET 4.7
[mono.git] / mcs / class / referencesource / System.Data.Entity / System / Data / EntityModel / SchemaObjectModel / OnOperation.cs
1 //---------------------------------------------------------------------
2 // <copyright file="OnOperation.cs" company="Microsoft">
3 //      Copyright (c) Microsoft Corporation.  All rights reserved.
4 // </copyright>
5 //
6 // @owner       Microsoft
7 // @backupOwner Microsoft
8 //---------------------------------------------------------------------
9
10 namespace System.Data.EntityModel.SchemaObjectModel
11 {
12     using System.Data.Metadata.Edm;
13     using System.Data.Objects.DataClasses;
14     using System.Diagnostics;
15     using System.Xml;
16
17     /// <summary>
18     /// Represents an OnDelete, OnCopy, OnSecure, OnLock or OnSerialize element
19     /// </summary>
20     internal sealed class OnOperation : SchemaElement
21     {
22         private Operation _Operation;
23         private Action _Action;
24         /// <summary>
25         /// 
26         /// </summary>
27         /// <param name="parentElement"></param>
28         /// <param name="operation"></param>
29         public OnOperation(RelationshipEnd parentElement, Operation operation)
30         : base(parentElement)
31         {
32             Operation = operation;
33         }
34
35         /// <summary>
36         /// The operation
37         /// </summary>
38         public Operation Operation
39         {
40             get
41             {
42                 return _Operation;
43             }
44             private set
45             {
46                 _Operation = value;
47             }
48         }
49
50         /// <summary>
51         /// The action
52         /// </summary>
53         public Action Action
54         {
55             get
56             {
57                 return _Action;
58             }
59             private set
60             {
61                 _Action = value;
62             }
63         }
64
65         protected override bool ProhibitAttribute(string namespaceUri, string localName)
66         {
67             if (base.ProhibitAttribute(namespaceUri, localName))
68             {
69                 return true;
70             }
71
72             if (namespaceUri == null && localName == XmlConstants.Name)
73             {
74                 return false;
75             }
76             return false;
77
78         }
79
80         protected override bool HandleAttribute(XmlReader reader)
81         {
82             if (base.HandleAttribute(reader))
83             {
84                 return true;
85             }
86             else if (CanHandleAttribute(reader, XmlConstants.Action))
87             {
88                 HandleActionAttribute(reader);
89                 return true;
90             }
91
92             return false;
93         }
94
95         /// <summary>
96         /// Handle the Action attribute
97         /// </summary>
98         /// <param name="reader">reader positioned at Action attribute</param>
99         private void HandleActionAttribute(XmlReader reader)
100         {
101             Debug.Assert(reader != null);
102
103             RelationshipKind relationshipKind = ParentElement.ParentElement.RelationshipKind;
104
105             switch ( reader.Value.Trim() )
106             {
107                 case "None":
108                     Action = Action.None;
109                     break;
110                 case "Cascade":
111                     Action = Action.Cascade;
112                     break;
113                 default:
114                     AddError( ErrorCode.InvalidAction, EdmSchemaErrorSeverity.Error, reader, System.Data.Entity.Strings.InvalidAction(reader.Value, ParentElement.FQName ) );
115                     break;
116             }
117         }
118
119         /// <summary>
120         /// the parent element.
121             /// </summary>
122         private new RelationshipEnd ParentElement
123         {
124             get
125             {
126                 return (RelationshipEnd)base.ParentElement;
127             }
128         }
129     }
130 }