当前位置: 首页>>代码示例>>C#>>正文


C# IEdmTypeReference.IsEquivalentTo方法代码示例

本文整理汇总了C#中IEdmTypeReference.IsEquivalentTo方法的典型用法代码示例。如果您正苦于以下问题:C# IEdmTypeReference.IsEquivalentTo方法的具体用法?C# IEdmTypeReference.IsEquivalentTo怎么用?C# IEdmTypeReference.IsEquivalentTo使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在IEdmTypeReference的用法示例。


在下文中一共展示了IEdmTypeReference.IsEquivalentTo方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: CanConvertTo

 internal static bool CanConvertTo(IEdmTypeReference sourceReference, IEdmTypeReference targetReference)
 {
     if (sourceReference.IsEquivalentTo(targetReference))
     {
         return true;
     }
     if (targetReference.IsODataComplexTypeKind() || targetReference.IsODataEntityTypeKind())
     {
         return ((IEdmStructuredType) targetReference.Definition).IsAssignableFrom(((IEdmStructuredType) sourceReference.Definition));
     }
     if (IsOpenPropertyType(targetReference))
     {
         return true;
     }
     IEdmPrimitiveTypeReference type = sourceReference.AsPrimitiveOrNull();
     IEdmPrimitiveTypeReference reference2 = targetReference.AsPrimitiveOrNull();
     return (((type != null) && (reference2 != null)) && MetadataUtilsCommon.CanConvertPrimitiveTypeTo(type.PrimitiveDefinition(), reference2.PrimitiveDefinition()));
 }
开发者ID:nickchal,项目名称:pash,代码行数:18,代码来源:TypePromotionUtils.cs

示例2: CompareConversions

        /// <summary>Checks which conversion is better.</summary>
        /// <param name="source">Source type.</param>
        /// <param name="targetA">First candidate type to convert to.</param>
        /// <param name="targetB">Second candidate type to convert to.</param>
        /// <returns>
        /// Return 1 if s -> t1 is a better conversion than s -> t2
        /// Return -1 if s -> t2 is a better conversion than s -> t1
        /// Return 0 if neither conversion is better
        /// </returns>
        private static int CompareConversions(IEdmTypeReference source, IEdmTypeReference targetA, IEdmTypeReference targetB)
        {
            // If both types are exactly the same, there is no preference.
            if (targetA.IsEquivalentTo(targetB))
            {
                return 0;
            }

            // Look for exact matches.
            if (source.IsEquivalentTo(targetA))
            {
                return 1;
            }

            if (source.IsEquivalentTo(targetB))
            {
                return -1;
            }

            // If one is compatible and the other is not, choose the compatible type.
            bool compatibleT1AndT2 = CanConvertTo(null, targetA, targetB);
            bool compatibleT2AndT1 = CanConvertTo(null, targetB, targetA);
            if (compatibleT1AndT2 && !compatibleT2AndT1)
            {
                return 1;
            }

            if (compatibleT2AndT1 && !compatibleT1AndT2)
            {
                return -1;
            }

            // Prefer to keep the original nullability.
            bool sourceNullable = source.IsNullable;
            bool typeNullableA = targetA.IsNullable;
            bool typeNullableB = targetB.IsNullable;
            if (sourceNullable == typeNullableA && sourceNullable != typeNullableB)
            {
                return 1;
            }

            if (sourceNullable != typeNullableA && sourceNullable == typeNullableB)
            {
                return -1;
            }

            // Prefer signed to unsigned.
            if (IsSignedIntegralType(targetA) && IsUnsignedIntegralType(targetB))
            {
                return 1;
            }

            if (IsSignedIntegralType(targetB) && IsUnsignedIntegralType(targetA))
            {
                return -1;
            }

            // If both decimal and double are possible or if both decimal and single are possible, then single/double is prefered (int32->long->single->double->decimal).
            if (IsDecimalType(targetA) && IsDoubleOrSingle(targetB))
            {
                return -1;
            }

            if (IsDecimalType(targetB) && IsDoubleOrSingle(targetA))
            {
                return 1;
            }

            // If both DateTimeOffset and Date are possible, then DateTimeOffset is perfered, as to keep previous behaviour.
            if (IsDateTimeOffset(targetA) && IsDate(targetB))
            {
                return 1;
            }

            if (IsDateTimeOffset(targetB) && IsDate(targetA))
            {
                return -1;
            }

            return 0;
        }
开发者ID:larsenjo,项目名称:odata.net,代码行数:90,代码来源:TypePromotionUtils.cs

