Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/vb.net/15.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
序列化并写入许多相同的XML元素_Xml_Vb.net_Serialization - Fatal编程技术网

序列化并写入许多相同的XML元素

序列化并写入许多相同的XML元素,xml,vb.net,serialization,Xml,Vb.net,Serialization,我将3146个行星反序列化为对象,为它们可能拥有的任何空标记生成新值,然后将它们全部序列化给编写器,创建一个新的xml文档。有些行星有多块陆地、多颗卫星和多个标记。我的代码(谢谢@djv)正确地写出了派系更改标记,这些标记都有数据和派系子节点。但陆地和卫星仍然只能打印出来 我试过了:(从) 公共属性satellite()作为(字符串的)列表 公共属性landMass()作为(字符串的)列表 公共属性HPGStation()作为字符串 公共属性()作为字符串 公共属性更改()为PlanetPla

我将3146个行星反序列化为对象,为它们可能拥有的任何空标记生成新值,然后将它们全部序列化给编写器,创建一个新的xml文档。有些行星有多块陆地、多颗卫星和多个标记。我的代码(谢谢@djv)正确地写出了派系更改标记,这些标记都有数据和派系子节点。但陆地和卫星仍然只能打印出来

我试过了:(从)


公共属性satellite()作为(字符串的)列表
公共属性landMass()作为(字符串的)列表
公共属性HPGStation()作为字符串
公共属性()作为字符串
公共属性更改()为PlanetPlanetActionChange())
公共属性desc()作为字符串()
私人分新
附属=新列表(字符串)()
landMass=新列表(字符串)()
端接头
我最初的代码是这样的:

    <System.Xml.Serialization.XmlElementAttribute("satellite", GetType(String))>
    Public Property satellite() As planetsPlanetSatellite()

    <System.Xml.Serialization.XmlElementAttribute("landMass", GetType(String))>
    Public Property landMass() As planetsPlanetLandMass()

    <System.Xml.Serialization.XmlElementAttribute("hpg", GetType(String))>
    Public Property HPGStation() As String

    <System.Xml.Serialization.XmlElementAttribute("faction", GetType(String))>
    Public Property faction() As String

    <System.Xml.Serialization.XmlElementAttribute("factionChange", GetType(planetsPlanetFactionChange))>
    Public Property factionChange() As planetsPlanetFactionChange()

    <System.Xml.Serialization.XmlElementAttribute("desc", GetType(String))>
    Public Property desc() As String()

End Class

'''<remarks/>
<System.SerializableAttribute(),
 System.ComponentModel.DesignerCategoryAttribute("code"),
 System.Xml.Serialization.XmlTypeAttribute(AnonymousType:=True)>
Partial Public Class planetsPlanetFactionChange

    Private dateField As Date

    Private factionField As String

    <System.Xml.Serialization.XmlElementAttribute(DataType:="date")>
    Public Property [date]() As Date

    <System.Xml.Serialization.XmlElementAttribute("faction", GetType(String))>
    Public Property faction() As String

End Class

<System.SerializableAttribute(),
 System.ComponentModel.DesignerCategoryAttribute("code"),
 System.Xml.Serialization.XmlTypeAttribute(AnonymousType:=True)>
Partial Public Class planetsPlanetSatellite

    Private satelliteField As String

    <System.Xml.Serialization.XmlElementAttribute("satellite", GetType(String))>
    Public Property satellite() As String

End Class

<System.SerializableAttribute(),
 System.ComponentModel.DesignerCategoryAttribute("code"),
 System.Xml.Serialization.XmlTypeAttribute(AnonymousType:=True)>
Partial Public Class planetsPlanetLandMass

    Private landMassField As String

    <System.Xml.Serialization.XmlElementAttribute("landMass", GetType(String))>
    Public Property landMass() As String

End Class

公共财产卫星()作为PlanetPlanetSetTellite()
作为PlanetPlanetLandmass()的公共财产地块()
公共属性HPGStation()作为字符串
公共属性()作为字符串
公共属性更改()为PlanetPlanetActionChange())
公共属性desc()作为字符串()
末级
'''
部分公共类PlanetPlanetActionChange
私有日期字段作为日期
私有字段作为字符串
公共财产[日期]()作为日期
公共属性()作为字符串
末级
部分公共类飞机飞机卫星
专用卫星场作为字符串
公共属性satellite()作为字符串
末级
部分公共类飞机飞机陆地质量
私有landMassField作为字符串
公共属性landMass()作为字符串
末级
我只是复制了改变的方式,因为它对陆地和卫星不起作用

因此,问题是如何序列化并让XmlWriter将多个landMass和satellite标记(如果地球上有)写入新的xml文件

Planets.vb

Imports System.Xml.Serialization
'''<remarks/>
<System.SerializableAttribute(),
 System.ComponentModel.DesignerCategoryAttribute("code"),
 System.Xml.Serialization.XmlTypeAttribute(AnonymousType:=True),
 System.Xml.Serialization.XmlRootAttribute("planets", IsNullable:=False)>
Partial Public Class Planets

    Private planetField() As planetsPlanet

    '''<remarks/>
    <System.Xml.Serialization.XmlElementAttribute("planet")>
    Public Property planet() As planetsPlanet()

End Class

