public void ProcessType(IEdmPathType pathType, bool inCollection) { string kind = ""; string primitiveTemplate = null; switch (pathType.PathKind) { case EdmPathTypeKind.PropertyPath: kind = "PropertyPath"; primitiveTemplate = "PropertyPathValue"; break; case EdmPathTypeKind.AnnotationPath: kind = "AnnotationPath"; primitiveTemplate = "Supplier/@Communication.Contact"; break; case EdmPathTypeKind.NavigationPropertyPath: kind = "NavigationPropertyPath"; primitiveTemplate = "NavigationPropertyPathValue"; break; } WriteStringValueTemplate(kind, primitiveTemplate, inCollection); }
public void TestCapabilitiesVocabularyExpandRestrictions() { var expandTerm = this.capVocModel.FindDeclaredTerm("Org.OData.Capabilities.V1.ExpandRestrictions"); Assert.NotNull(expandTerm); Assert.Equal("Org.OData.Capabilities.V1", expandTerm.Namespace); Assert.Equal("ExpandRestrictions", expandTerm.Name); var type = expandTerm.Type; Assert.Equal("Org.OData.Capabilities.V1.ExpandRestrictionsType", type.FullName()); Assert.Equal(EdmTypeKind.Complex, type.Definition.TypeKind); var complexType = type.Definition as IEdmComplexType; Assert.NotNull(complexType); var p = complexType.FindProperty("Expandable"); Assert.NotNull(p); Assert.Equal(EdmPrimitiveTypeKind.Boolean, p.Type.PrimitiveKind()); p = complexType.FindProperty("NonExpandableProperties"); Assert.NotNull(p); Assert.Equal(EdmTypeKind.Collection, p.Type.Definition.TypeKind); Assert.Equal(EdmTypeKind.Path, p.Type.AsCollection().ElementType().TypeKind()); IEdmPathType pathType = p.Type.AsCollection().ElementType().AsPath().Definition as IEdmPathType; Assert.NotNull(pathType); Assert.Equal("NavigationPropertyPath", pathType.Name); Assert.Equal("Edm", pathType.Namespace); Assert.Equal("Edm.NavigationPropertyPath", pathType.FullName()); }
private static CsdlExpressionBase AdjustStringConstantUsingTermType(CsdlExpressionBase expression, IEdmTypeReference termType) { if (expression == null || termType == null) { return(expression); } switch (expression.ExpressionKind) { case EdmExpressionKind.Collection: if (termType.IsCollection()) { IEdmTypeReference elementType = termType.AsCollection().ElementType(); IList <CsdlExpressionBase> newElements = new List <CsdlExpressionBase>(); CsdlCollectionExpression collectionExp = (CsdlCollectionExpression)expression; foreach (CsdlExpressionBase exp in collectionExp.ElementValues) { if (exp != null && exp.ExpressionKind == EdmExpressionKind.StringConstant) { newElements.Add(AdjustStringConstantUsingTermType(exp, elementType)); } else { newElements.Add(exp); } } return(new CsdlCollectionExpression(collectionExp.Type, newElements, collectionExp.Location as CsdlLocation)); } break; case EdmExpressionKind.StringConstant: CsdlConstantExpression constantExp = (CsdlConstantExpression)expression; switch (termType.TypeKind()) { case EdmTypeKind.Primitive: IEdmPrimitiveTypeReference primitiveTypeReference = (IEdmPrimitiveTypeReference)termType; return(BuildPrimitiveExpression(primitiveTypeReference, constantExp)); case EdmTypeKind.Path: IEdmPathType pathType = (IEdmPathType)termType.Definition; return(BuildPathExpression(pathType, constantExp)); case EdmTypeKind.Enum: IEdmEnumType enumType = (IEdmEnumType)termType.Definition; return(BuildEnumExpression(enumType, constantExp)); } break; } return(expression); }
/// <summary> /// Gets a reference to a path type of the specified kind. /// </summary> /// <param name="kind">Primitive kind of the type reference being created.</param> /// <param name="isNullable">Flag specifying if the referenced type should be nullable.</param> /// <returns>A new primitive type reference.</returns> public IEdmPathTypeReference GetPathType(EdmPathTypeKind kind, bool isNullable) { IEdmPathType pathDefinition = this.GetPathType(kind); if (pathDefinition != null) { return(new EdmPathTypeReference(pathDefinition, isNullable)); } else { throw new InvalidOperationException(Edm.Strings.EdmPath_UnexpectedKind); } }
public void BuildEdmExpression_Works_ForPropertyPathValue() { // Arrange IEdmPathType pathType = EdmCoreModel.Instance.GetPathType(EdmPathTypeKind.PropertyPath); // Act IEdmExpression exp = IEdmTermExtensions.BuildEdmExpression(pathType, "HomeAddress/City"); // Assert Assert.NotNull(exp); EdmPropertyPathExpression constant = Assert.IsType <EdmPropertyPathExpression>(exp); Assert.Equal("HomeAddress/City", constant.Path); }
private void VisitPathType(IEdmPathTypeReference pathReference) { string qualifiedName = pathReference.FullName(); if (_types.ContainsKey(qualifiedName)) { return; } IEdmPathType primitiveType = (IEdmPathType)(pathReference.Definition); MetaPrimitiveType metaPrimitiveType = new MetaPrimitiveType(); metaPrimitiveType.QualifiedName = qualifiedName; metaPrimitiveType.Name = primitiveType.Name; _types[qualifiedName] = metaPrimitiveType; }
private static CsdlExpressionBase BuildPathExpression(IEdmPathType pathType, CsdlConstantExpression expression) { Debug.Assert(expression.ExpressionKind == EdmExpressionKind.StringConstant); CsdlLocation location = expression.Location as CsdlLocation; switch (pathType.PathKind) { case EdmPathTypeKind.AnnotationPath: return(new CsdlAnnotationPathExpression(expression.Value, location)); case EdmPathTypeKind.PropertyPath: return(new CsdlPropertyPathExpression(expression.Value, location)); case EdmPathTypeKind.NavigationPropertyPath: return(new CsdlNavigationPropertyPathExpression(expression.Value, location)); case EdmPathTypeKind.None: default: return(expression); } }
/// <summary> /// Constructor /// </summary> /// <param name="definition">IEdmPathType definition.</param> /// <param name="isNullable">nullable or not.</param> public EdmPathTypeReference(IEdmPathType definition, bool isNullable) : base(definition, isNullable) { }