示例3: CanPromoteNodeTo

        /// <summary>Promotes the specified expression to the given type if necessary.</summary>
        /// <param name="sourceNodeOrNull">The actual argument node, may be null.</param>
        /// <param name="sourceType">The actual argument type.</param>
        /// <param name="targetType">The required type to promote to.</param>
        /// <returns>True if the <paramref name="sourceType"/> could be promoted; otherwise false.</returns>
        private static bool CanPromoteNodeTo(SingleValueNode sourceNodeOrNull, IEdmTypeReference sourceType, IEdmTypeReference targetType)
        {
            Debug.Assert(targetType != null, "targetType != null");
            Debug.Assert(targetType.IsODataPrimitiveTypeKind(), "Type promotion only supported for primitive types.");

            if (sourceType == null)
            {
                // This indicates that a null literal or an open type has been specified.
                // For either case we can promote to the required target type if it is nullable
                return targetType.IsNullable;
            }

            if (sourceType.IsEquivalentTo(targetType))
            {
                return true;
            }

            if (CanConvertTo(sourceNodeOrNull, sourceType, targetType))
            {
                return true;
            }

            // Allow promotion from nullable<T> to non-nullable by directly accessing underlying value.
            if (sourceType.IsNullable && targetType.IsODataValueType())
            {
                // COMPAT 40: Type promotion in the product allows promotion from a nullable type to arbitrary value types
                IEdmTypeReference nonNullableSourceType = sourceType.Definition.ToTypeReference(false);
                if (CanConvertTo(sourceNodeOrNull, nonNullableSourceType, targetType))
                {
                    return true;
                }
            }

            return false;
        }
开发者ID:larsenjo,项目名称:odata.net,代码行数:40,代码来源:TypePromotionUtils.cs

示例4: CanConvertTo

        internal static bool CanConvertTo(SingleValueNode sourceNodeOrNull, IEdmTypeReference sourceReference, IEdmTypeReference targetReference)
        {
            Debug.Assert(sourceReference != null, "sourceReference != null");
            Debug.Assert(targetReference != null, "targetReference != null");

            //// Copy of the ResourceQueryParser.ExpressionParser.IsCompatibleWith method.

            if (sourceReference.IsEquivalentTo(targetReference))
            {
                return true;
            }

            if (targetReference.IsODataComplexTypeKind() || targetReference.IsODataEntityTypeKind())
            {
                // for structured types, use IsAssignableFrom
                return EdmLibraryExtensions.IsAssignableFrom(
                    (IEdmStructuredType)targetReference.Definition,
                    (IEdmStructuredType)sourceReference.Definition);
            }

            //// This rule stops the parser from considering nullable types as incompatible
            //// with non-nullable types. We have however implemented this rule because we just
            //// access underlying rules. C# requires an explicit .Value access, and EDM has no
            //// nullablity on types and (at the model level) implements null propagation.
            ////
            //// if (sourceReference.IsNullable && !targetReference.IsNullable)
            //// {
            ////     return false;
            //// }

            if (sourceReference.IsEnum() && targetReference.IsEnum())
            {
                if (sourceReference.Definition.IsEquivalentTo(targetReference.Definition))
                {
                    return targetReference.IsNullable() || (!sourceReference.IsNullable());
                }

                return false;
            }

            IEdmPrimitiveTypeReference sourcePrimitiveTypeReference = sourceReference.AsPrimitiveOrNull();
            IEdmPrimitiveTypeReference targetPrimitiveTypeReference = targetReference.AsPrimitiveOrNull();

            if (sourcePrimitiveTypeReference == null || targetPrimitiveTypeReference == null)
            {
                return false;
            }

            return MetadataUtilsCommon.CanConvertPrimitiveTypeTo(sourceNodeOrNull, sourcePrimitiveTypeReference.PrimitiveDefinition(), targetPrimitiveTypeReference.PrimitiveDefinition());
        }
开发者ID:larsenjo,项目名称:odata.net,代码行数:50,代码来源:TypePromotionUtils.cs

示例5: CompareConversions

        /// <summary>Checks which conversion is better.</summary>
        /// <param name="source">Source type.</param>
        /// <param name="targetA">First candidate type to convert to.</param>
        /// <param name="targetB">Second candidate type to convert to.</param>
        /// <returns>
        /// Return 1 if s -> t1 is a better conversion than s -> t2
        /// Return -1 if s -> t2 is a better conversion than s -> t1
        /// Return 0 if neither conversion is better
        /// </returns>
        private static int CompareConversions(IEdmTypeReference source, IEdmTypeReference targetA, IEdmTypeReference targetB)
        {
            // If both types are exactly the same, there is no preference.
            if (targetA.IsEquivalentTo(targetB))
            {
                return 0;
            }

            // Look for exact matches.
            if (source.IsEquivalentTo(targetA))
            {
                return 1;
            }

            if (source.IsEquivalentTo(targetB))
            {
                return -1;
            }

            // If one is compatible and the other is not, choose the compatible type.
            bool compatibleT1AndT2 = CanConvertTo(targetA, targetB);
            bool compatibleT2AndT1 = CanConvertTo(targetB, targetA);
            if (compatibleT1AndT2 && !compatibleT2AndT1)
            {
                return 1;
            }

            if (compatibleT2AndT1 && !compatibleT1AndT2)
            {
                return -1;
            }

            // Prefer to keep the original nullability.
            bool sourceNullable = source.IsNullable;
            bool typeNullableA = targetA.IsNullable;
            bool typeNullableB = targetB.IsNullable;
            if (sourceNullable == typeNullableA && sourceNullable != typeNullableB)
            {
                return 1;
            }

            if (sourceNullable != typeNullableA && sourceNullable == typeNullableB)
            {
                return -1;
            }

            // Prefer signed to unsigned.
            if (IsSignedIntegralType(targetA) && IsUnsignedIntegralType(targetB))
            {
                return 1;
            }

            if (IsSignedIntegralType(targetB) && IsUnsignedIntegralType(targetA))
            {
                return -1;
            }

            // If both decimal and double are possible or if both decimal and single are possible, then prefer decimal
            // since double and single should only be targets for single and double source if decimal is available.
            // And since neither single not double convert to decimal, we don't need to handle that case here.
            if (IsDecimalType(targetA) && IsDoubleOrSingle(targetB))
            {
                return 1;
            }

            if (IsDecimalType(targetB) && IsDoubleOrSingle(targetA))
            {
                return -1;
            }

            // Prefer non-object to object.
            // TODO: this is how the product treats open properties (as object-typed). Left here for now
            //       but likely to have to change when we start supporting open properties (since our open
            //       properties are not object-typed).
            if (!IsOpenPropertyType(targetA) && IsOpenPropertyType(targetB))
            {
                return 1;
            }

            if (!IsOpenPropertyType(targetB) && IsOpenPropertyType(targetA))
            {
                return -1;
            }

            return 0;
        }