'''<remarks/>
<System.SerializableAttribute(),
 System.ComponentModel.DesignerCategoryAttribute("code"),
 System.Xml.Serialization.XmlTypeAttribute(AnonymousType:=True)>
Partial Public Class planetsPlanet

    <System.Xml.Serialization.XmlElementAttribute("name", GetType(String))>
    Public Property name() As String

    <System.Xml.Serialization.XmlElementAttribute("xcood", GetType(Decimal?))>
    Public Property xcood() As Decimal?

    <System.Xml.Serialization.XmlElementAttribute("ycood", GetType(Decimal?))>
    Public Property ycood() As Decimal?

    <System.Xml.Serialization.XmlElementAttribute("station", GetType(String))>
    Public Property station() As String

    <System.Xml.Serialization.XmlElementAttribute("spectralClass", GetType(String))>
    Public Property spectralClass() As String

    <System.Xml.Serialization.XmlElementAttribute("subtype", GetType(Integer?))>
    Public Property subtype() As Integer?

    <System.Xml.Serialization.XmlElementAttribute("luminosity", GetType(String))>
    Public Property luminosity() As String

    <System.Xml.Serialization.XmlElementAttribute("spectralType", GetType(String))>
    Public Property spectralType() As String

    <XmlIgnoreAttribute()>
    Public mass As Decimal
    <XmlIgnoreAttribute()>
    Public innerLife As Decimal
    <XmlIgnoreAttribute()>
    Public outerLife As Decimal
    <XmlIgnoreAttribute()>
    Public slot1 As Decimal
    <XmlIgnoreAttribute()>
    Public slot2 As Decimal
    <XmlIgnoreAttribute()>
    Public slot3 As Decimal
    <XmlIgnoreAttribute()>
    Public slot4 As Decimal
    <XmlIgnoreAttribute()>
    Public slot5 As Decimal
    <XmlIgnoreAttribute()>
    Public slot6 As Decimal
    <XmlIgnoreAttribute()>
    Public slot7 As Decimal
    <XmlIgnoreAttribute()>
    Public slot8 As Decimal
    <XmlIgnoreAttribute()>
    Public slot9 As Decimal
    <XmlIgnoreAttribute()>
    Public slot10 As Decimal
    <XmlIgnoreAttribute()>
    Public slot11 As Decimal
    <XmlIgnoreAttribute()>
    Public slot12 As Decimal
    <XmlIgnoreAttribute()>
    Public slot13 As Decimal
    <XmlIgnoreAttribute()>
    Public slot14 As Decimal
    <XmlIgnoreAttribute()>
    Public slot15 As Decimal

    <System.Xml.Serialization.XmlElementAttribute("nadirCharge", GetType(String))>
    Public Property nadirCharge() As String

    <System.Xml.Serialization.XmlElementAttribute("zenithCharge", GetType(String))>
    Public Property zenithCharge() As String

    <System.Xml.Serialization.XmlElementAttribute("sysPos", GetType(Integer?))>
    Public Property sysPos() As Integer?

    <System.Xml.Serialization.XmlElementAttribute("axis", GetType(String))>
    Public Property axis() As String

    <System.Xml.Serialization.XmlElementAttribute("orbit", GetType(String))>
    Public Property orbit() As String

    <System.Xml.Serialization.XmlElementAttribute("pressure", GetType(Integer?))>
    Public Property pressure() As Integer?

    <System.Xml.Serialization.XmlElementAttribute("gravity", GetType(Decimal?))>
    Public Property gravity() As Decimal?

    <System.Xml.Serialization.XmlElementAttribute("lifeForm", GetType(Integer?))>
    Public Property lifeForm() As Integer?

    <System.Xml.Serialization.XmlElementAttribute("climate", GetType(Integer?))>
    Public Property climate() As Integer?

    <System.Xml.Serialization.XmlElementAttribute("percentWater", GetType(Integer?))>
    Public Property percentWater() As Integer?

    <System.Xml.Serialization.XmlElementAttribute("temperature", GetType(Integer?))>
    Public Property temperature() As Integer?

    <System.Xml.Serialization.XmlElementAttribute("socioIndustrial", GetType(String))>
    Public Property socioIndustrial() As String()

    <System.Xml.Serialization.XmlElementAttribute("satellite", GetType(String))>
    Public Property satellite() As planetsPlanetSatellite()

    <System.Xml.Serialization.XmlElementAttribute("landMass", GetType(String))>
    Public Property landMass() As planetsPlanetLandMass()

    <System.Xml.Serialization.XmlElementAttribute("hpg", GetType(String))>
    Public Property HPGStation() As String

    <System.Xml.Serialization.XmlElementAttribute("faction", GetType(String))>
    Public Property faction() As String

    <System.Xml.Serialization.XmlElementAttribute("factionChange", GetType(planetsPlanetFactionChange))>
    Public Property factionChange() As planetsPlanetFactionChange()

    <System.Xml.Serialization.XmlElementAttribute("desc", GetType(String))>
    Public Property desc() As String()

End Class

'''<remarks/>
<System.SerializableAttribute(),
 System.ComponentModel.DesignerCategoryAttribute("code"),
 System.Xml.Serialization.XmlTypeAttribute(AnonymousType:=True)>
