[runtime] Fix corlib out of date error with disabled COM
[mono.git] / mcs / class / referencesource / System.Activities.Presentation / System.Activities.Presentation / System / Activities / Presentation / Model / AttachedPropertiesService.cs
1 //----------------------------------------------------------------
2 // Copyright (c) Microsoft Corporation.  All rights reserved.
3 //----------------------------------------------------------------
4
5 namespace System.Activities.Presentation.Model
6 {
7     using System;
8     using System.Collections.Generic;
9     using System.Linq;
10     using System.Text;
11     using System.Runtime;
12     
13     public class AttachedPropertiesService
14     {
15         List<AttachedProperty> properties;
16
17         public AttachedPropertiesService()
18         {
19             this.properties = new List<AttachedProperty>();
20         }
21
22         public void AddProperty(AttachedProperty property)
23         {
24             if (property == null)
25             {
26                 throw FxTrace.Exception.AsError(new ArgumentNullException("property"));
27             }
28             if (string.IsNullOrEmpty(property.Name))
29             {
30                 throw FxTrace.Exception.AsError(new ArgumentException(SR.AttachedPropertyNameShouldNotBeEmpty));
31             }
32             this.properties.Add(property);
33         }
34
35         internal IEnumerable<AttachedProperty> GetAttachedProperties(Type modelItemType)
36         {
37             var properties = from property in this.properties
38                 where property.OwnerType.IsAssignableFrom(modelItemType) select property;
39
40             if (modelItemType.IsGenericType)
41             {
42                 var propertiesFromGenericRoot = from property in this.properties
43                                                 where property.OwnerType.IsAssignableFrom(modelItemType.GetGenericTypeDefinition())
44                                                 select property;
45                 properties = properties.Concat(propertiesFromGenericRoot).Distinct();
46             }
47
48             return properties;
49         }
50     }
51
52 }