문제

나는 보았다 모래와 인터넷을하지만 여전히 알아낼 수 없습니다 내가 누락과를 구현하는 방법 일반적인 명령 인터페이스에서는 F#이러한 유형:

type OrCondition() as self =
    inherit Condition()
    member val Conditions: List<Condition> = new List<Condition>() with get, set
    interface IList<Condition> with
        member this.Item 
            with get(index) = self.Conditions.[index]
            and  set(index)(value) = self.Conditions.[index] <- value
        member this.IndexOf item = self.Conditions.IndexOf(item)
        member this.Insert(index, item) = self.Conditions.Insert(index, item)
        member this.RemoveAt(index) = self.Conditions.RemoveAt(index)
        member this.Count with get() = self.Conditions.Count
        member this.IsReadOnly with get() = false
        member this.Add(item) = self.Conditions.Add(item)
        member this.Clear() = self.Conditions.Clear()
        member this.Contains(item) = self.Conditions.Contains(item)
        member this.CopyTo(conditions, index) = self.Conditions.CopyTo(conditions, index)
        member this.Remove(item) = self.Conditions.Remove(item)
        member this.GetEnumerator() = (Seq.cast<Condition> self.Conditions).GetEnumerator()

지금 컴파일러는 불평하지 않았 구현 컬렉션이 있습니다.페.GetEnumerator()나는 그것을 알지만 내가 말을 하는 방법을 알고 있습니다.

업데이트: 최종 결과는 같다.좋은 씨에게 감사환.또한 가치를 지적하는 나만 참조 시스템입니다.컬렉션이 있습니다.일반 및 가 참조 시스템.컬렉션가 아닌 일반 버전페이 있습니다.슬---끝---이력서 지원하지 않 F#.

open System.Collections
open System.Collections.Generic

type OrCondition() as self =
    inherit Condition()
    member val Conditions = new List<Condition>() with get, set
    interface IList<Condition> with
        member this.Item 
            with get(index) = self.Conditions.[index]
            and  set(index)(value) = self.Conditions.[index] <- value
        member this.IndexOf item = self.Conditions.IndexOf(item)
        member this.Insert(index, item) = self.Conditions.Insert(index, item)
        member this.RemoveAt(index) = self.Conditions.RemoveAt(index)
        member this.Count with get() = self.Conditions.Count
        member this.IsReadOnly with get() = false
        member this.Add(item) = self.Conditions.Add(item)
        member this.Clear() = self.Conditions.Clear()
        member this.Contains(item) = self.Conditions.Contains(item)
        member this.CopyTo(conditions, index) = self.Conditions.CopyTo(conditions, index)
        member this.Remove(item) = self.Conditions.Remove(item)
        member this.GetEnumerator() = self.Conditions.GetEnumerator() :> IEnumerator<Condition>
        member this.GetEnumerator() = self.Conditions.GetEnumerator() :> IEnumerator 
도움이 되었습니까?

해결책

이 때문입니다 IList 는 두 개의 GetEnumerator 방법 중 하나,대 IEnumerable<T> 인터페이스 및 아닌 일반 IEnumerable 인터페이스입니다.

추가할 수 있습니다 이 회원을 구현하는 IEnumerable

member this.GetEnumerator() = (this.Conditions :> IEnumerable).GetEnumerator()

다른 팁

가장 간단한 방법은

입니다.
interface System.Collections.IEnumerable with
    member this.GetEnumerator() = this.Conditions.GetEnumerator() :> _
.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top