TextTryCast Method
Tries to cast the object specified in the 
basedOn parameter to a 
Boolean.
Namespace: Firefly.BoxAssembly: Firefly.Box (in Firefly.Box.dll) Version: debug-master-v:33791
public static bool TryCast(
	Object basedOn,
	out Text result
)
Public Shared Function TryCast ( 
	basedOn As Object,
	<OutAttribute> ByRef result As Text
) As Boolean
static member TryCast : 
        basedOn : Object * 
        result : Text byref -> bool 
- basedOn  Object
- The Object to cast to Boolean
- result  Text
- The Boolean field to update with the result
BooleanThe method returns true if successful, otherwise return false.
 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.
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();
        }
    }
}