ここで私を避けている別の簡単な質問があります。
私には2つのクラスがあります:
namespace Assets
{
public class BaseAsset
{
// Code here
}
}
と
namespace Assets
{
public class Asset : BaseAsset
{
// Code here
}
}
データベースからAssetのコレクションを返す関数があり、別の関数でその関数を実行してBaseAssetのコレクションを返すようにします。私はこれを試しました:
public static Collection<BaseAsset> GetCategoryAssets(int CategoryId, string UserId, string CompanyId)
{
return (Collection<BaseAsset>)AssetData.getAssets(CategoryId, UserId, CompanyId);
}
しかし、ご想像のとおり、機能しません。リストを操作している場合は、次のことができます。
public static List<BaseAsset> GetCategoryAssets(int CategoryId, string UserId, string CompanyId)
{
return AssetData.getAssets(CategoryId, UserId, CompanyId).Cast<BaseAsset>().ToList();
}
しかし、私はコレクションを使用したいと思います、誰かがエレガントな解決策を思い付くことができますか?
乾杯、r3plica