0

私のVB.NETプロジェクトには次のクラスがあります。

Public Class Field
       Public Property FieldName As String
       Public Property ScriptObject As Script
End Class

Public Class Script
       Public Property ScriptName As String
       Public Property InputParamList As List (Of InputParam)
       Public Property OutputParam As String
End Class


Public Class InputParam
       Public Property ParamName As String
       Public Property Type As String //Type can be Field, FixValue or Counter
       Public Property FieldName As String
       Public Property FixValue As String
       Public Property CounterObject As Counter
End Class

Public Class Counter
       Public Property StartValue As Integer
       Public Property StepValue As Integer
End Class

ビジネス関数の 1 つが me を返しますList(Of Field)。からList(Of Field)、同じスクリプト構成を持つフィールドをフィルター/検索する必要があります。これは、同じスクリプト名、同じ入力パラメーター構成 (名前、タイプ、フィールド名、FixValue、およびカウンター構成 (StartValue、StepValue)) を持つことを意味します。

LINQクエリまたはEqualityComparerまたはその他の方法を使用してこれを達成するにはどうすればよいですか?

==================

以下はサンプル関数です。GetFields()関数は、同じ構成(同じプロパティ値)を持つList(of Field)必要があるものから戻ります。以下の関数では、FirstField と SecondField は、スクリプト名、InputParam プロパティに関して同じ ScriptObject を持ちます。したがって、LINQ またはその他の方法を使用して(ScriptName ('Script1') を文字列として、List(Of Field) を First および Second Field アイテムとして)返す必要があります。List(Of Field)ScriptObjectGetFields()IGrouping(of String,List(Of Field))List(Of Field)GetFields()

Public Function GetFields() As List(Of Field)
    Dim oFieldList As New List(Of Field)
    Dim oFirstScript As Script = GetFirstScript()
        Dim oSecondScript As Script = GetSecondScript()


    Dim oFirstField As New Field
    oFirstField.Name = "FirstField"
    oFirstField.ScriptObject = New Script()
    oFirstField.ScriptObject.Name = oFirstScript.Name
    oFirstField.ScriptObject.InputParamList = new List(Of InputParam)

    For Each oInParam In oFirstScript.InputParamList
        Dim oInputParam = New InputParam()
        oInputParam.Name = oInParam.Name
        oInputParam.Type = oInParam.Type
        oInputParam.FixVaue = oInParam.FixValue
        oInputParam.CounterObject = oInParam.CounterObject  
        oFirstField.ScriptObject.InputParamList.Add(oInputParam)
    Next

    oFirstField.OutputParam = oFirstScript.OutputParam

    oFieldList.Add(oFirstField)

    //Second Field
    Dim oSecondField As New Field
    oSecondField.Name = "SecondField" 
    oSecondField.ScriptObject = New Script()
    oSecondField.ScriptObject.Name = oFirstScript.Name
    oSecondField.ScriptObject.InputParamList = new List(Of InputParam)

    For Each oInParam In oFirstScript.InputParamList
        Dim oInputParam = New InputParam()
        oInputParam.Name = oInParam.Name
        oInputParam.Type = oInParam.Type
        oInputParam.FixVaue = oInParam.FixValue
        oInputParam.CounterObject = oInParam.CounterObject  
        oSecondField.ScriptObject.InputParamList.Add(oInputParam)
    Next

    oSecondField.OutputParam = oFirstScript.OutputParam

    oFieldList.Add(oSecondField)

    //Third Field
    Dim oThirdField As New Field
    oThirdField.Name = "ThirdField" 
    oThirdField.ScriptObject = New Script()
    oThirdField.ScriptObject.Name = oSecondScript.Name
    oThirdField.ScriptObject.InputParamList = new List(Of InputParam)

    For Each oInParam In oSecondScript.InputParamList
        Dim oInputParam = New InputParam()
        oInputParam.Name = oInParam.Name
        oInputParam.Type = oInParam.Type
        oInputParam.FixVaue = oInParam.FixValue
        oInputParam.CounterObject = oInParam.CounterObject  
        oThirdField.ScriptObject.InputParamList.Add(oInputParam)
    Next

    oThirdField.OutputParam = oSecondScript.OutputParam

    oFieldList.Add(oThirdField)

    Return oFieldList
End Function

Public Function GetFirstScript() As Script
    Dim oScript As New Script
    oScript.Name = "Script1"
    oScript.InputParamList = New List(Of InputParam)

    Dim oFieldInputParam As New InputParam
    oFieldInputParam.Name = "Param1"
    oFieldInputParam.Type = "Field"
    oFieldInputParam.FieldName = "FirstField"
    oFieldInputParam.FixValue = String.Empty
    oFieldInputParam.CounterObject = Nothing

    oScript.InputParamList.Add(oFieldInputParam)

    Dim oFixInputParam As New InputParam
    oFixInputParam.Name = "Param2"
    oFixInputParam.Type = "FixValue"
    oFixInputParam.FieldName = String.Empty
    oFixInputParam.FixValue = "123"
    oFixInputParam.CounterObject = Nothing

    oScript.InputParamList.Add(oFixInputParam)

    Dim oCounterInputParam As New InputParam
    oCounterInputParam.Name = "Param3"
    oCounterInputParam.Type = "Counter"
    oCounterInputParam.FieldName = String.Empty
    oCounterInputParam.FixValue = String.Empty
    oCounterInputParam.CounterObject = New Counter
    oCounterInputParam.CounterObject.StartValue = 1
    oCounterInputParam.CounterObject.StepValue = 1

    oScript.InputParamList.Add(oCounterInputParam)

    oScript.OutputParam = "returnResult"

    Return oScript
End Function

Public Function GetSecondScript() As Script
    Dim oScript As New Script
    oScript.Name = "Script2"
    oScript.InputParamList = New List(Of InputParam)

    Dim oFieldInputParam As New InputParam
    oFieldInputParam.Name = "Param1"
    oFieldInputParam.Type = "Field"
    oFieldInputParam.FieldName = "SecondField"
    oFieldInputParam.FixValue = String.Empty
    oFieldInputParam.CounterObject = Nothing

    oScript.InputParamList.Add(oFieldInputParam)

    Dim oFixInputParam As New InputParam
    oFixInputParam.Name = "Param2"
    oFixInputParam.Type = "FixValue"
    oFixInputParam.FieldName = String.Empty
    oFixInputParam.FixValue = "XYZ"
    oFixInputParam.CounterObject = Nothing

    oScript.InputParamList.Add(oFixInputParam)

    Dim oCounterInputParam As New InputParam
    oCounterInputParam.Name = "Param3"
    oCounterInputParam.Type = "Counter"
    oCounterInputParam.FieldName = String.Empty
    oCounterInputParam.FixValue = String.Empty
    oCounterInputParam.CounterObject = New Counter
    oCounterInputParam.CounterObject.StartValue = 1
    oCounterInputParam.CounterObject.StepValue = 1

    oScript.InputParamList.Add(oCounterInputParam)

    oScript.OutputParam = "returnResult"

    Return oScript
End Function

注: ScriptName は一意です。したがって、同じスクリプト名の ScriptObject に異なる入力パラメーター数とパラメーター名を指定することはできません。パラメータのタイプのみが異なる場合があります。

ありがとう。

4

0 に答える 0