Partial Public Class planetsPlanetFactionChange

    Private dateField As Date

    Private factionField As String

    <System.Xml.Serialization.XmlElementAttribute(DataType:="date")>
    Public Property [date]() As Date

    <System.Xml.Serialization.XmlElementAttribute("faction", GetType(String))>
    Public Property faction() As String

End Class

<System.SerializableAttribute(),
 System.ComponentModel.DesignerCategoryAttribute("code"),
 System.Xml.Serialization.XmlTypeAttribute(AnonymousType:=True)>
Partial Public Class planetsPlanetSatellite

    Private satelliteField As String

    <System.Xml.Serialization.XmlElementAttribute("satellite", GetType(String))>
    Public Property satellite() As String

End Class

<System.SerializableAttribute(),
 System.ComponentModel.DesignerCategoryAttribute("code"),
 System.Xml.Serialization.XmlTypeAttribute(AnonymousType:=True)>
Partial Public Class planetsPlanetLandMass

    Private landMassField As String

    <System.Xml.Serialization.XmlElementAttribute("landMass", GetType(String))>
    Public Property landMass() As String

End Class
Imports System.Xml
Imports System.Xml.Serialization

Class objPlanets

    Private Shared ReadOnly r As New Random()

    Private Sub serialPlanets()

        Dim serial As New XmlSerializer(GetType(Planets))
        Dim p As New Planets
        Dim reader As XmlReader = XmlReader.Create(My.Application.Info.DirectoryPath & "\Planets\planetsTemplate.xml")
        While reader.Read()

            p = serial.Deserialize(reader)

        End While
        reader.Close()

        For Each planet In p.planet()

            If String.IsNullOrEmpty(planet.station()) = True Then

            Else

                Continue For

            End If

            If String.IsNullOrEmpty(planet.spectralClass()) = True AndAlso String.IsNullOrEmpty(planet.spectralType()) = False Then

                planet.spectralClass = planet.spectralType().Substring(0, 1)

            Else

            End If

            If String.IsNullOrEmpty(planet.spectralClass()) = True AndAlso String.IsNullOrEmpty(planet.spectralType()) = True Then

                planet.spectralClass = getSC()

            Else

            End If

            If (planet.subtype() Is Nothing) AndAlso String.IsNullOrEmpty(planet.spectralType()) = False Then

                planet.subtype = planet.spectralType().Substring(1, 1)

            Else

            End If

            If (planet.subtype() Is Nothing) AndAlso String.IsNullOrEmpty(planet.spectralType()) = True Then

                planet.subtype = getST()

            Else

            End If

            If String.IsNullOrEmpty(planet.luminosity()) = True AndAlso String.IsNullOrEmpty(planet.spectralType()) = False Then

                planet.luminosity = planet.spectralType().Substring(2, 2)

            Else

            End If

            If String.IsNullOrEmpty(planet.luminosity()) = True AndAlso String.IsNullOrEmpty(planet.spectralType()) = True Then

                planet.luminosity = getL(planet)

            Else

            End If

            If String.IsNullOrEmpty(planet.spectralType()) = True Then

                planet.spectralType = planet.spectralClass() & planet.subtype() & planet.luminosity()

            Else

            End If

            If planet.sysPos() Is Nothing Then

                planet.sysPos = getSP(planet)

            Else

            End If

            If String.IsNullOrEmpty(planet.axis()) = True Then

                planet.axis = getAxis()

            Else

            End If

            If String.IsNullOrEmpty(planet.orbit()) = True Then

                planet.orbit = getOrbit()

            Else

            End If

            If String.IsNullOrEmpty(planet.faction()) = True Then

                planet.faction = "UND"

            Else

            End If

        Next

        Dim Wsettings As XmlWriterSettings = New XmlWriterSettings()
        Wsettings.Indent = True
        Dim writer As XmlWriter = XmlWriter.Create(My.Application.Info.DirectoryPath & "\Planets\planets.xml", Wsettings)
        serial.Serialize(writer, p)
        writer.Flush()
        writer.Close()

    End Sub

    Private Function getAxis() As String

        Dim r As Integer = roll2D6()
        Select Case r

            Case 2 To 6

                Return "Tilted"

            Case 7 To 12

                Return "No Tilt"

            Case Else

                Return "Error"

        End Select

    End Function

    Private Function getOrbit() As String

        Dim r As Integer = roll2D6()
        Select Case r

            Case 2 To 6

                Return "Elliptical"

            Case 7 To 12

                Return "Circular"

            Case Else

                Return "Error"

        End Select

    End Function

    Private Function getSC() As String

        Dim r As Integer = roll2D6()
        Select Case r

            Case 2 To 4

                Return "M"

            Case 5 To 6

                Return "K"

            Case 7 To 8

                Return "G"

            Case 9 To 11

                Return "F"

            Case 12

                Return getHotStars()

            Case Else

                Return "Error"

        End Select

    End Function

    Private Function getHotStars() As String

        Dim r As Integer = roll2D6()

        If r >= 7 Then

            Return "F"

        Else

            Dim rr As Integer = roll2D6()
            Select Case rr

                Case 2 To 3

                    Return "B"

                Case 4 To 10

                    Return "A"

                Case 11

                    Return "B"

                Case 12

                    Return "F"

                Case Else

                    Return "Error"

            End Select

        End If

    End Function

    Private Function getST() As Integer

        Dim r As Integer = roll2D6()
        Select Case r

            Case 2, 12

                Return 9

            Case 3

                Return 7

            Case 4

                Return 5

            Case 5

                Return 3

            Case 6

                Return 1

            Case 7

                Return 0

            Case 8

                Return 2

            Case 9

                Return 4

            Case 10

                Return 6

            Case 11

                Return 8

            Case Else

                Return 99

        End Select

    End Function

    Private Function getL(planet) As String

        Dim r As Integer = roll2D6()

        If String.Compare(planet.SpectralClass(), "M", True) = 0 AndAlso (r = 2 OrElse r = 4) Then

            While r = 2 OrElse r = 4
                r = roll2D6()
            End While

        ElseIf String.Compare(planet.SpectralClass(), "K", True) = 0 AndAlso planet.subtype() >= 4 AndAlso r = 4 Then

            While r = 4
                r = roll2D6()
            End While

        Else

        End If

        Select Case r

            Case 2

                Return "VII"

            Case 3

                Return "VI"

            Case 4

                Return "IV"

            Case 5 To 8

                Return "V"

            Case 9

                Return "III"

            Case 10

                Return "II"

            Case 11

                Return "Ib"

            Case 12

                Return "Ia"

            Case Else

                Return "Error"

        End Select

    End Function

    Private Function getSP(planet) As Integer

        Dim table As DataTable = StarTable.starTable()
        Dim expression As String = "[Spectral Type] = " & "'" & planet.spectralType() & "'"
        Dim selectRow As DataRow()
        selectRow = table.Select(expression)
        planet.mass = selectRow(0)(1)
        planet.innerLife = selectRow(0)(2)
        planet.outerLife = selectRow(0)(4)
        getOrbitals(planet, table, expression, selectRow)
        Dim arraySlots() As Decimal = {planet.slot1(), planet.slot2(), planet.slot3(), planet.slot4(), planet.slot5(), planet.slot6(), planet.slot7(),
            planet.slot8(), planet.slot9(), planet.slot10(), planet.slot11(), planet.slot12(), planet.slot13(), planet.slot14(), planet.slot15()}
        Dim rollSlots() As Decimal = getSlots(planet)
        For i = 0 To arraySlots.Length - 1

            arraySlots(i) = rollSlots(i)

        Next

        Dim checkLife As Decimal = Array.Find(arraySlots, Function(slot)

                                                              Return slot >= planet.innerLife() AndAlso slot <= planet.outerLife()

                                                          End Function)

        If checkLife = 0 Then

            While checkLife = 0

                rollSlots = getSlots(planet)
                For i = 0 To arraySlots.Length - 1

                    arraySlots(i) = rollSlots(i)

                Next
                checkLife = Array.Find(arraySlots, Function(slot)

                                                       Return slot >= planet.innerLife() AndAlso slot <= planet.outerLife()

                                                   End Function)

            End While

        Else

        End If

        Dim p As Integer = getRandom15()
        If arraySlots(p - 1) < planet.innerLife() OrElse arraySlots(p - 1) > planet.outerLife() Then

            While arraySlots(p - 1) < planet.innerLife() OrElse arraySlots(p - 1) > planet.outerLife()

                p = getRandom15()

            End While

        End If

        Return p

    End Function

    Private Function getRandom15() As Integer

        Return r.Next(1, 16)

    End Function

    Private Sub getOrbitals(planet As Object, table As DataTable, expression As String, selectRow As DataRow())

        If (((4 / 3) ^ 2) ^ (1 / 3) * planet.mass()) > planet.outerLife() Then

            While (((4 / 3) ^ 2) ^ (1 / 3) * planet.mass()) > planet.outerLife()

                planet.spectralClass = getSC()
                planet.subtype = getST()
                planet.luminosity = getL(planet)
                planet.spectralType = planet.spectralClass() & planet.subtype() & planet.luminosity()
                expression = "[Spectral Type] = " & "'" & planet.spectralType() & "'"
                selectRow = table.Select(expression)
                planet.mass = selectRow(0)(1)
                planet.outerLife = selectRow(0)(4)

            End While

        Else

        End If

    End Sub

    Private Function getSlots(planet) As Array

        Dim Slots(14) As Decimal

        For i = 0 To Slots.Length - 1

            If i = 0 Then

                Slots(0) = getResonance() * planet.mass()

            Else

                Slots(i) = getResonance() * Slots(i - 1)

            End If

        Next

        Return Slots

    End Function

    Private Function getResonance() As Decimal

        Dim r As Integer = roll1D10()
        Select Case r

            Case 1

                Return ((4 / 3) ^ 2) ^ (1 / 3)

            Case 2

                Return ((3 / 2) ^ 2) ^ (1 / 3)

            Case 3

                Return ((8 / 5) ^ 2) ^ (1 / 3)

            Case 4

                Return ((5 / 3) ^ 2) ^ (1 / 3)

            Case 5

                Return ((7 / 4) ^ 2) ^ (1 / 3)

            Case 6

                Return ((9 / 5) ^ 2) ^ (1 / 3)

            Case 7

                Return ((2 / 1) ^ 2) ^ (1 / 3)

            Case 8

                Return ((7 / 3) ^ 2) ^ (1 / 3)

            Case 9

                Return ((5 / 2) ^ 2) ^ (1 / 3)

            Case 10

                Return ((3 / 1) ^ 2) ^ (1 / 3)

            Case Else

                Return 0

        End Select

    End Function

    Shared Function roll1D10() As Integer

        Return r.Next(1, 11)

    End Function

    Shared Function roll2D6() As Integer

        Return r.Next(1, 7) + r.Next(1, 7)

    End Function

    Public Sub New()

        serialPlanets()

    End Sub

