[This is preliminary documentation and is subject to change.]

Casts the object specified in the o parameter to a Date. If the cast fails an InvalidCastException is thrown

Namespace:  Firefly.Box
Assembly:  Firefly.Box (in Firefly.Box.dll) Version: 3.4.23.6473 (3.4.23.6473)

Syntax

C#
public static Date Cast(
	Object o
)
Visual Basic (Declaration)
Public Shared Function Cast ( _
	o As Object _
) As Date
Visual C++
public:
static Date^ Cast(
	Object^ o
)

Parameters

o
Type: System..::.Object
The Object to cast to Date

Examples

This example demonstrates the deferent aspects of casting
This example is in the form of Unit Tests. It references the NUnit framework. This framework can be downloaded from www.NUnit.org. For more information about unit testing visit: www.NUnit.org.
CopyC#
using System;
using System.Collections.Generic;
using System.Text;
using NUnit.Framework;
using Firefly.Box;
using Firefly.Box.Testing;


namespace TestFirefly.Box.Documentation
{
    [TestFixture]
    public class Cast
    {
        [Test]
        public void CastSuccess()
        {
            object o = 5;
            Number n = Number.Cast(o);
            n.ShouldBe(5);
        }
        [Test]
        [ExpectedException(typeof(InvalidCastException))]
        public void CastFail()
        {
            object o = "5";
            Number n = Number.Cast(o);
        }
        [Test]
        public void TryCastSuccess()
        {
            object o = 5;
            Number n;
            if (Number.TryCast(o, out n))
                n.ShouldBe(5);
            else
                Assert.Fail();
        }
        [Test]
        public void TryCastFail()
        {
            object o = "5";
            Number n;
            if (Number.TryCast(o, out n))
                Assert.Fail();
        }
    }
}

See Also