2013-04-24 3 views
1
나는 Item 클래스는 여러 가지 다른 회원이 IEnumerable<Item>를 반환하는 쿼리를 작성했습니다

: 나는 LINQPad는 결과 테이블의 컬럼에 Item 속성을 할당 선택한 순서를 좋아하지 않는다LINQPad - IEnumerable <MyObject>을 렌더링 할 때 열 순서를 제어 하시겠습니까?

public class Item 
{ 
    public string Name { get; private set; } 
    public string Type { get; private set; } 

    public IEnumerable<Property> Properties; 
    public IEnumerable<Item> Items; 

    public Item(XElement itemElement) 
    { 
     Name = itemElement.Attribute("name").Value; 
     Type = itemElement.Attribute("type").Value; 
     Properties = from property in itemElement.Elements("Property") 
        select new Property(property); 

     Items = from item in itemElement.Elements("Item") 
       select new Item(item); 
    } 
} 

을 . 열이 Name, Type, Properties, Items의 순서로 표시되기를 원하지만 LINQPad 기본값은 Properties, Items, Name, Type입니다. 속성 열이 있어야하는 순서를 LINQPad에 알 수있는 방법이 있습니까?

+1

시도'추가 {얻을; set;}'을 속성과'Type'으로 설정하여 속성을 만듭니다 - 테이블을 생성하는 코드는 필드를 먼저 순환 한 다음 속성을 반복 할 수 있습니다. 또는 [custom visualizer] (http://www.linqpad.net/customvisualizers.aspx)를 작성할 수도 있습니다. –

답변

6

난 아직도 IEnumerable<FooObject>에 대한 선언 순서를 제어하지 않는 경우 상황에서 LINQPad 덤프() 열 순서를 무시하는 방법이 있는지 알고 싶습니다. 당신이 항목 클래스를 변경할 수 있습니다 제공

, 당신은 (http://www.linqpad.net/FAQ.aspx#extensibility 참조) ICustomMemberProvider를 구현하여이 작업을 수행 할 수 있습니다

예를 들어

public class Item : LINQPad.ICustomMemberProvider 
{ 

    ... 

    IEnumerable<string> ICustomMemberProvider.GetNames() 
    { 
     return new [] { "Name", "Type", "Properties", "Items" }; 
    } 

    IEnumerable<Type> ICustomMemberProvider.GetTypes() 
    { 
     return new [] { typeof (string), typeof(string) , typeof(IEnumerable<Item>), typeof(IEnumerable<Property>) }; 
    } 

    IEnumerable<object> ICustomMemberProvider.GetValues() 
    { 
     return new object [] { this.Name, this.Type, this.Properties, this.Items }; 
    }       
} 
0

이름과 형식이 C# 개체 속성 이었지만 속성 구성원과 항목 구성원이 실제로 C# 개체 필드 였기 때문에 질문에 설명 된 LINQPad 정렬 순서가 발생했습니다.

LINQPad는 기본적으로 속성 앞에 개체 필드를 표시합니다.

나는 등록 회원 및 항목 회원에게 자동 구현 속성을 추가 :

public string Name { get; private set; } 
    public string Type { get; private set; } 
    public IEnumerable<Property> Properties { get; private set; } 
    public IEnumerable<Item> Items { get; private set; } 

이 변경을 한 후, LINQPad 열 순서는 내가 원래 원했던 인 클래스에서 멤버 선언 순서를 일치.

그러나이 질문을 남겨두고 직접 선언문을 제어하지 않는 상황에서 LINQPad Dump() 열 순서를 재정의 할 수있는 방법이 있는지 알고 싶습니다. IEnumerable<FooObject>.