End Class
Imports System.Xml.Serialization
'''
部分公共类行星
专用planetField()作为planetsPlanet
'''
公共财产行星()作为planetsPlanet()
末级
'''
部分公共类飞机
作为字符串的公共属性名()
公共属性xcood()是否为十进制?
公共属性ycood()是否为十进制?
公共属性站()作为字符串
公共属性spectralClass()作为字符串
公共属性子类型()是否为整数?
公共属性luminosity()作为字符串
公共属性spectralType()作为字符串
以十进制表示的公共弥撒
以十进制表示的公共内部生活
以十进制表示的公共外部生命
以十进制表示的公共slot1
公共slot2作为十进制
以十进制表示的公共slot3
以十进制表示的公共slot4
公共slot5作为十进制
以十进制形式显示的公共slot6
公共时隙7为十进制
公共槽8为十进制
公共槽9为十进制
以十进制表示的公共slot10
以十进制表示的公共slot11
公共slot12为十进制
以十进制表示的公共slot13
以十进制表示的公共slot14
以十进制表示的公共slot15
公共属性nadirCharge()作为字符串
公共属性zenithCharge()作为字符串
公共属性sysPos()是否为整数?
公共属性axis()作为字符串
作为字符串的公共属性轨道()
公共属性压力()为整数?
公共属性重力()为十进制?
公共属性生命形式()是否为整数?
公共属性气候()为整数?
公共属性percentWater()是否为整数?
公共属性温度()为整数?
作为字符串()的公共属性
公共财产卫星()作为PlanetPlanetSetTellite()
作为PlanetPlanetLandmass()的公共财产地块()
公共属性HPGStation()作为字符串
公共属性()作为字符串
公共属性更改()为PlanetPlanetActionChange())
公共属性desc()作为字符串()
末级
'''
部分公共类PlanetPlanetActionChange
私有日期字段作为日期
私有字段作为字符串
公共财产[日期]()作为日期
公共属性()作为字符串
末级
部分公共类飞机飞机卫星
专用卫星场作为字符串
公共属性satellite()作为字符串
末级
部分公共类飞机飞机陆地质量
私有landMassField作为字符串
公共属性landMass()作为字符串
末级
objPlanets.vb

