/// <summary> /// Get the OSpace type given the CSpace typename /// </summary> /// <param name="cspaceTypeName"> </param> /// <param name="ignoreCase"> </param> /// <param name="edmType"> </param> /// <returns> </returns> internal bool TryGetOSpaceType(EdmType cspaceType, out EdmType edmType) { Debug.Assert(DataSpace.CSpace == cspaceType.DataSpace, "DataSpace should be CSpace"); // check if there is an entity, complex type or enum type mapping with this name if (Helper.IsEntityType(cspaceType) || Helper.IsComplexType(cspaceType) || Helper.IsEnumType(cspaceType)) { return(_ocMapping.TryGetValue(cspaceType.Identity, out edmType)); } return(TryGetItem(cspaceType.Identity, out edmType)); }
protected override void LoadTypesFromAssembly() { foreach (var type in SourceAssembly.GetAccessibleTypes()) { EdmType cspaceType; if (TryGetCSpaceTypeMatch(type, out cspaceType)) { if (type.IsValueType && !type.IsEnum) { SessionData.LoadMessageLogger.LogLoadMessage( Strings.Validator_OSpace_Convention_Struct(cspaceType.FullName, type.FullName), cspaceType); continue; } EdmType ospaceType; if (TryCreateType(type, cspaceType, out ospaceType)) { Debug.Assert( ospaceType is StructuralType || Helper.IsEnumType(ospaceType), "Only StructuralType or EnumType expected."); CacheEntry.TypesInAssembly.Add(ospaceType); // check for duplicates so we don't cause an ArgumentException, // Mapping will do the actual error for the duplicate type later if (!SessionData.CspaceToOspace.ContainsKey(cspaceType)) { SessionData.CspaceToOspace.Add(cspaceType, ospaceType); } else { // at this point there is already a Clr Type that is structurally matched to this CSpace type, we throw exception var previousOSpaceType = SessionData.CspaceToOspace[cspaceType]; SessionData.EdmItemErrors.Add( new EdmItemError( Strings.Validator_OSpace_Convention_AmbiguousClrType( cspaceType.Name, previousOSpaceType.ClrType.FullName, type.FullName))); } } } } if (SessionData.TypesInLoading.Count == 0) { Debug.Assert(CacheEntry.ClosureAssemblies.Count == 0, "How did we get closure assemblies?"); // since we didn't find any types, don't lock into convention based SessionData.ObjectItemAssemblyLoaderFactory = null; } }
internal ObjectItemLoadingSessionData( KnownAssembliesSet knownAssemblies, LockedAssemblyCache lockedAssemblyCache, EdmItemCollection edmItemCollection, Action <String> logLoadMessage, object loaderCookie) { Debug.Assert( loaderCookie == null || loaderCookie is Func <Assembly, ObjectItemLoadingSessionData, ObjectItemAssemblyLoader>, "This is a bad loader cookie"); _typesInLoading = new Dictionary <string, EdmType>(StringComparer.Ordinal); _errors = new List <EdmItemError>(); _knownAssemblies = knownAssemblies; _lockedAssemblyCache = lockedAssemblyCache; _edmItemCollection = edmItemCollection; _loadMessageLogger = new LoadMessageLogger(logLoadMessage); _cspaceToOspace = new Dictionary <EdmType, EdmType>(); _loaderFactory = (Func <Assembly, ObjectItemLoadingSessionData, ObjectItemAssemblyLoader>)loaderCookie; _originalLoaderCookie = loaderCookie; if (_loaderFactory == ObjectItemConventionAssemblyLoader.Create && _edmItemCollection != null) { foreach (var entry in _knownAssemblies.GetEntries(_loaderFactory, edmItemCollection)) { foreach (var type in entry.CacheEntry.TypesInAssembly.OfType <EdmType>()) { if (Helper.IsEntityType(type)) { var entityType = (ClrEntityType)type; _cspaceToOspace.Add(_edmItemCollection.GetItem <StructuralType>(entityType.CSpaceTypeName), entityType); } else if (Helper.IsComplexType(type)) { var complexType = (ClrComplexType)type; _cspaceToOspace.Add(_edmItemCollection.GetItem <StructuralType>(complexType.CSpaceTypeName), complexType); } else if (Helper.IsEnumType(type)) { var enumType = (ClrEnumType)type; _cspaceToOspace.Add(_edmItemCollection.GetItem <EnumType>(enumType.CSpaceTypeName), enumType); } else { Debug.Assert(Helper.IsAssociationType(type)); _cspaceToOspace.Add(_edmItemCollection.GetItem <StructuralType>(type.FullName), type); } } } } }
/// <summary> /// Creates a new instance of EdmProperty type. /// </summary> /// <param name="name">Name of the property.</param> /// <param name="typeUsage"> /// Property <see cref="TypeUsage" /> /// </param> /// <returns>A new instance of EdmProperty type</returns> public static EdmProperty Create(string name, TypeUsage typeUsage) { Check.NotEmpty(name, "name"); Check.NotNull(typeUsage, "typeUsage"); var edmType = typeUsage.EdmType; if (!(Helper.IsPrimitiveType(edmType) || Helper.IsEnumType(edmType) || Helper.IsComplexType(edmType))) { throw new ArgumentException(Strings.EdmProperty_InvalidPropertyType(edmType.FullName)); } return(new EdmProperty(name, typeUsage)); }
internal static string TryGetMappingCSpaceTypeIdentity(EdmType edmType) { if (Helper.IsEntityType(edmType)) { return(((ClrEntityType)edmType).CSpaceTypeName); } if (Helper.IsComplexType(edmType)) { return(((ClrComplexType)edmType).CSpaceTypeName); } if (Helper.IsEnumType(edmType)) { return(((ClrEnumType)edmType).CSpaceTypeName); } return(edmType.Identity); }
internal ObjectItemLoadingSessionData( KnownAssembliesSet knownAssemblies, LockedAssemblyCache lockedAssemblyCache, EdmItemCollection edmItemCollection, Action <string> logLoadMessage, object loaderCookie) { this._typesInLoading = new Dictionary <string, EdmType>((IEqualityComparer <string>)StringComparer.Ordinal); this._errors = new List <EdmItemError>(); this._knownAssemblies = knownAssemblies; this._lockedAssemblyCache = lockedAssemblyCache; this._edmItemCollection = edmItemCollection; this._loadMessageLogger = new LoadMessageLogger(logLoadMessage); this._cspaceToOspace = new Dictionary <EdmType, EdmType>(); this._loaderFactory = (Func <Assembly, ObjectItemLoadingSessionData, ObjectItemAssemblyLoader>)loaderCookie; this._originalLoaderCookie = loaderCookie; if (!(this._loaderFactory == new Func <Assembly, ObjectItemLoadingSessionData, ObjectItemAssemblyLoader>(ObjectItemConventionAssemblyLoader.Create)) || this._edmItemCollection == null) { return; } foreach (KnownAssemblyEntry entry in this._knownAssemblies.GetEntries((object)this._loaderFactory, edmItemCollection)) { foreach (EdmType edmType in entry.CacheEntry.TypesInAssembly.OfType <EdmType>()) { if (Helper.IsEntityType(edmType)) { ClrEntityType clrEntityType = (ClrEntityType)edmType; this._cspaceToOspace.Add((EdmType)this._edmItemCollection.GetItem <StructuralType>(clrEntityType.CSpaceTypeName), (EdmType)clrEntityType); } else if (Helper.IsComplexType(edmType)) { ClrComplexType clrComplexType = (ClrComplexType)edmType; this._cspaceToOspace.Add((EdmType)this._edmItemCollection.GetItem <StructuralType>(clrComplexType.CSpaceTypeName), (EdmType)clrComplexType); } else if (Helper.IsEnumType(edmType)) { ClrEnumType clrEnumType = (ClrEnumType)edmType; this._cspaceToOspace.Add((EdmType)this._edmItemCollection.GetItem <EnumType>(clrEnumType.CSpaceTypeName), (EdmType)clrEnumType); } else { this._cspaceToOspace.Add((EdmType)this._edmItemCollection.GetItem <StructuralType>(edmType.FullName), edmType); } } } }
private bool EnumMembersMatch(Type enumType, EnumType cspaceEnumType) { DebugCheck.NotNull(enumType); Debug.Assert(enumType.IsEnum, "expected enum OSpace type"); DebugCheck.NotNull(cspaceEnumType); Debug.Assert(Helper.IsEnumType(cspaceEnumType), "Enum type expected"); Debug.Assert( cspaceEnumType.UnderlyingType.ClrEquivalentType == enumType.GetEnumUnderlyingType(), "underlying types should have already been checked"); var enumUnderlyingType = enumType.GetEnumUnderlyingType(); var cspaceSortedEnumMemberEnumerator = cspaceEnumType.Members.OrderBy(m => m.Name).GetEnumerator(); var ospaceSortedEnumMemberNamesEnumerator = enumType.GetEnumNames().OrderBy(n => n).GetEnumerator(); // no checks required if edm enum type does not have any members if (!cspaceSortedEnumMemberEnumerator.MoveNext()) { return(true); } while (ospaceSortedEnumMemberNamesEnumerator.MoveNext()) { if (cspaceSortedEnumMemberEnumerator.Current.Name == ospaceSortedEnumMemberNamesEnumerator.Current && cspaceSortedEnumMemberEnumerator.Current.Value.Equals( Convert.ChangeType( Enum.Parse(enumType, ospaceSortedEnumMemberNamesEnumerator.Current), enumUnderlyingType, CultureInfo.InvariantCulture))) { if (!cspaceSortedEnumMemberEnumerator.MoveNext()) { return(true); } } } LogLoadMessage( Strings.Mapping_Enum_OCMapping_MemberMismatch( enumType.FullName, cspaceSortedEnumMemberEnumerator.Current.Name, cspaceSortedEnumMemberEnumerator.Current.Value, cspaceEnumType.FullName), cspaceEnumType); return(false); }
public virtual EdmType TryCreateType(Type type, EdmType cspaceType) { if (Helper.IsEnumType(cspaceType) ^ type.IsEnum()) { this.LogLoadMessage(Strings.Validator_OSpace_Convention_SSpaceOSpaceTypeMismatch((object)cspaceType.FullName, (object)cspaceType.FullName), cspaceType); return((EdmType)null); } if (Helper.IsEnumType(cspaceType)) { EdmType newOSpaceType; this.TryCreateEnumType(type, (EnumType)cspaceType, out newOSpaceType); return(newOSpaceType); } EdmType newOSpaceType1; this.TryCreateStructuralType(type, (StructuralType)cspaceType, out newOSpaceType1); return(newOSpaceType1); }
/// <summary> /// Resolves enum type property. /// </summary> /// <param name="declaringType"> The type to add the declared property to. </param> /// <param name="clrProperty"> Property to resolve. </param> private void ResolveEnumTypeProperty(StructuralType declaringType, PropertyInfo clrProperty) { DebugCheck.NotNull(declaringType); DebugCheck.NotNull(clrProperty); Debug.Assert( (Nullable.GetUnderlyingType(clrProperty.PropertyType) ?? clrProperty.PropertyType).IsEnum, "This method should be called for enums only"); EdmType propertyType; if (!TryGetLoadedType(clrProperty.PropertyType, out propertyType) || !Helper.IsEnumType(propertyType)) { SessionData.EdmItemErrors.Add( new EdmItemError( Strings.Validator_OSpace_ScalarPropertyNotPrimitive( clrProperty.Name, clrProperty.DeclaringType.FullName, clrProperty.PropertyType.FullName))); } else { var edmScalarPropertyAttribute = (EdmScalarPropertyAttribute)clrProperty.GetCustomAttributes(typeof(EdmScalarPropertyAttribute), false).Single(); var enumProperty = new EdmProperty( clrProperty.Name, TypeUsage.Create( propertyType, new FacetValues { Nullable = edmScalarPropertyAttribute.IsNullable }), clrProperty, declaringType.ClrType); declaringType.AddMember(enumProperty); if (declaringType.BuiltInTypeKind == BuiltInTypeKind.EntityType && edmScalarPropertyAttribute.EntityKeyProperty) { ((EntityType)declaringType).AddKeyMember(enumProperty); } } }
// <summary> // Given the ospace type, returns the fullname of the mapped cspace type. // Today, since we allow non-default mapping between entity type and complex type, // this is only possible for entity and complex type. // </summary> internal static string TryGetMappingCSpaceTypeIdentity(EdmType edmType) { Debug.Assert(DataSpace.OSpace == edmType.DataSpace, "DataSpace must be OSpace"); if (Helper.IsEntityType(edmType)) { return(((ClrEntityType)edmType).CSpaceTypeName); } else if (Helper.IsComplexType(edmType)) { return(((ClrComplexType)edmType).CSpaceTypeName); } else if (Helper.IsEnumType(edmType)) { return(((ClrEnumType)edmType).CSpaceTypeName); } return(edmType.Identity); }
internal virtual void AddLoadedTypes(Dictionary <string, EdmType> typesInLoading) { DebugCheck.NotNull(typesInLoading); var globalItems = new List <GlobalItem>(); foreach (var edmType in typesInLoading.Values) { globalItems.Add(edmType); var cspaceTypeName = ""; try { // Also populate the ocmapping information if (Helper.IsEntityType(edmType)) { cspaceTypeName = ((ClrEntityType)edmType).CSpaceTypeName; _ocMapping.Add(cspaceTypeName, edmType); } else if (Helper.IsComplexType(edmType)) { cspaceTypeName = ((ClrComplexType)edmType).CSpaceTypeName; _ocMapping.Add(cspaceTypeName, edmType); } else if (Helper.IsEnumType(edmType)) { cspaceTypeName = ((ClrEnumType)edmType).CSpaceTypeName; _ocMapping.Add(cspaceTypeName, edmType); } // for the rest of the types like a relationship type, we do not have oc mapping, // so we don't keep that information } catch (ArgumentException e) { throw new MappingException(Strings.Mapping_CannotMapCLRTypeMultipleTimes(cspaceTypeName), e); } } // Create a new ObjectItemCollection and add all the global items to it. // Also copy all the existing items from the existing collection AddRange(globalItems); }
private bool TryCreateEnumType(Type enumType, EnumType cspaceEnumType, out EdmType newOSpaceType) { DebugCheck.NotNull(enumType); Debug.Assert(enumType.IsEnum, "enum type expected"); DebugCheck.NotNull(cspaceEnumType); Debug.Assert(Helper.IsEnumType(cspaceEnumType), "Enum type expected"); newOSpaceType = null; // Check if the OSpace and CSpace enum type match if (!UnderlyingEnumTypesMatch(enumType, cspaceEnumType) || !EnumMembersMatch(enumType, cspaceEnumType)) { return(false); } newOSpaceType = new ClrEnumType(enumType, cspaceEnumType.NamespaceName, cspaceEnumType.Name); LoadedTypes.Add(enumType.FullName, newOSpaceType); return(true); }
/// <summary> /// Creates new enum OSpace type built based on CLR <paramref name="enumType" /> and <paramref name="cspaceEnumType" /> /// </summary> /// <param name="enumType"> CLR type to create OSpace type from. </param> /// <param name="cspaceEnumType"> CSpace type used to get namespace and name for the newly created OSpace type. </param> /// <param name="newOSpaceType"> /// New enum OSpace type built based on CLR <paramref name="enumType" /> and /// <paramref /// name="cspaceEnumType" /> /// or null if the type could not be built. /// </param> /// <returns> /// <c>true</c> if the type was built successfully. <c>false</c> otherwise. /// </returns> private bool TryCreateEnumType(Type enumType, EnumType cspaceEnumType, out EdmType newOSpaceType) { DebugCheck.NotNull(enumType); Debug.Assert(enumType.IsEnum, "enum type expected"); DebugCheck.NotNull(cspaceEnumType); Debug.Assert(Helper.IsEnumType(cspaceEnumType), "Enum type expected"); Debug.Assert(TypesMatchByConvention(enumType, cspaceEnumType), "The types passed as parameters don't match by convention."); newOSpaceType = null; // Check if the OSpace and CSpace enum type match if (!UnderlyingEnumTypesMatch(enumType, cspaceEnumType) || !EnumMembersMatch(enumType, cspaceEnumType)) { return(false); } newOSpaceType = new ClrEnumType(enumType, cspaceEnumType.NamespaceName, cspaceEnumType.Name); SessionData.TypesInLoading.Add(enumType.FullName, newOSpaceType); return(true); }
private void ResolveEnumTypeProperty(StructuralType declaringType, PropertyInfo clrProperty) { EdmType edmType; if (!this.TryGetLoadedType(clrProperty.PropertyType, out edmType) || !Helper.IsEnumType(edmType)) { this.SessionData.EdmItemErrors.Add(new EdmItemError(Strings.Validator_OSpace_ScalarPropertyNotPrimitive((object)clrProperty.Name, (object)clrProperty.DeclaringType.FullName, (object)clrProperty.PropertyType.FullName))); } else { EdmScalarPropertyAttribute propertyAttribute = clrProperty.GetCustomAttributes <EdmScalarPropertyAttribute>(false).Single <EdmScalarPropertyAttribute>(); EdmProperty edmProperty = new EdmProperty(clrProperty.Name, TypeUsage.Create(edmType, new FacetValues() { Nullable = (FacetValueContainer <bool?>) new bool?(propertyAttribute.IsNullable) }), clrProperty, declaringType.ClrType); declaringType.AddMember((EdmMember)edmProperty); if (declaringType.BuiltInTypeKind != BuiltInTypeKind.EntityType || !propertyAttribute.EntityKeyProperty) { return; } ((EntityTypeBase)declaringType).AddKeyMember((EdmMember)edmProperty); } }
// <summary> // Determines if the given edmType is equal comparable. Consult "EntitySql Language Specification", // section 7 - Comparison and Dependent Operations for details. // </summary> // <param name="edmType"> an instance of an EdmType </param> // <returns> true if edmType is equal-comparable, false otherwise </returns> private static bool IsEqualComparable(EdmType edmType) { if (Helper.IsPrimitiveType(edmType) || Helper.IsRefType(edmType) || Helper.IsEntityType(edmType) || Helper.IsEnumType(edmType)) { return(true); } else if (Helper.IsRowType(edmType)) { var rowType = (RowType)edmType; foreach (var rowProperty in rowType.Properties) { if (!IsEqualComparable(rowProperty.TypeUsage)) { return(false); } } return(true); } return(false); }
private bool TryFindAndCreateEnumProperties( Type type, StructuralType cspaceType, StructuralType ospaceType, PropertyInfo[] clrProperties, List <Action> referenceResolutionListForCurrentType) { var typeClosureToTrack = new List <KeyValuePair <EdmProperty, PropertyInfo> >(); foreach ( var cspaceProperty in cspaceType.GetDeclaredOnlyMembers <EdmProperty>().Where(p => Helper.IsEnumType(p.TypeUsage.EdmType))) { var clrProperty = clrProperties.FirstOrDefault(p => MemberMatchesByConvention(p, cspaceProperty)); if (clrProperty != null) { typeClosureToTrack.Add(new KeyValuePair <EdmProperty, PropertyInfo>(cspaceProperty, clrProperty)); } else { var message = Strings.Validator_OSpace_Convention_MissingRequiredProperty(cspaceProperty.Name, type.FullName); LogLoadMessage(message, cspaceType); return(false); } } foreach (var typeToTrack in typeClosureToTrack) { TrackClosure(typeToTrack.Value.PropertyType); // prevent the lifting of these closure variables var ot = ospaceType; var cp = typeToTrack.Key; var clrp = typeToTrack.Value; referenceResolutionListForCurrentType.Add(() => CreateAndAddEnumProperty(type, ot, cp, clrp)); } return(true); }
internal static bool IsEnumerationType(TypeUsage type) { return(Helper.IsEnumType(type.EdmType)); }
// <summary> // determines if <paramref name="type" /> is primitive or enumeration type // </summary> // <param name="type"> Type to verify. </param> // <returns> // <c>true</c> if <paramref name="type" /> is primitive or enumeration type. <c>false</c> otherwise. // </returns> internal static bool IsScalarType(EdmType type) { DebugCheck.NotNull(type); return(Helper.IsPrimitiveType(type) || Helper.IsEnumType(type)); }
// <summary> // determines if type is of EnumerationType. // </summary> internal static bool IsEnumerationType(TypeUsage type) { DebugCheck.NotNull(type); return(Helper.IsEnumType(type.EdmType)); }
private static bool IsEqualComparable(EdmType edmType) { if (Helper.IsPrimitiveType(edmType) || Helper.IsRefType((GlobalItem)edmType) || (Helper.IsEntityType(edmType) || Helper.IsEnumType(edmType))) { return(true); } if (!Helper.IsRowType((GlobalItem)edmType)) { return(false); } foreach (EdmMember property in ((RowType)edmType).Properties) { if (!TypeSemantics.IsEqualComparable(property.TypeUsage)) { return(false); } } return(true); }
private static bool TryGetClrType(EdmType objectSpaceType, out Type clrType) { if (objectSpaceType.DataSpace != DataSpace.OSpace) { throw new ArgumentException(Strings.ArgumentMustBeOSpaceType, nameof(objectSpaceType)); } clrType = (Type)null; if (Helper.IsEntityType(objectSpaceType) || Helper.IsComplexType(objectSpaceType) || Helper.IsEnumType(objectSpaceType)) { clrType = objectSpaceType.ClrType; } return(clrType != (Type)null); }
internal bool TryGetOSpaceType(EdmType cspaceType, out EdmType edmType) { if (Helper.IsEntityType(cspaceType) || Helper.IsComplexType(cspaceType) || Helper.IsEnumType(cspaceType)) { return(this._ocMapping.TryGetValue(cspaceType.Identity, out edmType)); } return(this.TryGetItem <EdmType>(cspaceType.Identity, out edmType)); }
private static bool LoadAssemblyFromCache( ObjectItemCollection objectItemCollection, Assembly assembly, bool loadReferencedAssemblies, EdmItemCollection edmItemCollection, Action <String> logLoadMessage) { // Check if its loaded in the cache - if the call is for loading referenced assemblies, make sure that all referenced // assemblies are also loaded KnownAssemblyEntry entry; if (objectItemCollection._knownAssemblies.TryGetKnownAssembly( assembly, objectItemCollection._loaderCookie, edmItemCollection, out entry)) { // Proceed if only we need to load the referenced assemblies and they are not loaded if (loadReferencedAssemblies == false) { // don't say we loaded anything, unless we actually did before return(entry.CacheEntry.TypesInAssembly.Count != 0); } else if (entry.ReferencedAssembliesAreLoaded) { // this assembly was part of a all hands reference search return(true); } } lock (objectItemCollection.LoadAssemblyLock) { // Check after acquiring the lock, since the known assemblies might have got modified // Check if the assembly is already loaded. The reason we need to check if the assembly is already loaded, is that if (objectItemCollection._knownAssemblies.TryGetKnownAssembly( assembly, objectItemCollection._loaderCookie, edmItemCollection, out entry)) { // Proceed if only we need to load the referenced assemblies and they are not loaded if (loadReferencedAssemblies == false || entry.ReferencedAssembliesAreLoaded) { return(true); } } Dictionary <string, EdmType> typesInLoading; List <EdmItemError> errors; KnownAssembliesSet knownAssemblies; if (objectItemCollection != null) { knownAssemblies = new KnownAssembliesSet(objectItemCollection._knownAssemblies); } else { knownAssemblies = new KnownAssembliesSet(); } // Load the assembly from the cache AssemblyCache.LoadAssembly( assembly, loadReferencedAssemblies, knownAssemblies, edmItemCollection, logLoadMessage, ref objectItemCollection._loaderCookie, out typesInLoading, out errors); // Throw if we have encountered errors if (errors.Count != 0) { throw EntityUtil.InvalidSchemaEncountered(Helper.CombineErrorMessage(errors)); } // We can encounter new assemblies, but they may not have any time in them if (typesInLoading.Count != 0) { // No errors, so go ahead and add the types and make them readonly // The existence of the loading lock tells us whether we should be thread safe or not, if we need // to be thread safe, then we need to use AtomicAddRange. We don't need to actually use the lock // because the caller should have done it already // Recheck the assemblies added, another list is created just to match up the collection type // taken in by AtomicAddRange() var globalItems = new List <GlobalItem>(); foreach (var edmType in typesInLoading.Values) { globalItems.Add(edmType); var cspaceTypeName = ""; try { // Also populate the ocmapping information if (Helper.IsEntityType(edmType)) { cspaceTypeName = ((ClrEntityType)edmType).CSpaceTypeName; objectItemCollection._ocMapping.Add(cspaceTypeName, edmType); } else if (Helper.IsComplexType(edmType)) { cspaceTypeName = ((ClrComplexType)edmType).CSpaceTypeName; objectItemCollection._ocMapping.Add(cspaceTypeName, edmType); } else if (Helper.IsEnumType(edmType)) { cspaceTypeName = ((ClrEnumType)edmType).CSpaceTypeName; objectItemCollection._ocMapping.Add(cspaceTypeName, edmType); } // for the rest of the types like a relationship type, we do not have oc mapping, // so we don't keep that information } catch (ArgumentException e) { throw new MappingException(Strings.Mapping_CannotMapCLRTypeMultipleTimes(cspaceTypeName), e); } } // Create a new ObjectItemCollection and add all the global items to it. // Also copy all the existing items from the existing collection objectItemCollection.AtomicAddRange(globalItems); } // Update the value of known assemblies objectItemCollection._knownAssemblies = knownAssemblies; foreach (var loadedAssembly in knownAssemblies.Assemblies) { CollectIfViewGenAssembly(loadedAssembly); } return(typesInLoading.Count != 0); } }
internal static bool IsCastAllowed(TypeUsage fromType, TypeUsage toType) { if (Helper.IsPrimitiveType(fromType.EdmType) && Helper.IsPrimitiveType(toType.EdmType) || Helper.IsPrimitiveType(fromType.EdmType) && Helper.IsEnumType(toType.EdmType) || Helper.IsEnumType(fromType.EdmType) && Helper.IsPrimitiveType(toType.EdmType)) { return(true); } if (Helper.IsEnumType(fromType.EdmType) && Helper.IsEnumType(toType.EdmType)) { return(fromType.EdmType.Equals((object)toType.EdmType)); } return(false); }