开发者ID:smasonuk,项目名称:odata-sparql,代码行数:95,代码来源:TypePromotionUtils.cs

示例6: VerifyTypesAreEqual

 public static void VerifyTypesAreEqual(IEdmTypeReference expected, IEdmTypeReference actual, AssertionHandler assert)
 {
     assert.IsTrue(expected.IsEquivalentTo(actual), "The expected and the actual types don't match.");
 }
开发者ID:AlineGuan,项目名称:odata.net,代码行数:4,代码来源:QueryTestUtils.cs

示例7: CanPromoteTo

        /// <summary>Promotes the specified expression to the given type if necessary.</summary>
        /// <param name="sourceType">The actual argument type.</param>
        /// <param name="targetType">The required type to promote to.</param>
        /// <returns>True if the <paramref name="sourceType"/> could be promoted; otherwise false.</returns>
        private static bool CanPromoteTo(IEdmTypeReference sourceType, IEdmTypeReference targetType)
        {
            Debug.Assert(targetType != null, "targetType != null");
            Debug.Assert(sourceType == null || sourceType.IsODataPrimitiveTypeKind(), "Type promotion only supported for primitive types.");
            Debug.Assert(targetType.IsODataPrimitiveTypeKind(), "Type promotion only supported for primitive types.");

            if (sourceType == null)
            {
                // This indicates that a null literal or an open type has been specified.
                // For null literals we can promote to the required target type if it is nullable
                // TODO: review this once open types are supported.
                return targetType.IsNullable;
            }

            if (sourceType.IsEquivalentTo(targetType))
            {
                return true;
            }

            if (CanConvertTo(sourceType, targetType))
            {
                return true;
            }

            // Allow promotion from nullable to non-nullable by directly accessing underlying value.
            if (sourceType.IsNullable && targetType.IsODataValueType())
            {
                IEdmTypeReference nonNullableSourceType = sourceType.Definition.ToTypeReference(false);
                if (CanConvertTo(nonNullableSourceType, targetType))
                {
                    return true;
                }
            }

            return false;
        }
开发者ID:smasonuk,项目名称:odata-sparql,代码行数:40,代码来源:TypePromotionUtils.cs

示例8: ParseUriStringToType

            public object ParseUriStringToType(string text, IEdmTypeReference targetType, out UriLiteralParsingException parsingException)
            {
                parsingException = null;
                if (!RegisteredTestCases.Exists(testCase => Environment.StackTrace.ToString().Contains(testCase)))
                {
                    return null;
                }

                if (!targetType.IsEquivalentTo(HeartbeatComplexType))
                {
                    return null;
                }
                if (text == null)
                {
                    return null;
                }

                // Take care of literals
                if (!text.StartsWith("myCustomHeartbeatTypePrefixLiteral"))
                {
                    return null;
                }

                text = text.Replace("myCustomHeartbeatTypePrefixLiteral", string.Empty);

                if (!UriParserHelper.IsUriValueQuoted(text))
                {
                    parsingException = new UriLiteralParsingException("Edm.Heartbeat value must be quoted");
                    return null;
                }

                text = UriParserHelper.RemoveQuotes(text);

                double textIntValue;
                // Simulates a bug in a client Parser
                if (double.TryParse(text, out textIntValue))
                {
                    return new HeatBeat() { Frequency = textIntValue };
                }

                return null;
            }
开发者ID:TomDu,项目名称:odata.net,代码行数:42,代码来源:CustomUriLiteralParserTests.cs


注:本文中的IEdmTypeReference.IsEquivalentTo方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。