Skip to content

Commit 997269d

Browse files
Address annotation support comments
1 parent b83c4c8 commit 997269d

File tree

3 files changed

+36
-27
lines changed

3 files changed

+36
-27
lines changed

src/Microsoft.Restier.Publishers.OData/Extensions.cs

Lines changed: 21 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -28,9 +28,11 @@ internal static class Extensions
2828
private static PropertyInfo etagConcurrencyPropertiesProperty = typeof(ETag).GetProperty(
2929
PropertyNameOfConcurrencyProperties, BindingFlags.NonPublic | BindingFlags.Instance);
3030

31+
// TODO GithubIssue#485 considering move to API class DI instance
3132
private static ConcurrentDictionary<IEdmEntitySet, bool> concurrencyCheckFlags
3233
= new ConcurrentDictionary<IEdmEntitySet, bool>();
3334

35+
// TODO GithubIssue#485 considering move to API class DI instance
3436
private static ConcurrentDictionary<IEdmStructuredType, IDictionary<string, PropertyAttributes>>
3537
typePropertiesAttributes
3638
= new ConcurrentDictionary<IEdmStructuredType, IDictionary<string, PropertyAttributes>>();
@@ -80,7 +82,8 @@ public static IReadOnlyDictionary<string, object> CreatePropertyDictionary(
8082
PropertyAttributes attributes;
8183
if (propertiesAttributes != null && propertiesAttributes.TryGetValue(propertyName, out attributes))
8284
{
83-
if ((isCreation && attributes.IgnoreForCreation) || (!isCreation && attributes.IgnoreForUpdate))
85+
if ((isCreation && (attributes & PropertyAttributes.IgnoreForCreation) != PropertyAttributes.None)
86+
|| (!isCreation && (attributes & PropertyAttributes.IgnoreForUpdate) != PropertyAttributes.None))
8487
{
8588
// Will not get the properties for update or creation
8689
continue;
@@ -116,7 +119,7 @@ public static IDictionary<string, PropertyAttributes> RetrievePropertiesAttribut
116119
foreach (var property in edmType.DeclaredProperties)
117120
{
118121
var annotations = model.FindVocabularyAnnotations(property);
119-
PropertyAttributes attributes = null;
122+
var attributes = PropertyAttributes.None;
120123
foreach (var annotation in annotations)
121124
{
122125
var valueAnnotation = annotation as EdmAnnotation;
@@ -125,34 +128,22 @@ public static IDictionary<string, PropertyAttributes> RetrievePropertiesAttribut
125128
continue;
126129
}
127130

128-
if (valueAnnotation.Term.Namespace == CoreVocabularyModel.ImmutableTerm.Namespace
129-
&& valueAnnotation.Term.Name == CoreVocabularyModel.ImmutableTerm.Name)
131+
if (valueAnnotation.Term.IsSameTerm(CoreVocabularyModel.ImmutableTerm))
130132
{
131133
var value = valueAnnotation.Value as EdmBooleanConstant;
132134
if (value != null && value.Value)
133135
{
134-
if (attributes == null)
135-
{
136-
attributes = new PropertyAttributes();
137-
}
138-
139-
attributes.IgnoreForUpdate = true;
136+
attributes |= PropertyAttributes.IgnoreForUpdate;
140137
}
141138
}
142139

143-
if (valueAnnotation.Term.Namespace == CoreVocabularyModel.ComputedTerm.Namespace
144-
&& valueAnnotation.Term.Name == CoreVocabularyModel.ComputedTerm.Name)
140+
if (valueAnnotation.Term.IsSameTerm(CoreVocabularyModel.ComputedTerm))
145141
{
146142
var value = valueAnnotation.Value as EdmBooleanConstant;
147143
if (value != null && value.Value)
148144
{
149-
if (attributes == null)
150-
{
151-
attributes = new PropertyAttributes();
152-
}
153-
154-
attributes.IgnoreForUpdate = true;
155-
attributes.IgnoreForCreation = true;
145+
attributes |= PropertyAttributes.IgnoreForUpdate;
146+
attributes |= PropertyAttributes.IgnoreForCreation;
156147
}
157148
}
158149

@@ -161,7 +152,7 @@ public static IDictionary<string, PropertyAttributes> RetrievePropertiesAttribut
161152
}
162153

163154
// Add property attributes to the dictionary
164-
if (attributes != null)
155+
if (attributes != PropertyAttributes.None)
165156
{
166157
if (propertiesAttributes == null)
167158
{
@@ -241,5 +232,15 @@ public static IEdmTypeReference GetTypeReference(this Type type, IEdmModel model
241232

242233
return type.GetPrimitiveTypeReference();
243234
}
235+
236+
public static bool IsSameTerm(this IEdmTerm sourceTerm, IEdmTerm targetTerm)
237+
{
238+
if (sourceTerm.Namespace == targetTerm.Namespace && sourceTerm.Name == targetTerm.Name)
239+
{
240+
return true;
241+
}
242+
243+
return false;
244+
}
244245
}
245246
}
Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,36 @@
11
// Copyright (c) Microsoft Corporation. All rights reserved.
22
// Licensed under the MIT License. See License.txt in the project root for license information.
33

4+
using System;
5+
46
namespace Microsoft.Restier.Publishers.OData
57
{
6-
internal class PropertyAttributes
8+
[Flags]
9+
internal enum PropertyAttributes
710
{
11+
/// <summary>
12+
/// No flag is set for the property
13+
/// </summary>
14+
None = 0x0,
15+
816
/// <summary>
917
/// Gets or sets a value indicating whether the property should be ignored during update
1018
/// </summary>
11-
public bool IgnoreForUpdate { get; set; }
19+
IgnoreForUpdate = 0x1,
1220

1321
/// <summary>
1422
/// Gets or sets a value indicating whether the property should be ignored during creation
1523
/// </summary>
16-
public bool IgnoreForCreation { get; set; }
24+
IgnoreForCreation = 0x2,
1725

1826
/// <summary>
1927
/// Gets or sets a value indicating whether there is permission to read the property
2028
/// </summary>
21-
public bool NoReadPermission { get; set; }
29+
NoReadPermission = 0x4,
2230

2331
/// <summary>
2432
/// Gets or sets a value indicating whether there is permission to write the property
2533
/// </summary>
26-
public bool NoWritePermission { get; set; }
34+
NoWritePermission = 0x8
2735
}
2836
}

test/ODataEndToEnd/Microsoft.OData.Service.Library/DataStoreManager/DefaultDataStoreManager.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -110,9 +110,9 @@ private void ResouceTimeoutHandler(object source, EventArgs e)
110110

111111
private class DataStoreUnit
112112
{
113-
public TKey DatastoreKey { get; }
113+
public TKey DatastoreKey { get; private set; }
114114

115-
public TDataStoreType DataStore { get; }
115+
public TDataStoreType DataStore { get; private set; }
116116

117117
public DateTime DataStoreLastUsedDateTime { get; private set; }
118118

0 commit comments

Comments
 (0)