[corlib] Avoid unnecessary ephemeron array resizes
[mono.git] / mcs / class / referencesource / System.Activities.Presentation / System.Activities.Presentation / System / Activities / Presentation / Toolbox / ActivityTemplateFactoryExtension.cs
1 //----------------------------------------------------------------
2 // Copyright (c) Microsoft Corporation.  All rights reserved.
3 //----------------------------------------------------------------
4
5 namespace System.Activities.Presentation
6 {
7     static class ActivityTemplateFactoryExtension
8     {
9         public static bool IsActivityTemplateFactory(this Type type)
10         {
11             return type.GetInterface(typeof(IActivityTemplateFactory).FullName) != null || 
12                    type.GetInterface(typeof(IActivityTemplateFactory<>).FullName) != null;
13         }
14
15         public static bool TryGetActivityTemplateFactory(this Type type, out Type argumentType)
16         {
17             if (type.GetInterface(typeof(IActivityTemplateFactory).FullName) != null)
18             {
19                 // Hard coding here, because we don't want to create instance before dropped. Suggestion is to use IActivityTemplateFactory<> instead.
20                 argumentType = typeof(Activity);
21                 return true;
22             }
23
24             Type activityFactoryInterfaceType = type.GetInterface(typeof(IActivityTemplateFactory<>).FullName);
25             if (activityFactoryInterfaceType != null)
26             {
27                 argumentType = activityFactoryInterfaceType.GetGenericArguments()[0];
28                 return true;
29             }
30
31             argumentType = null;
32             return false;
33         }
34     }
35 }