Imports System.Xml.Serialization
'''<remarks/>
<System.SerializableAttribute(),
 System.ComponentModel.DesignerCategoryAttribute("code"),
 System.Xml.Serialization.XmlTypeAttribute(AnonymousType:=True),
 System.Xml.Serialization.XmlRootAttribute("planets", IsNullable:=False)>
Partial Public Class Planets

    Private planetField() As planetsPlanet

    '''<remarks/>
    <System.Xml.Serialization.XmlElementAttribute("planet")>
    Public Property planet() As planetsPlanet()

End Class

'''<remarks/>
<System.SerializableAttribute(),
 System.ComponentModel.DesignerCategoryAttribute("code"),
 System.Xml.Serialization.XmlTypeAttribute(AnonymousType:=True)>
Partial Public Class planetsPlanet

    <System.Xml.Serialization.XmlElementAttribute("name", GetType(String))>
    Public Property name() As String

    <System.Xml.Serialization.XmlElementAttribute("xcood", GetType(Decimal?))>
    Public Property xcood() As Decimal?

    <System.Xml.Serialization.XmlElementAttribute("ycood", GetType(Decimal?))>
    Public Property ycood() As Decimal?

    <System.Xml.Serialization.XmlElementAttribute("station", GetType(String))>
    Public Property station() As String

    <System.Xml.Serialization.XmlElementAttribute("spectralClass", GetType(String))>
    Public Property spectralClass() As String

    <System.Xml.Serialization.XmlElementAttribute("subtype", GetType(Integer?))>
    Public Property subtype() As Integer?

    <System.Xml.Serialization.XmlElementAttribute("luminosity", GetType(String))>
    Public Property luminosity() As String

    <System.Xml.Serialization.XmlElementAttribute("spectralType", GetType(String))>
    Public Property spectralType() As String

    <XmlIgnoreAttribute()>
    Public mass As Decimal
    <XmlIgnoreAttribute()>
    Public innerLife As Decimal
    <XmlIgnoreAttribute()>
    Public outerLife As Decimal
    <XmlIgnoreAttribute()>
    Public slot1 As Decimal
    <XmlIgnoreAttribute()>
    Public slot2 As Decimal
    <XmlIgnoreAttribute()>
    Public slot3 As Decimal
    <XmlIgnoreAttribute()>
    Public slot4 As Decimal
    <XmlIgnoreAttribute()>
    Public slot5 As Decimal
    <XmlIgnoreAttribute()>
    Public slot6 As Decimal
    <XmlIgnoreAttribute()>
    Public slot7 As Decimal
    <XmlIgnoreAttribute()>
    Public slot8 As Decimal
    <XmlIgnoreAttribute()>
    Public slot9 As Decimal
    <XmlIgnoreAttribute()>
    Public slot10 As Decimal
    <XmlIgnoreAttribute()>
    Public slot11 As Decimal
    <XmlIgnoreAttribute()>
    Public slot12 As Decimal
    <XmlIgnoreAttribute()>
    Public slot13 As Decimal
    <XmlIgnoreAttribute()>
    Public slot14 As Decimal
    <XmlIgnoreAttribute()>
    Public slot15 As Decimal

    <System.Xml.Serialization.XmlElementAttribute("nadirCharge", GetType(String))>
    Public Property nadirCharge() As String

    <System.Xml.Serialization.XmlElementAttribute("zenithCharge", GetType(String))>
    Public Property zenithCharge() As String

    <System.Xml.Serialization.XmlElementAttribute("sysPos", GetType(Integer?))>
    Public Property sysPos() As Integer?

    <System.Xml.Serialization.XmlElementAttribute("axis", GetType(String))>
    Public Property axis() As String

    <System.Xml.Serialization.XmlElementAttribute("orbit", GetType(String))>
    Public Property orbit() As String

    <System.Xml.Serialization.XmlElementAttribute("pressure", GetType(Integer?))>
    Public Property pressure() As Integer?

    <System.Xml.Serialization.XmlElementAttribute("gravity", GetType(Decimal?))>
    Public Property gravity() As Decimal?

    <System.Xml.Serialization.XmlElementAttribute("lifeForm", GetType(Integer?))>
    Public Property lifeForm() As Integer?

    <System.Xml.Serialization.XmlElementAttribute("climate", GetType(Integer?))>
    Public Property climate() As Integer?

    <System.Xml.Serialization.XmlElementAttribute("percentWater", GetType(Integer?))>
    Public Property percentWater() As Integer?

    <System.Xml.Serialization.XmlElementAttribute("temperature", GetType(Integer?))>
    Public Property temperature() As Integer?

    <System.Xml.Serialization.XmlElementAttribute("socioIndustrial", GetType(String))>
    Public Property socioIndustrial() As String()

    <System.Xml.Serialization.XmlElementAttribute("satellite", GetType(String))>
    Public Property satellite() As planetsPlanetSatellite()

    <System.Xml.Serialization.XmlElementAttribute("landMass", GetType(String))>
    Public Property landMass() As planetsPlanetLandMass()

    <System.Xml.Serialization.XmlElementAttribute("hpg", GetType(String))>
    Public Property HPGStation() As String

    <System.Xml.Serialization.XmlElementAttribute("faction", GetType(String))>
    Public Property faction() As String

    <System.Xml.Serialization.XmlElementAttribute("factionChange", GetType(planetsPlanetFactionChange))>
    Public Property factionChange() As planetsPlanetFactionChange()

    <System.Xml.Serialization.XmlElementAttribute("desc", GetType(String))>
    Public Property desc() As String()

End Class

'''<remarks/>
<System.SerializableAttribute(),
 System.ComponentModel.DesignerCategoryAttribute("code"),
 System.Xml.Serialization.XmlTypeAttribute(AnonymousType:=True)>
