-
Notifications
You must be signed in to change notification settings - Fork 349
/
ExtensionMethods.cs
3688 lines (3213 loc) · 184 KB
/
ExtensionMethods.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
//---------------------------------------------------------------------
// <copyright file="ExtensionMethods.cs" company="Microsoft">
// Copyright (C) Microsoft Corporation. All rights reserved. See License.txt in the project root for license information.
// </copyright>
//---------------------------------------------------------------------
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Diagnostics;
using System.Globalization;
using System.Linq;
using Microsoft.OData.Edm.Csdl;
using Microsoft.OData.Edm.Csdl.CsdlSemantics;
using Microsoft.OData.Edm.Csdl.Parsing.Ast;
using Microsoft.OData.Edm.Csdl.Serialization;
using Microsoft.OData.Edm.Validation;
using Microsoft.OData.Edm.Vocabularies;
using Microsoft.OData.Edm.Vocabularies.Community.V1;
using Microsoft.OData.Edm.Vocabularies.V1;
namespace Microsoft.OData.Edm
{
/// <summary>
/// Contains extension methods for <see cref="IEdmModel"/> interfaces.
/// </summary>
public static class ExtensionMethods
{
private const int ContainerExtendsMaxDepth = 100;
private const string CollectionTypeFormat = EdmConstants.Type_Collection + "({0})";
private static readonly IEnumerable<IEdmStructuralProperty> EmptyStructuralProperties = Enumerable.Empty<IEdmStructuralProperty>();
private static readonly IEnumerable<IEdmNavigationProperty> EmptyNavigationProperties = Enumerable.Empty<IEdmNavigationProperty>();
#region IEdmModel
private static readonly Func<IEdmModel, string, IEdmSchemaType> findType = (model, qualifiedName) => model.FindDeclaredType(qualifiedName);
private static readonly Func<IEdmModel, string, IEdmTerm> findTerm = (model, qualifiedName) => model.FindDeclaredTerm(qualifiedName);
private static readonly Func<IEdmModel, string, IEnumerable<IEdmOperation>> findOperations = (model, qualifiedName) => model.FindDeclaredOperations(qualifiedName);
private static readonly Func<IEdmModel, string, IEdmEntityContainer> findEntityContainer = (model, qualifiedName) => { return model.ExistsContainer(qualifiedName) ? model.EntityContainer : null; };
private static readonly Func<IEnumerable<IEdmOperation>, IEnumerable<IEdmOperation>, IEnumerable<IEdmOperation>> mergeFunctions = (f1, f2) => Enumerable.Concat(f1, f2);
/// <summary>
/// Gets the value for the EDM version of the <paramref name="model"/>.
/// </summary>
/// <param name="model">Model the version has been set for.</param>
/// <returns>The version.</returns>
public static Version GetEdmVersion(this IEdmModel model)
{
EdmUtil.CheckArgumentNull(model, "model");
return model.GetAnnotationValue<Version>(model, EdmConstants.InternalUri, EdmConstants.EdmVersionAnnotation);
}
/// <summary>
/// Sets a value of EDM version attribute of the <paramref name="model"/>.
/// </summary>
/// <param name="model">The model the version should be set for.</param>
/// <param name="version">The version.</param>
public static void SetEdmVersion(this IEdmModel model, Version version)
{
EdmUtil.CheckArgumentNull(model, "model");
model.SetAnnotationValue(model, EdmConstants.InternalUri, EdmConstants.EdmVersionAnnotation, version);
}
#region IEdmModel interface's FindDeclaredXxx() methods, here their counterpart methods become FindXxx().
/// <summary>
/// Searches for a type with the given name in this model and all referenced models and returns null if no such type exists.
/// </summary>
/// <param name="model">The model to search.</param>
/// <param name="qualifiedName">The namespace or alias qualified name of the type being found.</param>
/// <returns>The requested type, or null if no such type exists.</returns>
public static IEdmSchemaType FindType(this IEdmModel model, string qualifiedName)
{
EdmUtil.CheckArgumentNull(model, "model");
EdmUtil.CheckArgumentNull(qualifiedName, "qualifiedName");
string fullyQualifiedName = model.ReplaceAlias(qualifiedName);
// search built-in EdmCoreModel and CoreVocabularyModel.
return FindAcrossModels(
model,
fullyQualifiedName,
findType,
(first, second) => RegistrationHelper.CreateAmbiguousTypeBinding(first, second));
}
/// <summary>
/// Searches for bound operations based on the binding type, returns an empty enumerable if no operation exists.
/// </summary>
/// <param name="model">The model to search.</param>
/// <param name="bindingType">Type of the binding.</param>
/// <returns>A set of operations that share the binding type or empty enumerable if no such operation exists.</returns>
public static IEnumerable<IEdmOperation> FindBoundOperations(this IEdmModel model, IEdmType bindingType)
{
EdmUtil.CheckArgumentNull(model, "model");
EdmUtil.CheckArgumentNull(bindingType, "bindingType");
IList<IEdmOperation> bindableOperations = new List<IEdmOperation>();
foreach (IEdmOperation operation in model.FindDeclaredBoundOperations(bindingType))
{
bindableOperations.Add(operation);
}
foreach (IEdmModel reference in model.ReferencedModels)
{
foreach (IEdmOperation operation in reference.FindDeclaredBoundOperations(bindingType))
{
bindableOperations.Add(operation);
}
}
return bindableOperations;
}
/// <summary>
/// Searches for bound operations based on the qualified name and binding type, returns an empty enumerable if no operation exists.
/// </summary>
/// <param name="model">The model to search.</param>
/// <param name="qualifiedName">The qualified name of the operation.</param>
/// <param name="bindingType">Type of the binding.</param>
/// <returns>A set of operations that share the qualified name and binding type or empty enumerable if no such operation exists.</returns>
public static IEnumerable<IEdmOperation> FindBoundOperations(this IEdmModel model, string qualifiedName, IEdmType bindingType)
{
EdmUtil.CheckArgumentNull(model, "model");
EdmUtil.CheckArgumentNull(qualifiedName, "qualifiedName");
EdmUtil.CheckArgumentNull(bindingType, "bindingType");
string fullyQualifiedName = model.ReplaceAlias(qualifiedName);
// the below is a copy of FindAcrossModels method but Func<IEdmModel, TInput, T> finder is replaced by FindDeclaredBoundOperations.
IEnumerable<IEdmOperation> candidate = model.FindDeclaredBoundOperations(fullyQualifiedName, bindingType);
foreach (IEdmModel reference in model.ReferencedModels)
{
IEnumerable<IEdmOperation> fromReference = reference.FindDeclaredBoundOperations(fullyQualifiedName, bindingType);
if (fromReference != null)
{
candidate = candidate == null ? fromReference : mergeFunctions(candidate, fromReference);
}
}
return candidate;
}
/// <summary>
/// Searches for a term with the given name in this model and all referenced models and returns null if no such term exists.
/// </summary>
/// <param name="model">The model to search.</param>
/// <param name="qualifiedName">The qualified name of the term being found.</param>
/// <returns>The requested term, or null if no such term exists.</returns>
public static IEdmTerm FindTerm(this IEdmModel model, string qualifiedName)
{
EdmUtil.CheckArgumentNull(model, "model");
EdmUtil.CheckArgumentNull(qualifiedName, "qualifiedName");
string fullyQualifiedName = model.ReplaceAlias(qualifiedName);
return FindAcrossModels(
model,
fullyQualifiedName,
findTerm,
(first, second) => RegistrationHelper.CreateAmbiguousTermBinding(first, second));
}
/// <summary>
/// Searches for operations with the given name in this model and all referenced models and returns an empty enumerable if no such operations exist.
/// </summary>
/// <param name="model">The model to search.</param>
/// <param name="qualifiedName">The qualified name of the operations being found.</param>
/// <returns>The requested operations.</returns>
public static IEnumerable<IEdmOperation> FindOperations(this IEdmModel model, string qualifiedName)
{
EdmUtil.CheckArgumentNull(model, "model");
EdmUtil.CheckArgumentNull(qualifiedName, "qualifiedName");
return FindAcrossModels(model, qualifiedName, findOperations, mergeFunctions);
}
#endregion
/// <summary>
/// If the container name in the model is the same as the input name. The input name maybe full qualified name.
/// </summary>
/// <param name="model">The model to search.</param>
/// <param name="containerName">Input container name to be searched. The container name may be full qualified with namespace prefix.</param>
/// <returns>True if the model has a container called input name, otherwise false.</returns>
public static bool ExistsContainer(this IEdmModel model, string containerName)
{
if (model.EntityContainer == null)
{
return false;
}
string fullQualifiedName = (model.EntityContainer.Namespace ?? String.Empty) + "." + (containerName ?? String.Empty);
if (string.Equals(model.EntityContainer.FullName(), fullQualifiedName, StringComparison.Ordinal)
|| string.Equals(model.EntityContainer.FullName(), containerName, StringComparison.Ordinal))
{
return true;
}
return false;
}
/// <summary>
/// Searches for an entity container with the given name in this model and all referenced models and returns null if no such entity container exists.
/// </summary>
/// <param name="model">The model to search.</param>
/// <param name="qualifiedName">The qualified name of the entity container being found.</param>
/// <returns>The requested entity container, or null if no such entity container exists.</returns>
public static IEdmEntityContainer FindEntityContainer(this IEdmModel model, string qualifiedName)
{
EdmUtil.CheckArgumentNull(model, "model");
EdmUtil.CheckArgumentNull(qualifiedName, "qualifiedName");
return FindAcrossModels(
model,
qualifiedName,
findEntityContainer,
(first, second) => RegistrationHelper.CreateAmbiguousEntityContainerBinding(first, second));
}
/// <summary>
/// Gets an annotatable element's vocabulary annotations defined in a specific model and models referenced by that model.
/// </summary>
/// <param name="model">The model to search.</param>
/// <param name="element">Element to check for annotations.</param>
/// <returns>Annotations attached to the element (or, if the element is a type, to its base types) by this model or by models referenced by this model.</returns>
public static IEnumerable<IEdmVocabularyAnnotation> FindVocabularyAnnotationsIncludingInheritedAnnotations(this IEdmModel model, IEdmVocabularyAnnotatable element)
{
EdmUtil.CheckArgumentNull(model, "model");
EdmUtil.CheckArgumentNull(element, "element");
IEnumerable<IEdmVocabularyAnnotation> result = model.FindDeclaredVocabularyAnnotations(element);
IEdmStructuredType typeElement = element as IEdmStructuredType;
if (typeElement != null)
{
typeElement = typeElement.BaseType;
while (typeElement != null)
{
IEdmVocabularyAnnotatable annotatableElement = typeElement as IEdmVocabularyAnnotatable;
if (annotatableElement != null)
{
result = result.Concat(model.FindDeclaredVocabularyAnnotations(annotatableElement));
}
typeElement = typeElement.BaseType;
}
}
return result;
}
/// <summary>
/// Gets an annotatable element's vocabulary annotations defined in a specific model and models referenced by that model.
/// </summary>
/// <param name="model">The model to search.</param>
/// <param name="element">Element to check for annotations.</param>
/// <returns>Annotations attached to the element by this model or by models referenced by this model.</returns>
public static IEnumerable<IEdmVocabularyAnnotation> FindVocabularyAnnotations(this IEdmModel model, IEdmVocabularyAnnotatable element)
{
EdmUtil.CheckArgumentNull(model, "model");
EdmUtil.CheckArgumentNull(element, "element");
VocabularyAnnotationCache cache = null;
bool isImmutable = model.IsImmutable();
if (isImmutable)
{
cache = model.GetVocabularyAnnotationCache();
if (cache.TryGetVocabularyAnnotations(element, out IEnumerable<IEdmVocabularyAnnotation> annotations))
{
return annotations;
}
}
IEnumerable<IEdmVocabularyAnnotation> result = model.FindVocabularyAnnotationsIncludingInheritedAnnotations(element);
foreach (IEdmModel referencedModel in model.ReferencedModels)
{
result = result.Concat(referencedModel.FindVocabularyAnnotationsIncludingInheritedAnnotations(element));
}
if (isImmutable)
{
List<IEdmVocabularyAnnotation> cachedAnnotations = result.ToList();
cache.AddVocabularyAnnotations(element, cachedAnnotations);
return cachedAnnotations;
}
return result;
}
/// <summary>
/// Gets an annotatable element's vocabulary annotations that bind a particular term.
/// </summary>
/// <typeparam name="T">Type of the annotation being returned.</typeparam>
/// <param name="model">Model to search.</param>
/// <param name="element">Element to check for annotations.</param>
/// <param name="term">Term to search for.</param>
/// <returns>Annotations attached to the element by this model or by models referenced by this model that bind the term.</returns>
public static IEnumerable<T> FindVocabularyAnnotations<T>(this IEdmModel model, IEdmVocabularyAnnotatable element, IEdmTerm term) where T : IEdmVocabularyAnnotation
{
EdmUtil.CheckArgumentNull(model, "model");
EdmUtil.CheckArgumentNull(element, "element");
EdmUtil.CheckArgumentNull(term, "term");
return FindVocabularyAnnotations<T>(model, element, term, null);
}
/// <summary>
/// Gets an annotatable element's vocabulary annotations that bind a particular term.
/// </summary>
/// <typeparam name="T">Type of the annotation being returned.</typeparam>
/// <param name="model">Model to search.</param>
/// <param name="element">Element to check for annotations.</param>
/// <param name="term">Term to search for.</param>
/// <param name="qualifier">Qualifier to apply.</param>
/// <returns>Annotations attached to the element by this model or by models referenced by this model that bind the term with the given qualifier.</returns>
public static IEnumerable<T> FindVocabularyAnnotations<T>(this IEdmModel model, IEdmVocabularyAnnotatable element, IEdmTerm term, string qualifier) where T : IEdmVocabularyAnnotation
{
EdmUtil.CheckArgumentNull(model, "model");
EdmUtil.CheckArgumentNull(element, "element");
EdmUtil.CheckArgumentNull(term, "term");
List<T> result = null;
// this loop runs in a hot path, we avoid using OfType<T>() to avoid the extra allocations of OfTypeIterator
foreach (IEdmVocabularyAnnotation item in model.FindVocabularyAnnotations(element))
{
if (item is T annotation && annotation.Term == term && (qualifier == null || qualifier == annotation.Qualifier))
{
if (result == null)
{
result = new List<T>();
}
result.Add(annotation);
}
}
return result ?? Enumerable.Empty<T>();
}
/// <summary>
/// Gets an annotatable element's vocabulary annotations that bind a particular term.
/// </summary>
/// <typeparam name="T">Type of the annotation being returned.</typeparam>
/// <param name="model">Model to search.</param>
/// <param name="element">Element to check for annotations.</param>
/// <param name="termName">Name of the term to search for.</param>
/// <returns>Annotations attached to the element by this model or by models referenced by this model that bind the term.</returns>
public static IEnumerable<T> FindVocabularyAnnotations<T>(this IEdmModel model, IEdmVocabularyAnnotatable element, string termName) where T : IEdmVocabularyAnnotation
{
EdmUtil.CheckArgumentNull(model, "model");
EdmUtil.CheckArgumentNull(element, "element");
EdmUtil.CheckArgumentNull(termName, "termName");
return FindVocabularyAnnotations<T>(model, element, termName, null);
}
/// <summary>
/// Gets an annotatable element's vocabulary annotations that bind a particular term.
/// </summary>
/// <typeparam name="T">Type of the annotation being returned.</typeparam>
/// <param name="model">Model to search.</param>
/// <param name="element">Element to check for annotations.</param>
/// <param name="termName">Name of the term to search for.</param>
/// <param name="qualifier">Qualifier to apply.</param>
/// <returns>Annotations attached to the element by this model or by models referenced by this model that bind the term with the given qualifier.</returns>
public static IEnumerable<T> FindVocabularyAnnotations<T>(this IEdmModel model, IEdmVocabularyAnnotatable element, string termName, string qualifier) where T : IEdmVocabularyAnnotation
{
EdmUtil.CheckArgumentNull(model, "model");
EdmUtil.CheckArgumentNull(element, "element");
EdmUtil.CheckArgumentNull(termName, "termName");
// Look up annotations on the element by name. There's no particular advantage in searching for a term first.
string name;
string namespaceName;
if (EdmUtil.TryGetNamespaceNameFromQualifiedName(termName, out namespaceName, out name))
{
// this loop runs in a hot path, we avoid using OfType<T>() to avoid the extra allocations of OfTypeIterator
foreach (IEdmVocabularyAnnotation item in model.FindVocabularyAnnotations(element))
{
if (item is T annotation)
{
IEdmTerm annotationTerm = annotation.Term;
if (annotationTerm.Namespace == namespaceName && annotationTerm.Name == name && (qualifier == null || qualifier == annotation.Qualifier))
{
yield return annotation;
}
}
}
}
}
/// <summary>
/// Gets the <see cref="IEdmValue "/> of a vocabulary term that has been applied to the type of a value.
/// </summary>
/// <param name="model">Model to search for term annotations.</param>
/// <param name="context">Value to use as context in evaluation.</param>
/// <param name="termName">Name of the term to evaluate.</param>
/// <param name="expressionEvaluator">Evaluator to use to perform expression evaluation.</param>
/// <returns>Value of the term evaluated against the supplied value.</returns>
public static IEdmValue GetTermValue(this IEdmModel model, IEdmStructuredValue context, string termName, EdmExpressionEvaluator expressionEvaluator)
{
EdmUtil.CheckArgumentNull(model, "model");
EdmUtil.CheckArgumentNull(context, "context");
EdmUtil.CheckArgumentNull(termName, "termName");
EdmUtil.CheckArgumentNull(expressionEvaluator, "expressionEvaluator");
return GetTermValue<IEdmValue>(model, context, context.Type.AsEntity().EntityDefinition(), termName, null, expressionEvaluator.Evaluate);
}
/// <summary>
/// Gets the <see cref="IEdmValue "/> of a vocabulary term that has been applied to the type of a value.
/// </summary>
/// <param name="model">Model to search for term annotations.</param>
/// <param name="context">Value to use as context in evaluation.</param>
/// <param name="termName">Name of the term to evaluate.</param>
/// <param name="qualifier">Qualifier to apply.</param>
/// <param name="expressionEvaluator">Evaluator to use to perform expression evaluation.</param>
/// <returns>Value of the term evaluated against the supplied value.</returns>
public static IEdmValue GetTermValue(this IEdmModel model, IEdmStructuredValue context, string termName, string qualifier, EdmExpressionEvaluator expressionEvaluator)
{
EdmUtil.CheckArgumentNull(model, "model");
EdmUtil.CheckArgumentNull(context, "context");
EdmUtil.CheckArgumentNull(termName, "termName");
EdmUtil.CheckArgumentNull(expressionEvaluator, "expressionEvaluator");
return GetTermValue<IEdmValue>(model, context, context.Type.AsEntity().EntityDefinition(), termName, qualifier, expressionEvaluator.Evaluate);
}
/// <summary>
/// Gets the <see cref="IEdmValue "/> of a vocabulary term that has been applied to the type of a value.
/// </summary>
/// <param name="model">Model to search for term annotations.</param>
/// <param name="context">Value to use as context in evaluation.</param>
/// <param name="term">Term to evaluate.</param>
/// <param name="expressionEvaluator">Evaluator to use to perform expression evaluation.</param>
/// <returns>Value of the term evaluated against the supplied value.</returns>
public static IEdmValue GetTermValue(this IEdmModel model, IEdmStructuredValue context, IEdmTerm term, EdmExpressionEvaluator expressionEvaluator)
{
EdmUtil.CheckArgumentNull(model, "model");
EdmUtil.CheckArgumentNull(context, "context");
EdmUtil.CheckArgumentNull(term, "term");
EdmUtil.CheckArgumentNull(expressionEvaluator, "expressionEvaluator");
return GetTermValue<IEdmValue>(model, context, context.Type.AsEntity().EntityDefinition(), term, null, expressionEvaluator.Evaluate);
}
/// <summary>
/// Gets the <see cref="IEdmValue "/> of a vocabulary term that has been applied to the type of a value.
/// </summary>
/// <param name="model">Model to search for term annotations.</param>
/// <param name="context">Value to use as context in evaluation.</param>
/// <param name="term">Term to evaluate.</param>
/// <param name="qualifier">Qualifier to apply.</param>
/// <param name="expressionEvaluator">Evaluator to use to perform expression evaluation.</param>
/// <returns>Value of the term evaluated against the supplied value.</returns>
public static IEdmValue GetTermValue(this IEdmModel model, IEdmStructuredValue context, IEdmTerm term, string qualifier, EdmExpressionEvaluator expressionEvaluator)
{
EdmUtil.CheckArgumentNull(model, "model");
EdmUtil.CheckArgumentNull(context, "context");
EdmUtil.CheckArgumentNull(term, "term");
EdmUtil.CheckArgumentNull(expressionEvaluator, "expressionEvaluator");
return GetTermValue<IEdmValue>(model, context, context.Type.AsEntity().EntityDefinition(), term, qualifier, expressionEvaluator.Evaluate);
}
/// <summary>
/// Gets the CLR value of a vocabulary term that has been applied to the type of a value.
/// </summary>
/// <typeparam name="T">The CLR type of the value to be returned.</typeparam>
/// <param name="model">Model to search for term annotations.</param>
/// <param name="context">Value to use as context in evaluation.</param>
/// <param name="termName">Name of the term to evaluate.</param>
/// <param name="evaluator">Evaluator to use to perform expression evaluation.</param>
/// <returns>Value of the term evaluated against the supplied value.</returns>
public static T GetTermValue<T>(this IEdmModel model, IEdmStructuredValue context, string termName, EdmToClrEvaluator evaluator)
{
EdmUtil.CheckArgumentNull(model, "model");
EdmUtil.CheckArgumentNull(context, "context");
EdmUtil.CheckArgumentNull(termName, "termName");
EdmUtil.CheckArgumentNull(evaluator, "evaluator");
return GetTermValue<T>(model, context, context.Type.AsEntity().EntityDefinition(), termName, null, evaluator.EvaluateToClrValue<T>);
}
/// <summary>
/// Gets the CLR value of a vocabulary term that has been applied to the type of a value.
/// </summary>
/// <typeparam name="T">The CLR type of the value to be returned.</typeparam>
/// <param name="model">Model to search for term annotations.</param>
/// <param name="context">Value to use as context in evaluation.</param>
/// <param name="termName">Name of the term to evaluate.</param>
/// <param name="qualifier">Qualifier to apply.</param>
/// <param name="evaluator">Evaluator to use to perform expression evaluation.</param>
/// <returns>Value of the term evaluated against the supplied value.</returns>
public static T GetTermValue<T>(this IEdmModel model, IEdmStructuredValue context, string termName, string qualifier, EdmToClrEvaluator evaluator)
{
EdmUtil.CheckArgumentNull(model, "model");
EdmUtil.CheckArgumentNull(context, "context");
EdmUtil.CheckArgumentNull(termName, "termName");
EdmUtil.CheckArgumentNull(evaluator, "evaluator");
return GetTermValue<T>(model, context, context.Type.AsEntity().EntityDefinition(), termName, qualifier, evaluator.EvaluateToClrValue<T>);
}
/// <summary>
/// Gets the CLR value of a vocabulary term that has been applied to the type of a value.
/// </summary>
/// <typeparam name="T">The CLR type of the value to be returned.</typeparam>
/// <param name="model">Model to search for term annotations.</param>
/// <param name="context">Value to use as context in evaluation.</param>
/// <param name="term">Term to evaluate.</param>
/// <param name="evaluator">Evaluator to use to perform expression evaluation.</param>
/// <returns>Value of the term evaluated against the supplied value.</returns>
public static T GetTermValue<T>(this IEdmModel model, IEdmStructuredValue context, IEdmTerm term, EdmToClrEvaluator evaluator)
{
EdmUtil.CheckArgumentNull(model, "model");
EdmUtil.CheckArgumentNull(context, "context");
EdmUtil.CheckArgumentNull(term, "term");
EdmUtil.CheckArgumentNull(evaluator, "evaluator");
return GetTermValue<T>(model, context, context.Type.AsEntity().EntityDefinition(), term, null, evaluator.EvaluateToClrValue<T>);
}
/// <summary>
/// Gets the CLR value of a vocabulary term that has been applied to the type of a value.
/// </summary>
/// <typeparam name="T">The CLR type of the value to be returned.</typeparam>
/// <param name="model">Model to search for term annotations.</param>
/// <param name="context">Value to use as context in evaluation.</param>
/// <param name="term">Term to evaluate.</param>
/// <param name="qualifier">Qualifier to apply.</param>
/// <param name="evaluator">Evaluator to use to perform expression evaluation.</param>
/// <returns>Value of the term evaluated against the supplied value.</returns>
public static T GetTermValue<T>(this IEdmModel model, IEdmStructuredValue context, IEdmTerm term, string qualifier, EdmToClrEvaluator evaluator)
{
EdmUtil.CheckArgumentNull(model, "model");
EdmUtil.CheckArgumentNull(context, "context");
EdmUtil.CheckArgumentNull(term, "term");
EdmUtil.CheckArgumentNull(evaluator, "evaluator");
return GetTermValue<T>(model, context, context.Type.AsEntity().EntityDefinition(), term, qualifier, evaluator.EvaluateToClrValue<T>);
}
/// <summary>
/// Gets the <see cref="IEdmValue "/> of a vocabulary term that has been applied to an element.
/// </summary>
/// <param name="model">Model to search for term annotations.</param>
/// <param name="element">Annotated element.</param>
/// <param name="termName">Name of the term to evaluate.</param>
/// <param name="expressionEvaluator">Evaluator to use to perform expression evaluation.</param>
/// <returns>Value of the term evaluated against the supplied value.</returns>
public static IEdmValue GetTermValue(this IEdmModel model, IEdmVocabularyAnnotatable element, string termName, EdmExpressionEvaluator expressionEvaluator)
{
EdmUtil.CheckArgumentNull(model, "model");
EdmUtil.CheckArgumentNull(element, "element");
EdmUtil.CheckArgumentNull(termName, "termName");
EdmUtil.CheckArgumentNull(expressionEvaluator, "evaluator");
return GetTermValue<IEdmValue>(model, element, termName, null, expressionEvaluator.Evaluate);
}
/// <summary>
/// Gets the <see cref="IEdmValue "/> of a vocabulary term that has been applied to an element.
/// </summary>
/// <param name="model">Model to search for term annotations.</param>
/// <param name="element">Annotated element.</param>
/// <param name="termName">Name of the term to evaluate.</param>
/// <param name="qualifier">Qualifier to apply.</param>
/// <param name="expressionEvaluator">Evaluator to use to perform expression evaluation.</param>
/// <returns>Value of the term evaluated against the supplied value.</returns>
public static IEdmValue GetTermValue(this IEdmModel model, IEdmVocabularyAnnotatable element, string termName, string qualifier, EdmExpressionEvaluator expressionEvaluator)
{
EdmUtil.CheckArgumentNull(model, "model");
EdmUtil.CheckArgumentNull(element, "element");
EdmUtil.CheckArgumentNull(termName, "termName");
EdmUtil.CheckArgumentNull(expressionEvaluator, "evaluator");
return GetTermValue<IEdmValue>(model, element, termName, qualifier, expressionEvaluator.Evaluate);
}
/// <summary>
/// Gets the <see cref="IEdmValue "/> of a vocabulary term that has been applied to an element.
/// </summary>
/// <param name="model">Model to search for term annotations.</param>
/// <param name="element">Annotated element.</param>
/// <param name="term">Term to evaluate.</param>
/// <param name="expressionEvaluator">Evaluator to use to perform expression evaluation.</param>
/// <returns>Value of the term evaluated against the supplied value.</returns>
public static IEdmValue GetTermValue(this IEdmModel model, IEdmVocabularyAnnotatable element, IEdmTerm term, EdmExpressionEvaluator expressionEvaluator)
{
EdmUtil.CheckArgumentNull(model, "model");
EdmUtil.CheckArgumentNull(element, "element");
EdmUtil.CheckArgumentNull(term, "term");
EdmUtil.CheckArgumentNull(expressionEvaluator, "evaluator");
return GetTermValue<IEdmValue>(model, element, term, null, expressionEvaluator.Evaluate);
}
/// <summary>
/// Gets the <see cref="IEdmValue "/> of a vocabulary term that has been applied to an element.
/// </summary>
/// <param name="model">Model to search for term annotations.</param>
/// <param name="element">Annotated element.</param>
/// <param name="term">Term to evaluate.</param>
/// <param name="qualifier">Qualifier to apply.</param>
/// <param name="expressionEvaluator">Evaluator to use to perform expression evaluation.</param>
/// <returns>Value of the term evaluated against the supplied value.</returns>
public static IEdmValue GetTermValue(this IEdmModel model, IEdmVocabularyAnnotatable element, IEdmTerm term, string qualifier, EdmExpressionEvaluator expressionEvaluator)
{
EdmUtil.CheckArgumentNull(model, "model");
EdmUtil.CheckArgumentNull(element, "element");
EdmUtil.CheckArgumentNull(term, "term");
EdmUtil.CheckArgumentNull(expressionEvaluator, "evaluator");
return GetTermValue<IEdmValue>(model, element, term, qualifier, expressionEvaluator.Evaluate);
}
/// <summary>
/// Gets the CLR value of a vocabulary term that has been applied to an element.
/// </summary>
/// <typeparam name="T">The CLR type of the value to be returned.</typeparam>
/// <param name="model">Model to search for term annotations.</param>
/// <param name="element">Annotated element.</param>
/// <param name="termName">Name of the term to evaluate.</param>
/// <param name="evaluator">Evaluator to use to perform expression evaluation.</param>
/// <returns>Value of the term evaluated against the supplied value.</returns>
public static T GetTermValue<T>(this IEdmModel model, IEdmVocabularyAnnotatable element, string termName, EdmToClrEvaluator evaluator)
{
EdmUtil.CheckArgumentNull(model, "model");
EdmUtil.CheckArgumentNull(element, "element");
EdmUtil.CheckArgumentNull(termName, "termName");
EdmUtil.CheckArgumentNull(evaluator, "evaluator");
return GetTermValue<T>(model, element, termName, null, evaluator.EvaluateToClrValue<T>);
}
/// <summary>
/// Gets the CLR value of a vocabulary term that has been applied to an element.
/// </summary>
/// <typeparam name="T">The CLR type of the value to be returned.</typeparam>
/// <param name="model">Model to search for term annotations.</param>
/// <param name="element">Annotated element.</param>
/// <param name="termName">Name of the term to evaluate.</param>
/// <param name="qualifier">Qualifier to apply.</param>
/// <param name="evaluator">Evaluator to use to perform expression evaluation.</param>
/// <returns>Value of the term evaluated against the supplied value.</returns>
public static T GetTermValue<T>(this IEdmModel model, IEdmVocabularyAnnotatable element, string termName, string qualifier, EdmToClrEvaluator evaluator)
{
EdmUtil.CheckArgumentNull(model, "model");
EdmUtil.CheckArgumentNull(element, "element");
EdmUtil.CheckArgumentNull(termName, "termName");
EdmUtil.CheckArgumentNull(evaluator, "evaluator");
return GetTermValue<T>(model, element, termName, qualifier, evaluator.EvaluateToClrValue<T>);
}
/// <summary>
/// Gets the CLR value of a vocabulary term that has been applied to an element.
/// </summary>
/// <typeparam name="T">The CLR type of the value to be returned.</typeparam>
/// <param name="model">Model to search for term annotations.</param>
/// <param name="element">Annotated element.</param>
/// <param name="term">Term to evaluate.</param>
/// <param name="evaluator">Evaluator to use to perform expression evaluation.</param>
/// <returns>Value of the term evaluated against the supplied value.</returns>
public static T GetTermValue<T>(this IEdmModel model, IEdmVocabularyAnnotatable element, IEdmTerm term, EdmToClrEvaluator evaluator)
{
EdmUtil.CheckArgumentNull(model, "model");
EdmUtil.CheckArgumentNull(element, "element");
EdmUtil.CheckArgumentNull(term, "term");
EdmUtil.CheckArgumentNull(evaluator, "evaluator");
return GetTermValue<T>(model, element, term, null, evaluator.EvaluateToClrValue<T>);
}
/// <summary>
/// Gets the CLR value of a vocabulary term that has been applied to an element.
/// </summary>
/// <typeparam name="T">The CLR type of the value to be returned.</typeparam>
/// <param name="model">Model to search for term annotations.</param>
/// <param name="element">Annotated element.</param>
/// <param name="term">Term to evaluate.</param>
/// <param name="qualifier">Qualifier to apply.</param>
/// <param name="evaluator">Evaluator to use to perform expression evaluation.</param>
/// <returns>Value of the term evaluated against the supplied value.</returns>
public static T GetTermValue<T>(this IEdmModel model, IEdmVocabularyAnnotatable element, IEdmTerm term, string qualifier, EdmToClrEvaluator evaluator)
{
EdmUtil.CheckArgumentNull(model, "model");
EdmUtil.CheckArgumentNull(element, "element");
EdmUtil.CheckArgumentNull(term, "term");
EdmUtil.CheckArgumentNull(evaluator, "evaluator");
return GetTermValue<T>(model, element, term, qualifier, evaluator.EvaluateToClrValue<T>);
}
/// <summary>
/// Gets an annotation value corresponding to the given namespace and name provided.
/// </summary>
/// <param name="model">The model containing the annotation.</param>
/// <param name="element">The annotated element.</param>
/// <param name="namespaceName">Namespace of the annotation.</param>
/// <param name="localName">Name of the annotation inside the namespace.</param>
/// <returns>The requested annotation value, if it exists. Otherwise, null.</returns>
public static object GetAnnotationValue(this IEdmModel model, IEdmElement element, string namespaceName, string localName)
{
EdmUtil.CheckArgumentNull(model, "model");
EdmUtil.CheckArgumentNull(element, "element");
return model.DirectValueAnnotationsManager.GetAnnotationValue(element, namespaceName, localName);
}
/// <summary>
/// Gets an annotation value corresponding to the given namespace and name provided.
/// </summary>
/// <typeparam name="T">Type of the annotation being returned.</typeparam>
/// <param name="model">The model containing the annotation.</param>
/// <param name="element">The annotated element.</param>
/// <param name="namespaceName">Namespace of the annotation.</param>
/// <param name="localName">Name of the annotation inside the namespace.</param>
/// <returns>The requested annotation value, if it exists. Otherwise, null.</returns>
public static T GetAnnotationValue<T>(this IEdmModel model, IEdmElement element, string namespaceName, string localName) where T : class
{
EdmUtil.CheckArgumentNull(model, "model");
EdmUtil.CheckArgumentNull(element, "element");
return AnnotationValue<T>(model.GetAnnotationValue(element, namespaceName, localName));
}
/// <summary>
/// Gets an annotation value from an annotatable element.
/// </summary>
/// <typeparam name="T">Type of the annotation being returned.</typeparam>
/// <param name="model">The model containing the annotation.</param>
/// <param name="element">The annotated element.</param>
/// <returns>The requested annotation, if it exists. Otherwise, null.</returns>
/// <remarks>
/// Strongly-typed wrappers for unnamed annotations keyed by CLR type.
/// </remarks>
public static T GetAnnotationValue<T>(this IEdmModel model, IEdmElement element) where T : class
{
EdmUtil.CheckArgumentNull(model, "model");
EdmUtil.CheckArgumentNull(element, "element");
return model.GetAnnotationValue<T>(element, EdmConstants.InternalUri, TypeName<T>.LocalName);
}
/// <summary>
/// Sets an annotation value for an EDM element. If the value is null, no annotation is added and an existing annotation with the same name is removed.
/// </summary>
/// <param name="model">The model containing the annotation.</param>
/// <param name="element">The annotated element.</param>
/// <param name="namespaceName">Namespace that the annotation belongs to.</param>
/// <param name="localName">Name of the annotation within the namespace.</param>
/// <param name="value">Value of the new annotation.</param>
public static void SetAnnotationValue(this IEdmModel model, IEdmElement element, string namespaceName, string localName, object value)
{
EdmUtil.CheckArgumentNull(model, "model");
EdmUtil.CheckArgumentNull(element, "element");
model.DirectValueAnnotationsManager.SetAnnotationValue(element, namespaceName, localName, value);
}
/// <summary>
/// Gets description for term Org.OData.Core.V1.Description from a target annotatable
/// </summary>
/// <param name="model">The model referenced to.</param>
/// <param name="target">The target Annotatable to find annotation</param>
/// <returns>Description for term Org.OData.Core.V1.Description</returns>
public static string GetDescriptionAnnotation(this IEdmModel model, IEdmVocabularyAnnotatable target)
{
EdmUtil.CheckArgumentNull(model, "model");
EdmUtil.CheckArgumentNull(target, "target");
IEdmVocabularyAnnotation annotation = model.FindVocabularyAnnotations<IEdmVocabularyAnnotation>(target, CoreVocabularyModel.DescriptionTerm).FirstOrDefault();
if (annotation != null)
{
IEdmStringConstantExpression stringConstant = annotation.Value as IEdmStringConstantExpression;
if (stringConstant != null)
{
return stringConstant.Value;
}
}
return null;
}
/// <summary>
/// Gets description for term Org.OData.Core.V1.LongDescription from a target annotatable
/// </summary>
/// <param name="model">The model referenced to.</param>
/// <param name="target">The target Annotatable to find annotation</param>
/// <returns>Description for term Org.OData.Core.V1.LongDescription</returns>
public static string GetLongDescriptionAnnotation(this IEdmModel model, IEdmVocabularyAnnotatable target)
{
EdmUtil.CheckArgumentNull(model, "model");
EdmUtil.CheckArgumentNull(target, "target");
IEdmVocabularyAnnotation annotation = model.FindVocabularyAnnotations<IEdmVocabularyAnnotation>(target, CoreVocabularyModel.LongDescriptionTerm).FirstOrDefault();
if (annotation != null)
{
IEdmStringConstantExpression stringConstant = annotation.Value as IEdmStringConstantExpression;
if (stringConstant != null)
{
return stringConstant.Value;
}
}
return null;
}
/// <summary>
/// Gets the collection of qualified type name for term Org.OData.Validation.V1.DerivedTypeConstraint from a navigation source.
/// </summary>
/// <param name="model">The model referenced to.</param>
/// <param name="navigationSource">The navigation source.</param>
/// <returns>Null or a collection string of qualified type name.</returns>
public static IEnumerable<string> GetDerivedTypeConstraints(this IEdmModel model, IEdmNavigationSource navigationSource)
{
if (model == null || navigationSource == null)
{
return null;
}
IEnumerable<string> derivedTypeConstraints = null;
switch (navigationSource.NavigationSourceKind())
{
case EdmNavigationSourceKind.EntitySet:
derivedTypeConstraints = model.GetDerivedTypeConstraints((IEdmVocabularyAnnotatable)(IEdmEntitySet)navigationSource);
break;
case EdmNavigationSourceKind.Singleton:
derivedTypeConstraints = model.GetDerivedTypeConstraints((IEdmVocabularyAnnotatable)(IEdmSingleton)navigationSource);
break;
}
return derivedTypeConstraints;
}
/// <summary>
/// Gets the collection of qualified type name for term Org.OData.Validation.V1.DerivedTypeConstraint from a target annotatable.
/// </summary>
/// <param name="model">The model referenced to.</param>
/// <param name="target">The target annotatable to find annotation.</param>
/// <returns>Null or a collection string of qualified type name.</returns>
public static IEnumerable<string> GetDerivedTypeConstraints(this IEdmModel model, IEdmVocabularyAnnotatable target)
{
if (model == null || target == null)
{
return null;
}
IEdmVocabularyAnnotation annotation = model.FindVocabularyAnnotations<IEdmVocabularyAnnotation>(target, ValidationVocabularyModel.DerivedTypeConstraintTerm).FirstOrDefault();
if (annotation != null)
{
IEdmCollectionExpression collectionExpression = annotation.Value as IEdmCollectionExpression;
if (collectionExpression != null && collectionExpression.Elements != null)
{
return collectionExpression.Elements.OfType<IEdmStringConstantExpression>().Select(e => e.Value);
}
}
return null;
}
/// <summary>
/// Gets all schema elements from the model, and models referenced by it.
/// </summary>
/// <param name="model">Model to search for elements</param>
/// <returns>Schema elements from the model, and models referenced by it.</returns>
public static IEnumerable<IEdmSchemaElement> SchemaElementsAcrossModels(this IEdmModel model)
{
EdmUtil.CheckArgumentNull(model, "model");
IEnumerable<IEdmSchemaElement> result = Enumerable.Empty<IEdmSchemaElement>();
foreach (IEdmModel referencedModel in model.ReferencedModels)
{
result = result.Concat(referencedModel.SchemaElements);
}
result = result.Concat(model.SchemaElements);
return result;
}
/// <summary>
/// Finds a list of types that derive from the supplied type directly or indirectly, and across models.
/// </summary>
/// <param name="model">The model types are being found on.</param>
/// <param name="baseType">The base type that derived types are being searched for.</param>
/// <returns>A list of types that derive from the type.</returns>
public static IEnumerable<IEdmStructuredType> FindAllDerivedTypes(this IEdmModel model, IEdmStructuredType baseType)
{
List<IEdmStructuredType> result = new List<IEdmStructuredType>();
if (baseType is IEdmSchemaElement)
{
model.DerivedFrom(baseType, new HashSetInternal<IEdmStructuredType>(), result);
}
return result;
}
/// <summary>
/// Sets an annotation value on an annotatable element.
/// </summary>
/// <typeparam name="T">Type of the annotation being set.</typeparam>
/// <param name="model">The model containing the annotation.</param>
/// <param name="element">The annotated element.</param>
/// <param name="value">Value of the new annotation.</param>
public static void SetAnnotationValue<T>(this IEdmModel model, IEdmElement element, T value) where T : class
{
EdmUtil.CheckArgumentNull(model, "model");
EdmUtil.CheckArgumentNull(element, "element");
model.SetAnnotationValue(element, EdmConstants.InternalUri, TypeName<T>.LocalName, value);
}
/// <summary>
/// Retrieves a set of annotation values. For each requested value, returns null if no annotation with the given name exists for the given element.
/// </summary>
/// <param name="model">The model in which to find the annotations.</param>
/// <param name="annotations">The set of requested annotations.</param>
/// <returns>Returns values that correspond to the provided annotations. A value is null if no annotation with the given name exists for the given element.</returns>
public static object[] GetAnnotationValues(this IEdmModel model, IEnumerable<IEdmDirectValueAnnotationBinding> annotations)
{
EdmUtil.CheckArgumentNull(model, "model");
EdmUtil.CheckArgumentNull(annotations, "annotations");
return model.DirectValueAnnotationsManager.GetAnnotationValues(annotations);
}
/// <summary>
/// Sets a set of annotation values. If a supplied value is null, no annotation is added and an existing annotation with the same name is removed.
/// </summary>
/// <param name="model">The model in which to set the annotations.</param>
/// <param name="annotations">The annotations to set.</param>
public static void SetAnnotationValues(this IEdmModel model, IEnumerable<IEdmDirectValueAnnotationBinding> annotations)
{
EdmUtil.CheckArgumentNull(model, "model");
EdmUtil.CheckArgumentNull(annotations, "annotations");
model.DirectValueAnnotationsManager.SetAnnotationValues(annotations);
}
/// <summary>
/// Gets the direct annotations for an element.
/// </summary>
/// <param name="model">The model containing the annotations.</param>
/// <param name="element">The annotated element.</param>
/// <returns>The immediate annotations of the element.</returns>
public static IEnumerable<IEdmDirectValueAnnotation> DirectValueAnnotations(this IEdmModel model, IEdmElement element)
{
EdmUtil.CheckArgumentNull(model, "model");
EdmUtil.CheckArgumentNull(element, "element");
return model.DirectValueAnnotationsManager.GetDirectValueAnnotations(element);
}
/// <summary>
/// Finds the entity set with qualified entity set name (not simple entity set name).
/// </summary>
/// <param name="model">The model.</param>
/// <param name="containerQualifiedEntitySetName">Name of the container qualified element, can be an OperationImport or an EntitySet.</param>
/// <param name="entitySet">The Entity Set that was found.</param>
/// <returns>True if an entityset was found from the qualified container name, false if none were found.</returns>
public static bool TryFindContainerQualifiedEntitySet(this IEdmModel model, string containerQualifiedEntitySetName, out IEdmEntitySet entitySet)
{
entitySet = null;
string containerName = null;
string simpleEntitySetName = null;
if (containerQualifiedEntitySetName != null &&
containerQualifiedEntitySetName.IndexOf(".", StringComparison.Ordinal) > -1 &&
EdmUtil.TryParseContainerQualifiedElementName(containerQualifiedEntitySetName, out containerName, out simpleEntitySetName))
{
if (model.ExistsContainer(containerName))
{
IEdmEntityContainer container = model.EntityContainer;
if (container != null)
{
entitySet = container.FindEntitySetExtended(simpleEntitySetName);
}
}
}
return (entitySet != null);
}
/// <summary>
/// Finds the singleton.
/// </summary>
/// <param name="model">The model.</param>
/// <param name="containerQualifiedSingletonName">Name of the container qualified singleton element.</param>
/// <param name="singleton">The singleton that was found.</param>
/// <returns>True if an singleton was found from the qualified container name, false if none were found.</returns>
public static bool TryFindContainerQualifiedSingleton(this IEdmModel model, string containerQualifiedSingletonName, out IEdmSingleton singleton)