Free cookie consent management tool by TermsFeed Policy Generator

source: branches/HeuristicLab.Problems.GrammaticalOptimization/SharpVectorCore/Utils/Casting.cs @ 12762

Last change on this file since 12762 was 12762, checked in by aballeit, 9 years ago

#2283 GUI updates, Tree-chart, MCTS Version 2 (prune leaves)

File size: 902 bytes
Line 
1using System;
2using System.Collections.Generic;
3
4namespace SharpVectors
5{
6    public static class TryCast
7    {
8        public static bool Cast<B, D>(B baseObject, out D derivedObject)
9            where D : class
10        {
11            if (baseObject == null)
12            {
13                derivedObject = null;
14                return false;
15            }
16
17            derivedObject = baseObject as D;
18
19            return (derivedObject != null);
20        }
21    }
22
23    public static class DynamicCast
24    {
25        public static bool Cast<B, D>(B baseObject, out D derivedObject)
26            where D : class, B
27        {
28            if (baseObject == null)
29            {
30                derivedObject = null;
31                return false;
32            }
33
34            derivedObject = baseObject as D;
35
36            return (derivedObject != null);
37        }
38    }
39}
Note: See TracBrowser for help on using the repository browser.