Partial Public Class planetsPlanetFactionChange

    Private dateField As Date

    Private factionField As String

    <System.Xml.Serialization.XmlElementAttribute(DataType:="date")>
    Public Property [date]() As Date

    <System.Xml.Serialization.XmlElementAttribute("faction", GetType(String))>
    Public Property faction() As String

End Class

<System.SerializableAttribute(),
 System.ComponentModel.DesignerCategoryAttribute("code"),
 System.Xml.Serialization.XmlTypeAttribute(AnonymousType:=True)>
Partial Public Class planetsPlanetSatellite

    Private satelliteField As String

    <System.Xml.Serialization.XmlElementAttribute("satellite", GetType(String))>
    Public Property satellite() As String

End Class

<System.SerializableAttribute(),
 System.ComponentModel.DesignerCategoryAttribute("code"),
 System.Xml.Serialization.XmlTypeAttribute(AnonymousType:=True)>
Partial Public Class planetsPlanetLandMass

    Private landMassField As String

    <System.Xml.Serialization.XmlElementAttribute("landMass", GetType(String))>
    Public Property landMass() As String

End Class
Imports System.Xml
Imports System.Xml.Serialization

Class objPlanets

    Private Shared ReadOnly r As New Random()

    Private Sub serialPlanets()

        Dim serial As New XmlSerializer(GetType(Planets))
        Dim p As New Planets
        Dim reader As XmlReader = XmlReader.Create(My.Application.Info.DirectoryPath & "\Planets\planetsTemplate.xml")
        While reader.Read()

            p = serial.Deserialize(reader)

        End While
        reader.Close()

        For Each planet In p.planet()

            If String.IsNullOrEmpty(planet.station()) = True Then

            Else

                Continue For

            End If

            If String.IsNullOrEmpty(planet.spectralClass()) = True AndAlso String.IsNullOrEmpty(planet.spectralType()) = False Then

                planet.spectralClass = planet.spectralType().Substring(0, 1)

            Else

            End If

            If String.IsNullOrEmpty(planet.spectralClass()) = True AndAlso String.IsNullOrEmpty(planet.spectralType()) = True Then

                planet.spectralClass = getSC()

            Else

            End If

            If (planet.subtype() Is Nothing) AndAlso String.IsNullOrEmpty(planet.spectralType()) = False Then

                planet.subtype = planet.spectralType().Substring(1, 1)

            Else

            End If

            If (planet.subtype() Is Nothing) AndAlso String.IsNullOrEmpty(planet.spectralType()) = True Then

                planet.subtype = getST()

            Else

            End If

            If String.IsNullOrEmpty(planet.luminosity()) = True AndAlso String.IsNullOrEmpty(planet.spectralType()) = False Then

                planet.luminosity = planet.spectralType().Substring(2, 2)

            Else

            End If

            If String.IsNullOrEmpty(planet.luminosity()) = True AndAlso String.IsNullOrEmpty(planet.spectralType()) = True Then

                planet.luminosity = getL(planet)

            Else

            End If

            If String.IsNullOrEmpty(planet.spectralType()) = True Then

                planet.spectralType = planet.spectralClass() & planet.subtype() & planet.luminosity()

            Else

            End If

            If planet.sysPos() Is Nothing Then

                planet.sysPos = getSP(planet)

            Else

            End If

            If String.IsNullOrEmpty(planet.axis()) = True Then

                planet.axis = getAxis()

            Else

            End If

            If String.IsNullOrEmpty(planet.orbit()) = True Then

                planet.orbit = getOrbit()

            Else

            End If

            If String.IsNullOrEmpty(planet.faction()) = True Then

                planet.faction = "UND"

            Else

            End If

        Next

        Dim Wsettings As XmlWriterSettings = New XmlWriterSettings()
        Wsettings.Indent = True
        Dim writer As XmlWriter = XmlWriter.Create(My.Application.Info.DirectoryPath & "\Planets\planets.xml", Wsettings)
        serial.Serialize(writer, p)
        writer.Flush()
        writer.Close()

    End Sub

    Private Function getAxis() As String

        Dim r As Integer = roll2D6()
        Select Case r

            Case 2 To 6

                Return "Tilted"

            Case 7 To 12

                Return "No Tilt"

            Case Else

                Return "Error"

        End Select

    End Function

    Private Function getOrbit() As String

        Dim r As Integer = roll2D6()
        Select Case r

            Case 2 To 6

                Return "Elliptical"

            Case 7 To 12

                Return "Circular"

            Case Else

                Return "Error"

        End Select

    End Function

    Private Function getSC() As String

        Dim r As Integer = roll2D6()
        Select Case r

            Case 2 To 4

                Return "M"

            Case 5 To 6

                Return "K"

            Case 7 To 8

                Return "G"

            Case 9 To 11

                Return "F"

            Case 12

                Return getHotStars()

            Case Else

                Return "Error"

        End Select

    End Function

    Private Function getHotStars() As String

        Dim r As Integer = roll2D6()

        If r >= 7 Then

            Return "F"

        Else

            Dim rr As Integer = roll2D6()
            Select Case rr

                Case 2 To 3

                    Return "B"

                Case 4 To 10

                    Return "A"

                Case 11

                    Return "B"

                Case 12

                    Return "F"

                Case Else

                    Return "Error"

            End Select

        End If

    End Function

    Private Function getST() As Integer

        Dim r As Integer = roll2D6()
        Select Case r

            Case 2, 12

                Return 9

            Case 3

                Return 7

            Case 4

                Return 5

            Case 5

                Return 3

            Case 6

                Return 1

            Case 7

                Return 0

            Case 8

                Return 2

            Case 9

                Return 4

            Case 10

                Return 6

            Case 11

                Return 8

            Case Else

                Return 99

        End Select

    End Function

    Private Function getL(planet) As String

        Dim r As Integer = roll2D6()

        If String.Compare(planet.SpectralClass(), "M", True) = 0 AndAlso (r = 2 OrElse r = 4) Then

            While r = 2 OrElse r = 4
                r = roll2D6()
            End While

        ElseIf String.Compare(planet.SpectralClass(), "K", True) = 0 AndAlso planet.subtype() >= 4 AndAlso r = 4 Then

            While r = 4
                r = roll2D6()
            End While

        Else

        End If

        Select Case r

            Case 2

                Return "VII"

            Case 3

                Return "VI"

            Case 4

                Return "IV"

            Case 5 To 8

                Return "V"

            Case 9

                Return "III"

            Case 10

                Return "II"

            Case 11

                Return "Ib"

            Case 12

                Return "Ia"

            Case Else

                Return "Error"

        End Select

    End Function

    Private Function getSP(planet) As Integer

        Dim table As DataTable = StarTable.starTable()
        Dim expression As String = "[Spectral Type] = " & "'" & planet.spectralType() & "'"
        Dim selectRow As DataRow()
        selectRow = table.Select(expression)
        planet.mass = selectRow(0)(1)
        planet.innerLife = selectRow(0)(2)
        planet.outerLife = selectRow(0)(4)
        getOrbitals(planet, table, expression, selectRow)
        Dim arraySlots() As Decimal = {planet.slot1(), planet.slot2(), planet.slot3(), planet.slot4(), planet.slot5(), planet.slot6(), planet.slot7(),
            planet.slot8(), planet.slot9(), planet.slot10(), planet.slot11(), planet.slot12(), planet.slot13(), planet.slot14(), planet.slot15()}
        Dim rollSlots() As Decimal = getSlots(planet)
        For i = 0 To arraySlots.Length - 1

            arraySlots(i) = rollSlots(i)

        Next

        Dim checkLife As Decimal = Array.Find(arraySlots, Function(slot)

                                                              Return slot >= planet.innerLife() AndAlso slot <= planet.outerLife()

                                                          End Function)

        If checkLife = 0 Then

            While checkLife = 0

                rollSlots = getSlots(planet)
                For i = 0 To arraySlots.Length - 1

                    arraySlots(i) = rollSlots(i)

                Next
                checkLife = Array.Find(arraySlots, Function(slot)

                                                       Return slot >= planet.innerLife() AndAlso slot <= planet.outerLife()

                                                   End Function)

            End While

        Else

        End If

        Dim p As Integer = getRandom15()
        If arraySlots(p - 1) < planet.innerLife() OrElse arraySlots(p - 1) > planet.outerLife() Then

            While arraySlots(p - 1) < planet.innerLife() OrElse arraySlots(p - 1) > planet.outerLife()

                p = getRandom15()

            End While

        End If

        Return p

    End Function

    Private Function getRandom15() As Integer

        Return r.Next(1, 16)

    End Function

    Private Sub getOrbitals(planet As Object, table As DataTable, expression As String, selectRow As DataRow())

        If (((4 / 3) ^ 2) ^ (1 / 3) * planet.mass()) > planet.outerLife() Then

            While (((4 / 3) ^ 2) ^ (1 / 3) * planet.mass()) > planet.outerLife()

                planet.spectralClass = getSC()
                planet.subtype = getST()
                planet.luminosity = getL(planet)
                planet.spectralType = planet.spectralClass() & planet.subtype() & planet.luminosity()
                expression = "[Spectral Type] = " & "'" & planet.spectralType() & "'"
                selectRow = table.Select(expression)
                planet.mass = selectRow(0)(1)
                planet.outerLife = selectRow(0)(4)

            End While

        Else

        End If

    End Sub

    Private Function getSlots(planet) As Array

        Dim Slots(14) As Decimal

        For i = 0 To Slots.Length - 1

            If i = 0 Then

                Slots(0) = getResonance() * planet.mass()

            Else

                Slots(i) = getResonance() * Slots(i - 1)

            End If

        Next

        Return Slots

    End Function

    Private Function getResonance() As Decimal

        Dim r As Integer = roll1D10()
        Select Case r

            Case 1

                Return ((4 / 3) ^ 2) ^ (1 / 3)

            Case 2

                Return ((3 / 2) ^ 2) ^ (1 / 3)

            Case 3

                Return ((8 / 5) ^ 2) ^ (1 / 3)

            Case 4

                Return ((5 / 3) ^ 2) ^ (1 / 3)

            Case 5

                Return ((7 / 4) ^ 2) ^ (1 / 3)

            Case 6

                Return ((9 / 5) ^ 2) ^ (1 / 3)

            Case 7

                Return ((2 / 1) ^ 2) ^ (1 / 3)

            Case 8

                Return ((7 / 3) ^ 2) ^ (1 / 3)

            Case 9

                Return ((5 / 2) ^ 2) ^ (1 / 3)

            Case 10

                Return ((3 / 1) ^ 2) ^ (1 / 3)

            Case Else

                Return 0

        End Select

    End Function

    Shared Function roll1D10() As Integer

        Return r.Next(1, 11)

    End Function

    Shared Function roll2D6() As Integer

        Return r.Next(1, 7) + r.Next(1, 7)

    End Function

    Public Sub New()

        serialPlanets()

    End Sub

