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


C# IEdmTypeReference.IsStructured方法代码示例

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


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

示例1: TryCastRecordAsType

        internal static bool TryCastRecordAsType(this IEdmRecordExpression expression, IEdmTypeReference type, IEdmType context, bool matchExactly, out IEnumerable<EdmError> discoveredErrors)
        {
            EdmUtil.CheckArgumentNull(expression, "expression");
            EdmUtil.CheckArgumentNull(type, "type");

            if (!type.IsStructured())
            {
                discoveredErrors = new EdmError[] { new EdmError(expression.Location(), EdmErrorCode.RecordExpressionNotValidForNonStructuredType, Edm.Strings.EdmModel_Validator_Semantic_RecordExpressionNotValidForNonStructuredType) };
                return false;
            }

            HashSetInternal<string> foundProperties = new HashSetInternal<string>();
            List<EdmError> errors = new List<EdmError>();

            IEdmStructuredTypeReference structuredType = type.AsStructured();
            foreach (IEdmProperty typeProperty in structuredType.StructuredDefinition().Properties())
            {
                IEdmPropertyConstructor expressionProperty = expression.Properties.FirstOrDefault(p => p.Name == typeProperty.Name);
                if (expressionProperty == null)
                {
                    errors.Add(new EdmError(expression.Location(), EdmErrorCode.RecordExpressionMissingRequiredProperty, Edm.Strings.EdmModel_Validator_Semantic_RecordExpressionMissingProperty(typeProperty.Name)));
                }
                else
                {
                    IEnumerable<EdmError> recursiveErrors;
                    if (!expressionProperty.Value.TryCast(typeProperty.Type, context, matchExactly, out recursiveErrors))
                    {
                        foreach (EdmError error in recursiveErrors)
                        {
                            errors.Add(error);
                        }
                    }

                    foundProperties.Add(typeProperty.Name);
                }
            }

            if (!structuredType.IsOpen())
            {
                foreach (IEdmPropertyConstructor property in expression.Properties)
                {
                    if (!foundProperties.Contains(property.Name))
                    {
                        errors.Add(new EdmError(expression.Location(), EdmErrorCode.RecordExpressionHasExtraProperties, Edm.Strings.EdmModel_Validator_Semantic_RecordExpressionHasExtraProperties(property.Name)));
                    }
                }
            }

            if (errors.FirstOrDefault() != null)
            {
                discoveredErrors = errors;
                return false;
            }

            discoveredErrors = Enumerable.Empty<EdmError>();
            return true;
        }
开发者ID:larsenjo,项目名称:odata.net,代码行数:57,代码来源:ExpressionTypeChecker.cs

示例2: ConvertToEdmValue

        /// <summary>
        /// Converts a clr value to an edm value.
        /// </summary>
        /// <param name="propertyValue">The property value.</param>
        /// <param name="edmPropertyType">Type of the property.</param>
        /// <returns>
        /// The converted value
        /// </returns>
        private IEdmValue ConvertToEdmValue(object propertyValue, IEdmTypeReference edmPropertyType)
        {
            Debug.Assert(edmPropertyType != null, "edmPropertyType != null");

            if (propertyValue == null)
            {
                return EdmNullExpression.Instance;
            }

            if (edmPropertyType.IsStructured())
            {
                var actualEdmTypeReference = this.model.GetClientTypeAnnotation(propertyValue.GetType());
                if (actualEdmTypeReference != null && actualEdmTypeReference.EdmTypeReference.Definition.IsOrInheritsFrom(edmPropertyType.Definition))
                {
                    return new ClientEdmStructuredValue(propertyValue, this.model, actualEdmTypeReference);
                }
                else
                {
                    return new ClientEdmStructuredValue(propertyValue, this.model, this.model.GetClientTypeAnnotation(edmPropertyType.Definition));
                }
            }

            if (edmPropertyType.IsCollection())
            {
                var collectionType = edmPropertyType as IEdmCollectionTypeReference;
                Debug.Assert(collectionType != null, "collectionType != null");
                var elements = ((IEnumerable)propertyValue).Cast<object>().Select(v => this.ConvertToEdmValue(v, collectionType.ElementType()));
                return new ClientEdmCollectionValue(collectionType, elements);
            }

            if (edmPropertyType.IsEnum())
            {
                // Need to handle underlying type(Int16, Int32, Int64)
                return new EdmEnumValue(edmPropertyType as IEdmEnumTypeReference, new EdmIntegerConstant(Convert.ToInt64(propertyValue, CultureInfo.InvariantCulture)));
            }

            var primitiveType = edmPropertyType as IEdmPrimitiveTypeReference;
            Debug.Assert(primitiveType != null, "Type was not structured, collection, or primitive");

            return EdmValueUtils.ConvertPrimitiveValue(propertyValue, primitiveType).Value;
        }
开发者ID:larsenjo,项目名称:odata.net,代码行数:49,代码来源:ClientEdmStructuredValue.cs

