Exemple #1
0
        public void ParseIsOfExpressionWorksAsExpected()
        {
            string json = @" { ""$IsOf"": {
     ""$Path"": ""FirstName""
  },
   ""$Type"": ""self.PreferredCustomer"",
   ""$Collection"": true
}";

            CsdlExpressionBase expressionBase = ParseExpression(json);

            Assert.NotNull(expressionBase);
            CsdlIsTypeExpression isTypeExp = Assert.IsType <CsdlIsTypeExpression>(expressionBase);

            Assert.NotNull(isTypeExp.Type);
            CsdlExpressionTypeReference expTypeReference = Assert.IsType <CsdlExpressionTypeReference>(isTypeExp.Type);
            CsdlCollectionType          collectionType   = Assert.IsType <CsdlCollectionType>(expTypeReference.TypeExpression);
            CsdlNamedTypeReference      namedType        = Assert.IsType <CsdlNamedTypeReference>(collectionType.ElementType);

            Assert.Equal("self.PreferredCustomer", namedType.FullName);

            Assert.NotNull(isTypeExp.Operand);
            Assert.IsType <CsdlPathExpression>(isTypeExp.Operand);
        }
 public CsdlSemanticsCollectionTypeDefinition(CsdlSemanticsSchema schema, CsdlCollectionType collection)
     : base(collection)
 {
     this.collection = collection;
     this.schema     = schema;
 }
        internal static IEdmTypeReference WrapTypeReference(CsdlSemanticsSchema schema, CsdlTypeReference type)
        {
            CsdlNamedTypeReference reference = type as CsdlNamedTypeReference;

            if (reference != null)
            {
                CsdlPrimitiveTypeReference reference2 = reference as CsdlPrimitiveTypeReference;
                if (reference2 != null)
                {
                    switch (reference2.Kind)
                    {
                    case EdmPrimitiveTypeKind.Binary:
                        return(new CsdlSemanticsBinaryTypeReference(schema, (CsdlBinaryTypeReference)reference2));

                    case EdmPrimitiveTypeKind.Boolean:
                    case EdmPrimitiveTypeKind.Byte:
                    case EdmPrimitiveTypeKind.Double:
                    case EdmPrimitiveTypeKind.Guid:
                    case EdmPrimitiveTypeKind.Int16:
                    case EdmPrimitiveTypeKind.Int32:
                    case EdmPrimitiveTypeKind.Int64:
                    case EdmPrimitiveTypeKind.SByte:
                    case EdmPrimitiveTypeKind.Single:
                    case EdmPrimitiveTypeKind.Stream:
                        return(new CsdlSemanticsPrimitiveTypeReference(schema, reference2));

                    case EdmPrimitiveTypeKind.DateTime:
                    case EdmPrimitiveTypeKind.DateTimeOffset:
                    case EdmPrimitiveTypeKind.Time:
                        return(new CsdlSemanticsTemporalTypeReference(schema, (CsdlTemporalTypeReference)reference2));

                    case EdmPrimitiveTypeKind.Decimal:
                        return(new CsdlSemanticsDecimalTypeReference(schema, (CsdlDecimalTypeReference)reference2));

                    case EdmPrimitiveTypeKind.String:
                        return(new CsdlSemanticsStringTypeReference(schema, (CsdlStringTypeReference)reference2));

                    case EdmPrimitiveTypeKind.Geography:
                    case EdmPrimitiveTypeKind.GeographyPoint:
                    case EdmPrimitiveTypeKind.GeographyLineString:
                    case EdmPrimitiveTypeKind.GeographyPolygon:
                    case EdmPrimitiveTypeKind.GeographyCollection:
                    case EdmPrimitiveTypeKind.GeographyMultiPolygon:
                    case EdmPrimitiveTypeKind.GeographyMultiLineString:
                    case EdmPrimitiveTypeKind.GeographyMultiPoint:
                    case EdmPrimitiveTypeKind.Geometry:
                    case EdmPrimitiveTypeKind.GeometryPoint:
                    case EdmPrimitiveTypeKind.GeometryLineString:
                    case EdmPrimitiveTypeKind.GeometryPolygon:
                    case EdmPrimitiveTypeKind.GeometryCollection:
                    case EdmPrimitiveTypeKind.GeometryMultiPolygon:
                    case EdmPrimitiveTypeKind.GeometryMultiLineString:
                    case EdmPrimitiveTypeKind.GeometryMultiPoint:
                        return(new CsdlSemanticsSpatialTypeReference(schema, (CsdlSpatialTypeReference)reference2));
                    }
                }
                return(new CsdlSemanticsNamedTypeReference(schema, reference));
            }
            CsdlExpressionTypeReference expressionUsage = type as CsdlExpressionTypeReference;

            if (expressionUsage != null)
            {
                CsdlRowType typeExpression = expressionUsage.TypeExpression as CsdlRowType;
                if (typeExpression != null)
                {
                    return(new CsdlSemanticsRowTypeExpression(expressionUsage, new CsdlSemanticsRowTypeDefinition(schema, typeExpression)));
                }
                CsdlCollectionType collection = expressionUsage.TypeExpression as CsdlCollectionType;
                if (collection != null)
                {
                    return(new CsdlSemanticsCollectionTypeExpression(expressionUsage, new CsdlSemanticsCollectionTypeDefinition(schema, collection)));
                }
                CsdlEntityReferenceType entityTypeReference = expressionUsage.TypeExpression as CsdlEntityReferenceType;
                if (entityTypeReference != null)
                {
                    return(new CsdlSemanticsEntityReferenceTypeExpression(expressionUsage, new CsdlSemanticsEntityReferenceTypeDefinition(schema, entityTypeReference)));
                }
            }
            return(null);
        }
 public CsdlSemanticsCollectionTypeDefinition(CsdlSemanticsSchema schema, CsdlCollectionType collection) : base(collection)
 {
     this.elementTypeCache = new Cache <CsdlSemanticsCollectionTypeDefinition, IEdmTypeReference>();
     this.collection       = collection;
     this.schema           = schema;
 }