0

I have a requirement to pass an IEnumerable<Object> to an MVC view and have the view cast this to a strongly typed object and display it accordingly.

This appears to be having a performance impact vs. passing it down as a IEnumerable of MyCustomObject.

foreach (var item in Model.Items)
{
    var current = (MyCustomObject) item;
    <p>@current.Submitted</p>
}

My questions are

  1. Should I cast the entire IEnumerable of Objects to IEnumerable of MyCustomObject?
  2. How can I improve the performance of this operation?
  3. If this is not good practice, what's the best way to pass a "variable" type for my Items collection, which could be a collection of any type of custom object?

Custom JUnit test detection using gradle

Our test suite is growing quickly and we have reached a point where our more functional tests are dependent on other systems.

We use gradle test tasks to run these tests using the include and exclude filters but this is becoming cumbersome because we are having to name our tests in a particular way.

Our current approach is to name our tests in the following way:

class AppleSingleServiceTest {}
class BananaMultiServiceTest {}
class KiwiIntegrationTest {}

and then include tests in the relevant task using

include '**/*SingleServiceTest.class'
include '**/*MultiServiceTest.class'
include '**/*IntegrationTest.class'

Is it possible find test classes in gradle by looking at annotations?

@SingleServiceTest
public class AppleTest {}

I think any tests that are not annotated would then be run as normal unit tests, so if you forget to annotate a more functional test it will fail

An example of a single service test is a selenium test where any external dependencies of the SUT are stubbed

An example of a multi service test is one where some but maybe not all external dependencies are not stubbed

4

2 に答える 2

2

リストを使用してこれをモデルに渡すと、強く定義されます

コントローラ

public ActionResult Index(){

MyModel model = new MyModel();
model.list = //get list from source

return View(model);

}

モデル

public List<MyCustomObject> list {get; set;}
于 2012-11-30T12:45:27.060 に答える
2

最初は、コレクション全体でCastを使用できます。

foreach (var item in Model.Items.Cast<MyCustomObject>()){}

タイプがすべて基本タイプ、たとえばMyCustomObjectから継承する場合、モデルはこれを指定する必要があります。

public class MyViewModel<T> where T : MyCustomObject, new() 
{
    public IEnumerable<T> Items { get; set; }
}

MyCustomObject基本タイプから継承されたアイテムコレクションに追加したいタイプを確認する必要があります

于 2012-11-30T12:52:24.337 に答える