protected static void AssertBoolean(TypeUsage type) { Assert( TypeSemantics.IsPrimitiveType(type, PrimitiveTypeKind.Boolean), "Type Mismatch: Expected Boolean; found {0} instead", type.ToString()); }
protected static void AssertCollectionType(TypeUsage type) { Assert( TypeSemantics.IsCollectionType(type), "Type Mismatch: Expected Collection type: Found {0}", type.ToString()); }
internal static void AssertEdmType(TypeUsage typeUsage) { EdmType type = typeUsage.EdmType; if (TypeSemantics.IsCollectionType(typeUsage)) { AssertEdmType(TypeHelpers.GetElementTypeUsage(typeUsage)); } else if (TypeSemantics.IsStructuralType(typeUsage) && !Helper.IsComplexType(typeUsage.EdmType) && !Helper.IsEntityType(typeUsage.EdmType)) { foreach (EdmMember m in TypeHelpers.GetDeclaredStructuralMembers(typeUsage)) { AssertEdmType(m.TypeUsage); } } else if (TypeSemantics.IsPrimitiveType(typeUsage)) { PrimitiveType pType = type as PrimitiveType; if (null != pType) { if (pType.DataSpace != DataSpace.CSpace) { throw new NotSupportedException(String.Format(CultureInfo.InvariantCulture, "PrimitiveType must be CSpace '{0}'", typeUsage.ToString())); } } } }
// // Type Description // internal static string GetFullName(TypeUsage type) { return(type.ToString()); }
protected static void AssertCollectionType(TypeUsage type) { Assert( TypeSemantics.IsCollectionType(type), "Type Mismatch: Expected Collection type: Found {0}", type.ToString()); }
protected static void AssertBoolean(TypeUsage type) { Assert( TypeSemantics.IsPrimitiveType(type, PrimitiveTypeKind.Boolean), "Type Mismatch: Expected Boolean; found {0} instead", type.ToString()); }
private static void RequireCompatibleType( DbExpression from, RelationshipEndMember end, bool allowAllRelationshipsInSameTypeHierarchy) { TypeUsage typeUsage = end.TypeUsage; if (!TypeSemantics.IsReferenceType(typeUsage)) { typeUsage = TypeHelpers.CreateReferenceTypeUsage(TypeHelpers.GetEdmType <EntityType>(typeUsage)); } if (allowAllRelationshipsInSameTypeHierarchy) { if (TypeHelpers.GetCommonTypeUsage(typeUsage, from.ResultType) == null) { throw new ArgumentException(Strings.Cqt_RelNav_WrongSourceType((object)typeUsage.ToString()), nameof(from)); } } else if (!TypeSemantics.IsStructurallyEqualOrPromotableTo(from.ResultType.EdmType, typeUsage.EdmType)) { throw new ArgumentException(Strings.Cqt_RelNav_WrongSourceType((object)typeUsage.ToString()), nameof(from)); } }
private static List <TypeUsage> GetStructuralMemberTypes(TypeUsage instanceType) { StructuralType edmType = instanceType.EdmType as StructuralType; if (edmType == null) { throw new ArgumentException(Strings.Cqt_NewInstance_StructuralTypeRequired, nameof(instanceType)); } if (edmType.Abstract) { throw new ArgumentException(Strings.Cqt_NewInstance_CannotInstantiateAbstractType((object)instanceType.ToString()), nameof(instanceType)); } IBaseList <EdmMember> structuralMembers = TypeHelpers.GetAllStructuralMembers((EdmType)edmType); if (structuralMembers == null || structuralMembers.Count < 1) { throw new ArgumentException(Strings.Cqt_NewInstance_CannotInstantiateMemberlessType((object)instanceType.ToString()), nameof(instanceType)); } List <TypeUsage> typeUsageList = new List <TypeUsage>(structuralMembers.Count); for (int index = 0; index < structuralMembers.Count; ++index) { typeUsageList.Add(Helper.GetModelTypeUsage(structuralMembers[index])); } return(typeUsageList); }
private static void RequireCompatibleType( DbExpression expression, TypeUsage requiredResultType, string argumentName, int argumentIndex) { if (!TypeSemantics.IsStructurallyEqualOrPromotableTo(expression.ResultType, requiredResultType)) { if (argumentIndex != -1) { argumentName = StringUtil.FormatIndex(argumentName, argumentIndex); } throw new ArgumentException(Strings.Cqt_ExpressionLink_TypeMismatch((object)expression.ResultType.ToString(), (object)requiredResultType.ToString()), argumentName); } }
internal static void ValidateConstant(TypeUsage constantType, object value) { ArgumentValidation.CheckType(constantType, nameof(constantType)); EnumType type1; if (TypeHelpers.TryGetEdmType <EnumType>(constantType, out type1)) { Type clrEquivalentType = type1.UnderlyingType.ClrEquivalentType; if (clrEquivalentType != value.GetType() && (!value.GetType().IsEnum() || !ArgumentValidation.ClrEdmEnumTypesMatch(type1, value.GetType()))) { throw new ArgumentException(Strings.Cqt_Constant_ClrEnumTypeDoesNotMatchEdmEnumType((object)value.GetType().Name, (object)type1.Name, (object)clrEquivalentType.Name), nameof(value)); } } else { PrimitiveType type2; if (!TypeHelpers.TryGetEdmType <PrimitiveType>(constantType, out type2)) { throw new ArgumentException(Strings.Cqt_Constant_InvalidConstantType((object)constantType.ToString()), nameof(constantType)); } PrimitiveTypeKind primitiveTypeKind; if ((!ArgumentValidation.TryGetPrimitiveTypeKind(value.GetType(), out primitiveTypeKind) || type2.PrimitiveTypeKind != primitiveTypeKind) && (!Helper.IsGeographicType(type2) || primitiveTypeKind != PrimitiveTypeKind.Geography) && (!Helper.IsGeometricType(type2) || primitiveTypeKind != PrimitiveTypeKind.Geometry)) { throw new ArgumentException(Strings.Cqt_Constant_InvalidValueForType((object)constantType.ToString()), nameof(value)); } } }
internal static void RequirePolymorphicType(TypeUsage type) { if (!TypeSemantics.IsPolymorphicType(type)) { throw new ArgumentException(Strings.Cqt_General_PolymorphicTypeRequired((object)type.ToString()), nameof(type)); } }