/// <summary> /// Checks if the given type is assignable to this type. In other words, if this type /// is a subtype of the given type or not. /// </summary> /// <param name="subType">resource type to check.</param> /// <returns>true, if the given type is assignable to this type. Otherwise returns false.</returns> internal static bool IsAssignableFrom(this ResourceType thisType, ResourceType subType) { CollectionResourceType thisCollectionType = thisType as CollectionResourceType; CollectionResourceType subCollectionType = subType as CollectionResourceType; if (thisCollectionType != null && subCollectionType != null) { return(thisCollectionType.ItemType.IsAssignableFrom(subCollectionType.ItemType)); } EntityCollectionResourceType thisEntityCollectionType = thisType as EntityCollectionResourceType; EntityCollectionResourceType subEntityCollectionType = subType as EntityCollectionResourceType; if (thisEntityCollectionType != null && subEntityCollectionType != null) { return(thisEntityCollectionType.ItemType.IsAssignableFrom(subEntityCollectionType.ItemType)); } while (subType != null) { if (subType == thisType) { return(true); } subType = subType.BaseType; } return(false); }
// Given a type try to find the resource set. private ResourceSet GetResourceSet(ResourceType type) { if (type == null) { return(null); } else if (type.ResourceTypeKind == ResourceTypeKind.EntityCollection) { EntityCollectionResourceType ecType = type as EntityCollectionResourceType; return(GetResourceSet(ecType.ItemType)); } else if (type.ResourceTypeKind == ResourceTypeKind.EntityType) { var set = _metadata.ResourceSets.SingleOrDefault(rs => rs.ResourceType == type); if (set != null) { return(set); } else if (type.BaseType != null) { return(GetResourceSet(type.BaseType)); } } return(null); }