End Class
Imports System.Xml
导入System.Xml.Xml
类对象
私有共享只读r作为新随机数()
私有子序列号()
Dim serial作为新的XmlSerializer(GetType(Planets))
暗行星
将读卡器设置为XmlReader=XmlReader.Create(My.Application.Info.DirectoryPath&“\Planets\planetsttemplate.xml”)
而reader.Read()
p=串行。反序列化(读卡器)
结束时
reader.Close()
对于p.planet()中的每个行星
如果String.IsNullOrEmpty(planet.station())=True,则
其他的
继续
如果结束
如果String.IsNullOrEmpty(planet.spectralClass())=True,并且String.IsNullOrEmpty(planet.spectralType())=False,那么
planet.spectralClass=planet.spectralType().子字符串(0,1)
其他的
如果结束
如果String.IsNullOrEmpty(planet.spectralClass())=True,并且String.IsNullOrEmpty(planet.spectralType())=True,那么
planet.spectralClass=getSC()
其他的
如果结束
如果(planet.subtype()为Nothing)且字符串.IsNullOrEmpty(planet.spectralType())=False,则
planet.subtype=planet.spectralType().Substrin
<XmlRoot("landMass")>
Partial Public Class planetsPlanetLandMass

    Private landMassField As String

    'fixed
    <System.Xml.Serialization.XmlText()>
    Public landMass As String

End Class