internal static bool AddMemberNameToHashSet(IEdmNamedElement item, HashSetInternal <string> memberNameList, ValidationContext context, EdmErrorCode errorCode, string errorString, bool suppressError) { string name; IEdmSchemaElement edmSchemaElement = item as IEdmSchemaElement; if (edmSchemaElement != null) { name = edmSchemaElement.FullName(); } else { name = item.Name; } string str = name; if (memberNameList.Add(str)) { return(true); } else { if (!suppressError) { context.AddError(item.Location(), errorCode, errorString); } return(false); } }
internal static void RegisterSchemaElement(IEdmSchemaElement element, Dictionary <string, IEdmSchemaType> schemaTypeDictionary, Dictionary <string, IEdmValueTerm> valueTermDictionary, Dictionary <string, object> functionGroupDictionary, Dictionary <string, IEdmEntityContainer> containerDictionary) { string qualifiedName = element.FullName(); switch (element.SchemaElementKind) { case EdmSchemaElementKind.Function: AddFunction((IEdmFunction)element, qualifiedName, functionGroupDictionary); break; case EdmSchemaElementKind.TypeDefinition: AddElement((IEdmSchemaType)element, qualifiedName, schemaTypeDictionary, CreateAmbiguousTypeBinding); break; case EdmSchemaElementKind.ValueTerm: AddElement((IEdmValueTerm)element, qualifiedName, valueTermDictionary, CreateAmbiguousValueTermBinding); break; case EdmSchemaElementKind.EntityContainer: // Add EntityContainers to the dictionary twice to maintian backwards compat with Edms that did not consider EntityContainers to be schema elements. AddElement((IEdmEntityContainer)element, qualifiedName, containerDictionary, CreateAmbiguousEntityContainerBinding); AddElement((IEdmEntityContainer)element, element.Name, containerDictionary, CreateAmbiguousEntityContainerBinding); break; case EdmSchemaElementKind.None: throw new InvalidOperationException(Edm.Strings.EdmModel_CannotUseElementWithTypeNone); default: throw new InvalidOperationException(Edm.Strings.UnknownEnumVal_SchemaElementKind(element.SchemaElementKind)); } }
internal static string FullName(this IEdmType edmType) { IEdmSchemaElement element = edmType as IEdmSchemaElement; if (element != null) { return(element.FullName()); } return(null); }
internal static string FullyQualifiedName(IEdmVocabularyAnnotatable element) { IEdmSchemaElement schemaElement = element as IEdmSchemaElement; if (schemaElement != null) { IEdmOperation operation = schemaElement as IEdmOperation; if (operation != null) { return(ParameterizedName(operation)); } else { return(schemaElement.FullName()); } } else { IEdmEntityContainerElement containerElement = element as IEdmEntityContainerElement; if (containerElement != null) { return(containerElement.Container.FullName() + "/" + containerElement.Name); } else { IEdmProperty property = element as IEdmProperty; if (property != null) { IEdmSchemaType declaringSchemaType = property.DeclaringType as IEdmSchemaType; if (declaringSchemaType != null) { string propertyOwnerName = FullyQualifiedName(declaringSchemaType); if (propertyOwnerName != null) { return(propertyOwnerName + "/" + property.Name); } } } else { IEdmOperationParameter parameter = element as IEdmOperationParameter; if (parameter != null) { string parameterOwnerName = FullyQualifiedName(parameter.DeclaringOperation); if (parameterOwnerName != null) { return(parameterOwnerName + "/" + parameter.Name); } } } } } return(null); }
private ModelEntityName ConvertToModelEntityName(IEdmSchemaElement element) { if (element == null) { return(null); } else { return(new ModelEntityName(element.Namespace, element.FullName(), element.Name)); } }
protected void VerifyFindSchemaElementMethod(XElement sourceCsdl, IEdmModel testModel) { var csdlNamespace = EdmLibCsdlContentGenerator.GetCsdlFullNamespace(this.EdmVersion); Assert.AreEqual(csdlNamespace, sourceCsdl.Name.Namespace, "The source CSDL's namespace should match the target EDM version of the test cases."); IEnumerable <string> schemaElementTypes = new string[] { "EntityType", "ComplexType", "Function", "Term" }; // TODO: Function should be filtered based on the CSDL version; It is supported from CSDL 2.0. // TODO: What is the expected behavior of the parser when a CSDL of 1.0 has Functions. var namespaceValue = sourceCsdl.Attribute("Namespace").Value; foreach (var schemaElementType in schemaElementTypes) { var schemaElements = from element in sourceCsdl.Elements(XName.Get(schemaElementType, csdlNamespace.NamespaceName)) select element; Console.WriteLine("Test CSDL:\n\r{0}", sourceCsdl.ToString()); foreach (var schemaElement in schemaElements) { var elementNameExpected = string.Format("{0}.{1}", namespaceValue, schemaElement.Attribute("Name").Value); Console.WriteLine("FindSchemaType for {0}", elementNameExpected); var typeFound = testModel.FindType(elementNameExpected); Assert.AreEqual(typeFound, testModel.FindDeclaredType(elementNameExpected), "The results between FindMethod and its declared version should be same."); var operationGroup = testModel.FindOperations(elementNameExpected); Assert.IsTrue(operationGroup.Count() == testModel.FindDeclaredOperations(elementNameExpected).Count() && !operationGroup.Except(testModel.FindDeclaredOperations(elementNameExpected)).Any(), "The results between FindMethod and its declared version should be same."); var valueTermFound = testModel.FindValueTerm(elementNameExpected); Assert.AreEqual(valueTermFound, testModel.FindDeclaredValueTerm(elementNameExpected), "The results between FindMethod and its declared version should be same."); Assert.IsFalse((typeFound == null) && (operationGroup == null) && (valueTermFound == null), "Failed to FindSchemaType for {0}", elementNameExpected); IEdmSchemaElement schemaElementFound = null; if (operationGroup.Count() > 0) { schemaElementFound = (IEdmSchemaElement)operationGroup.First(); } else if (typeFound != null) { schemaElementFound = typeFound; } else if (valueTermFound != null) { schemaElementFound = valueTermFound; } Assert.IsTrue(elementNameExpected.Equals(schemaElementFound.FullName(), System.StringComparison.Ordinal), "The found result {0} is different from {1}", schemaElementFound.FullName(), elementNameExpected); } } }
private string SerializationName(IEdmSchemaElement element) { if (this.namespaceAliasMappings != null) { string alias; if (this.namespaceAliasMappings.TryGetValue(element.Namespace, out alias)) { return(alias + "." + element.Name); } } return(element.FullName()); }
private string SerializationName(IEdmSchemaElement element) { string str = null; if (this.namespaceAliasMappings == null || !this.namespaceAliasMappings.TryGetValue(element.Namespace, out str)) { return(element.FullName()); } else { return(string.Concat(str, ".", element.Name)); } }
internal static bool AddMemberNameToHashSet(IEdmNamedElement item, HashSetInternal <string> memberNameList, ValidationContext context, EdmErrorCode errorCode, string errorString, bool suppressError) { IEdmSchemaElement schemaElement = item as IEdmSchemaElement; string name = (schemaElement != null) ? schemaElement.FullName() : item.Name; if (!memberNameList.Add(name)) { if (!suppressError) { context.AddError(item.Location(), errorCode, errorString); } return(false); } return(true); }
private static int GetTargetDepth(IEdmSchemaElement target, OdcmClass odcmClass) { int depth = 0; if (target != null && odcmClass != null) { for (; odcmClass.FullName != target.FullName(); odcmClass = odcmClass.Base) { if (odcmClass.Base == null) { throw new InvalidOperationException($"Could not find target {target.FullName()}"); } ++depth; } } return(depth); }
internal static string ODataFullName(this IEdmType type) { IEdmCollectionType type2 = type as IEdmCollectionType; if (type2 != null) { string str = type2.ElementType.ODataFullName(); if (str == null) { return(null); } return("Collection(" + str + ")"); } IEdmSchemaElement element = type as IEdmSchemaElement; if (element == null) { return(null); } return(element.FullName()); }
internal static void RegisterSchemaElement(IEdmSchemaElement element, Dictionary <string, IEdmSchemaType> schemaTypeDictionary, Dictionary <string, IEdmTerm> valueTermDictionary, Dictionary <string, IList <IEdmOperation> > functionGroupDictionary, Dictionary <string, IEdmEntityContainer> containerDictionary) { string qualifiedName = element.FullName(); switch (element.SchemaElementKind) { case EdmSchemaElementKind.Action: case EdmSchemaElementKind.Function: AddOperation((IEdmOperation)element, qualifiedName, functionGroupDictionary); break; case EdmSchemaElementKind.TypeDefinition: AddElement((IEdmSchemaType)element, qualifiedName, schemaTypeDictionary, CreateAmbiguousTypeBinding); break; case EdmSchemaElementKind.Term: AddElement((IEdmTerm)element, qualifiedName, valueTermDictionary, CreateAmbiguousTermBinding); break; case EdmSchemaElementKind.EntityContainer: // Only one entity container can be added. if (containerDictionary.Count > 0) { throw new InvalidOperationException(Edm.Strings.EdmModel_CannotAddMoreThanOneEntityContainerToOneEdmModel); } IEdmEntityContainer container = (IEdmEntityContainer)element; AddElement(container, qualifiedName, containerDictionary, CreateAmbiguousEntityContainerBinding); AddElement(container, element.Name, containerDictionary, CreateAmbiguousEntityContainerBinding); break; case EdmSchemaElementKind.None: throw new InvalidOperationException(Edm.Strings.EdmModel_CannotUseElementWithTypeNone); default: throw new InvalidOperationException(Edm.Strings.UnknownEnumVal_SchemaElementKind(element.SchemaElementKind)); } }
internal static void RegisterSchemaElement(IEdmSchemaElement element, Dictionary <string, IEdmSchemaType> schemaTypeDictionary, Dictionary <string, IEdmValueTerm> valueTermDictionary, Dictionary <string, object> functionGroupDictionary, Dictionary <string, IEdmEntityContainer> containerDictionary) { string str = element.FullName(); EdmSchemaElementKind schemaElementKind = element.SchemaElementKind; switch (schemaElementKind) { case EdmSchemaElementKind.None: { throw new InvalidOperationException(Strings.EdmModel_CannotUseElementWithTypeNone); } case EdmSchemaElementKind.TypeDefinition: { RegistrationHelper.AddElement <IEdmSchemaType>((IEdmSchemaType)element, str, schemaTypeDictionary, new Func <IEdmSchemaType, IEdmSchemaType, IEdmSchemaType>(RegistrationHelper.CreateAmbiguousTypeBinding)); return; } case EdmSchemaElementKind.Function: { RegistrationHelper.AddFunction <IEdmFunction>((IEdmFunction)element, str, functionGroupDictionary); return; } case EdmSchemaElementKind.ValueTerm: { RegistrationHelper.AddElement <IEdmValueTerm>((IEdmValueTerm)element, str, valueTermDictionary, new Func <IEdmValueTerm, IEdmValueTerm, IEdmValueTerm>(RegistrationHelper.CreateAmbiguousValueTermBinding)); return; } case EdmSchemaElementKind.EntityContainer: { RegistrationHelper.AddElement <IEdmEntityContainer>((IEdmEntityContainer)element, str, containerDictionary, new Func <IEdmEntityContainer, IEdmEntityContainer, IEdmEntityContainer>(RegistrationHelper.CreateAmbiguousEntityContainerBinding)); RegistrationHelper.AddElement <IEdmEntityContainer>((IEdmEntityContainer)element, element.Name, containerDictionary, new Func <IEdmEntityContainer, IEdmEntityContainer, IEdmEntityContainer>(RegistrationHelper.CreateAmbiguousEntityContainerBinding)); return; } } throw new InvalidOperationException(Strings.UnknownEnumVal_SchemaElementKind(element.SchemaElementKind)); }
private static string GetFullName(IEdmSchemaElement schemaElement) { return(schemaElement.FullName()); }
/// <summary> /// Returns the text representation of the current object. /// </summary> /// <param name="schemaElement">Reference to the calling object.</param> /// <returns>The text representation of the current object.</returns> public static string ToTraceString(this IEdmSchemaElement schemaElement) { return(schemaElement.FullName()); }
public static string FullyQualifiedName(IEdmVocabularyAnnotatable element) { IEdmSchemaElement edmSchemaElement = element as IEdmSchemaElement; if (edmSchemaElement == null) { IEdmEntityContainerElement edmEntityContainerElement = element as IEdmEntityContainerElement; if (edmEntityContainerElement == null) { IEdmProperty edmProperty = element as IEdmProperty; if (edmProperty == null) { IEdmFunctionParameter edmFunctionParameter = element as IEdmFunctionParameter; if (edmFunctionParameter != null) { string str = EdmUtil.FullyQualifiedName(edmFunctionParameter.DeclaringFunction); if (str != null) { return(string.Concat(str, "/", edmFunctionParameter.Name)); } } } else { IEdmSchemaType declaringType = edmProperty.DeclaringType as IEdmSchemaType; if (declaringType != null) { string str1 = EdmUtil.FullyQualifiedName(declaringType); if (str1 != null) { return(string.Concat(str1, "/", edmProperty.Name)); } } } return(null); } else { IEdmFunctionImport edmFunctionImport = edmEntityContainerElement as IEdmFunctionImport; if (edmFunctionImport == null) { return(string.Concat(edmEntityContainerElement.Container.FullName(), "/", edmEntityContainerElement.Name)); } else { return(string.Concat(edmFunctionImport.Container.FullName(), "/", EdmUtil.ParameterizedName(edmFunctionImport))); } } } else { IEdmFunction edmFunction = edmSchemaElement as IEdmFunction; if (edmFunction == null) { return(edmSchemaElement.FullName()); } else { return(EdmUtil.ParameterizedName(edmFunction)); } } }