Statsar Statistics Library

v1.0.1 for .NET

Product Guide



More Information...

Valid XHTML


Import Reflection Example (VB.NET)

[VB.NET]
' COPYRIGHT(C), SIMPLEXAR SOFTWARE LIMITED, 2006-2008.
' All rights reserved.
'
' Use of this copyright notice is precautionary only, and does not imply
' publication or disclosure. The content of this work contains confidential
' and proprietary information of Simplexar Software Limited. Any duplication,
' modification, distribution, or disclosure in any form, in whole, or in part,
' is strictly prohibited without express prior written permission.

' Get namespaces.
Imports System
Imports Simplexar.Statsar

' Start namespace.
Namespace Simplexar.Examples.Statsar

    ' This example loads an array of objects using reflection,
    ' and illustrates how to bind to a custom object model.
    Module Example

        ' The application entry point.
        Public Sub Main()
            Try
                RunExample()
            Catch exception As Exception
                Console.WriteLine(exception)
            End Try
            Console.WriteLine("Press ENTER to terminate.")
            Console.ReadLine()
        End Sub

        Private Sub RunExample()

            ' Create a calculator.
            Dim calculator As New StatsCalculator()

            ' Load an array of a custom data type. The calculator
            ' will use reflection to achieve this.
            Dim sheet As DataSheet = calculator.Load( _
                New Product() { _
                    New Product("Milk", 52, 12.8), _
                    New Product("Cheese", 58, 64.8), _
                    New Product("Bread", 62, 66.9)})
            Console.WriteLine(sheet)

        End Sub

        ' Product is a class with properties name, size and cost.
        Private Class Product

            ' Creates a new product instance.
            Public Sub New( _
                ByVal name As String, ByVal size As Double, _
                ByVal cost As Double)
                _name = name
                _size = size
                _cost = cost
            End Sub

            ' Gets or sets the product name.
            Public Property Name() As String
                Get
                    Return _name
                End Get
                Set(ByVal value As String)
                    _name = value
                End Set
            End Property

            ' Gets or sets the product size.
            Public Property Size() As String
                Get
                    Return _size
                End Get
                Set(ByVal value As String)
                    _size = value
                End Set
            End Property

            ' Gets or sets the product cost.
            Public Property Cost() As String
                Get
                    Return _cost
                End Get
                Set(ByVal value As String)
                    _cost = value
                End Set
            End Property

            Private _size As Double = 0
            Private _cost As Double = 0
            Private _name As String = Nothing

        End Class

    End Module

End Namespace