示例3: TryHandleEqualityOperatorForEntityOrComplexTypes

        /// <summary>
        /// Tries to handle the special eq and ne operators, which have a broader definition than the other binary operators.
        /// We try a few special cases and return true if we used one of them. Otherwise we return false, and
        /// allow the regular function matching code to handle the primitive cases.
        /// </summary>
        /// <param name="left">Left type.</param>
        /// <param name="right">Right type.</param>
        /// <returns>True if this function was able to handle the promotion of these types, false otherwise.</returns>
        private static bool TryHandleEqualityOperatorForEntityOrComplexTypes(ref IEdmTypeReference left, ref IEdmTypeReference right)
        {
            if (left != null && left.IsStructured())
            {
                // When one is null and the other isn't, we use the other's type for the null one
                if (right == null)
                {
                    right = left;
                    return true;
                }

                // When one is structured but the other primitive, there is no match
                if (!right.IsStructured())
                {
                    return false;
                }

                // If they are the same type but have different nullability, we need to choose the nullable one for both
                if (left.Definition.IsEquivalentTo(right.Definition))
                {
                    if (left.IsNullable && !right.IsNullable)
                    {
                        right = left;
                    }
                    else
                    {
                        left = right;
                    }

                    return true;
                }

                // I think we should just use IsAssignableFrom instead now
                if (CanConvertTo(null, left, right))
                {
                    left = right;
                    return true;
                }

                if (CanConvertTo(null, right, left))
                {
                    right = left;
                    return true;
                }

                return false;
            }

            // Left was null or primitive
            if (right != null && (right.IsStructured()))
            {
                if (left == null)
                {
                    left = right;
                    return true;
                }

                return false;
            }

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

示例4: TryAssertRecordAsType

		internal static bool TryAssertRecordAsType(this IEdmRecordExpression expression, IEdmTypeReference type, out IEnumerable<EdmError> discoveredErrors)
		{
			IEnumerable<EdmError> edmErrors = null;
			EdmUtil.CheckArgumentNull<IEdmRecordExpression>(expression, "expression");
			EdmUtil.CheckArgumentNull<IEdmTypeReference>(type, "type");
			if (type.IsStructured())
			{
				HashSetInternal<string> strs = new HashSetInternal<string>();
				List<EdmError> edmErrors1 = new List<EdmError>();
				IEdmStructuredTypeReference edmStructuredTypeReference = type.AsStructured();
				IEnumerator<IEdmProperty> enumerator = edmStructuredTypeReference.StructuredDefinition().Properties().GetEnumerator();
				using (enumerator)
				{
					Func<IEdmPropertyConstructor, bool> func = null;
					while (enumerator.MoveNext())
					{
						IEdmProperty current = enumerator.Current;
						IEnumerable<IEdmPropertyConstructor> properties = expression.Properties;
						if (func == null)
						{
							func = (IEdmPropertyConstructor p) => p.Name == current.Name;
						}
						IEdmPropertyConstructor edmPropertyConstructor = properties.FirstOrDefault<IEdmPropertyConstructor>(func);
						if (edmPropertyConstructor != null)
						{
							if (!edmPropertyConstructor.Value.TryAssertType(current.Type, out edmErrors))
							{
								IEnumerator<EdmError> enumerator1 = edmErrors.GetEnumerator();
								using (enumerator1)
								{
									while (enumerator1.MoveNext())
									{
										EdmError edmError = enumerator1.Current;
										edmErrors1.Add(edmError);
									}
								}
							}
							strs.Add(current.Name);
						}
						else
						{
							edmErrors1.Add(new EdmError(expression.Location(), EdmErrorCode.RecordExpressionMissingRequiredProperty, Strings.EdmModel_Validator_Semantic_RecordExpressionMissingProperty(current.Name)));
						}
					}
				}
				if (!edmStructuredTypeReference.IsOpen())
				{
					foreach (IEdmPropertyConstructor property in expression.Properties)
					{
						if (strs.Contains(property.Name))
						{
							continue;
						}
						edmErrors1.Add(new EdmError(expression.Location(), EdmErrorCode.RecordExpressionHasExtraProperties, Strings.EdmModel_Validator_Semantic_RecordExpressionHasExtraProperties(property.Name)));
					}
				}
				if (edmErrors1.FirstOrDefault<EdmError>() == null)
				{
					discoveredErrors = Enumerable.Empty<EdmError>();
					return true;
				}
				else
				{
					discoveredErrors = edmErrors1;
					return false;
				}
			}
			else
			{
				EdmError[] edmErrorArray = new EdmError[1];
				edmErrorArray[0] = new EdmError(expression.Location(), EdmErrorCode.RecordExpressionNotValidForNonStructuredType, Strings.EdmModel_Validator_Semantic_RecordExpressionNotValidForNonStructuredType);
				discoveredErrors = edmErrorArray;
				return false;
			}
		}
开发者ID:nickchal,项目名称:pash,代码行数:75,代码来源:ExpressionTypeChecker.cs


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