コード例 #1
0
        public static bool IsEquivalentTo(this IEdmType thisType, IEdmType otherType)
        {
            if (thisType != otherType)
            {
                if (thisType == null || otherType == null)
                {
                    return(false);
                }
                else
                {
                    if (thisType.TypeKind == otherType.TypeKind)
                    {
                        EdmTypeKind typeKind = thisType.TypeKind;
                        switch (typeKind)
                        {
                        case EdmTypeKind.None:
                        {
                            return(otherType.TypeKind == EdmTypeKind.None);
                        }

                        case EdmTypeKind.Primitive:
                        {
                            return(thisType.IsEquivalentTo((IEdmPrimitiveType)otherType));
                        }

                        case EdmTypeKind.Entity:
                        case EdmTypeKind.Complex:
                        case EdmTypeKind.Enum:
                        {
                            return(thisType.IsEquivalentTo((IEdmSchemaType)otherType));
                        }

                        case EdmTypeKind.Row:
                        {
                            return(thisType.IsEquivalentTo((IEdmRowType)otherType));
                        }

                        case EdmTypeKind.Collection:
                        {
                            return(thisType.IsEquivalentTo((IEdmCollectionType)otherType));
                        }

                        case EdmTypeKind.EntityReference:
                        {
                            return(thisType.IsEquivalentTo((IEdmEntityReferenceType)otherType));
                        }
                        }
                        throw new InvalidOperationException(Strings.UnknownEnumVal_TypeKind(thisType.TypeKind));
                    }
                    else
                    {
                        return(false);
                    }
                }
            }
            else
            {
                return(true);
            }
        }
コード例 #2
0
        public OperationImportSegment(IEnumerable <IEdmOperationImport> operationImports, IEdmEntitySetBase entitySet)
            : this()
        {
            // DEVNOTE: This ctor is only used in Select and Expand currently.
            ExceptionUtils.CheckArgumentNotNull(operationImports, "operations");
            this.operationImports = new ReadOnlyCollection <IEdmOperationImport>(operationImports.ToList());

            // check for empty after we copy locally, so that we don't do multiple enumeration of input
            ExceptionUtils.CheckArgumentCollectionNotNullOrEmpty(this.operationImports, "operations");

            // Determine the return type of the operation. This is only possible if all the candidate operations agree on the return type.
            // TODO: Because we work on types and not type references, if there are nullability differences we'd ignore them...
            IEdmType typeSoFar = this.operationImports.First().Operation.ReturnType != null
                                     ? this.operationImports.First().Operation.ReturnType.Definition
                                     : null;

            if (typeSoFar == null)
            {
                // This is for void operations
                if (this.operationImports.Any(operation => operation.Operation.ReturnType != null))
                {
                    typeSoFar = UnknownSentinel;
                }
            }
            else if (this.operationImports.Any(operationImport => !typeSoFar.IsEquivalentTo(operationImport.Operation.ReturnType.Definition)))
            {
                typeSoFar = UnknownSentinel;
            }

            this.computedReturnEdmType = typeSoFar;
            this.entitySet             = entitySet;
            this.EnsureTypeAndSetAreCompatable();
        }
コード例 #3
0
 public static bool IsOrInheritsFrom(this IEdmType thisType, IEdmType otherType)
 {
     if (thisType == null || otherType == null)
     {
         return(false);
     }
     else
     {
         if (!thisType.IsEquivalentTo(otherType))
         {
             EdmTypeKind typeKind = thisType.TypeKind;
             if (typeKind != otherType.TypeKind || typeKind != EdmTypeKind.Entity && typeKind != EdmTypeKind.Complex && typeKind != EdmTypeKind.Row)
             {
                 return(false);
             }
             else
             {
                 return(thisType.IsOrInheritsFrom(otherType));
             }
         }
         else
         {
             return(true);
         }
     }
 }
コード例 #4
0
 public static AndConstraint <IEdmType> ShouldBeEquivalentTo(this IEdmType type, IEdmType expectedType)
 {
     type.IsEquivalentTo(expectedType).Should().BeTrue();
     ////typeReference.Should().BeSameAs(expectedTypeReference.Definition);
     ////typeReference.IsNullable.Should().Be(expectedTypeReference.IsNullable);
     return(new AndConstraint <IEdmType>(type));
 }
コード例 #5
0
ファイル: ExpressionTypeChecker.cs プロジェクト: tapika/swupd
        private static bool TestTypeMatch(this IEdmType expressionType, IEdmType assertedType, EdmLocation location, bool matchExactly, out IEnumerable <EdmError> discoveredErrors)
        {
            if (matchExactly)
            {
                if (!expressionType.IsEquivalentTo(assertedType))
                {
                    discoveredErrors = new EdmError[] { new EdmError(location, EdmErrorCode.ExpressionNotValidForTheAssertedType, Edm.Strings.EdmModel_Validator_Semantic_ExpressionNotValidForTheAssertedType) };
                    return(false);
                }
            }
            else
            {
                // A bad type matches anything (so as to avoid generating spurious errors).
                if (expressionType.TypeKind == EdmTypeKind.None || expressionType.IsBad())
                {
                    discoveredErrors = Enumerable.Empty <EdmError>();
                    return(true);
                }

                if (expressionType.TypeKind == EdmTypeKind.Primitive && assertedType.TypeKind == EdmTypeKind.Primitive)
                {
                    IEdmPrimitiveType primitiveExpressionType = expressionType as IEdmPrimitiveType;
                    IEdmPrimitiveType primitiveAssertedType   = assertedType as IEdmPrimitiveType;
                    if (!primitiveExpressionType.PrimitiveKind.PromotesTo(primitiveAssertedType.PrimitiveKind))
                    {
                        discoveredErrors = new EdmError[] { new EdmError(location, EdmErrorCode.ExpressionPrimitiveKindNotValidForAssertedType, Edm.Strings.EdmModel_Validator_Semantic_ExpressionPrimitiveKindCannotPromoteToAssertedType(expressionType.ToTraceString(), assertedType.ToTraceString())) };
                        return(false);
                    }
                }
                else
                {
                    if (!expressionType.IsOrInheritsFrom(assertedType))
                    {
                        discoveredErrors = new EdmError[] { new EdmError(location, EdmErrorCode.ExpressionNotValidForTheAssertedType, Edm.Strings.EdmModel_Validator_Semantic_ExpressionNotValidForTheAssertedType) };
                        return(false);
                    }
                }
            }

            discoveredErrors = Enumerable.Empty <EdmError>();
            return(true);
        }
コード例 #6
0
        /// <summary>
        /// Determines if a type is equivalent to or derived from another type.
        /// </summary>
        /// <param name="thisType">Type to be tested for equivalence to or derivation from the other type.</param>
        /// <param name="otherType">Type that is the other type.</param>
        /// <returns>True if and only if the thisType is equivalent to or inherits from otherType.</returns>
        public static bool IsOrInheritsFrom(this IEdmType thisType, IEdmType otherType)
        {
            if (thisType == null || otherType == null)
            {
                return(false);
            }

            if (thisType.IsEquivalentTo(otherType))
            {
                return(true);
            }

            EdmTypeKind thisKind = thisType.TypeKind;

            if (thisKind != otherType.TypeKind || !(thisKind == EdmTypeKind.Entity || thisKind == EdmTypeKind.Complex))
            {
                return(false);
            }

            return(((IEdmStructuredType)thisType).InheritsFrom((IEdmStructuredType)otherType));
        }