~ubuntu-branches/ubuntu/trusty/mono-addins/trusty-proposed

« back to all changes in this revision

Viewing changes to Mono.Addins/Mono.Addins.Database/DefaultAssemblyReflector.cs

  • Committer: Bazaar Package Importer
  • Author(s): Jo Shields
  • Date: 2011-04-25 11:11:33 UTC
  • mfrom: (4.1.5 sid)
  • Revision ID: james.westby@ubuntu.com-20110425111133-t05u5p7o5fxx70fu
Tags: 0.6-2
Upload to Unstable

Show diffs side-by-side

added added

removed removed

Lines of Context:
28
28
using System;
29
29
using System.Reflection;
30
30
using System.Collections;
 
31
using System.Collections.Generic;
31
32
 
32
33
namespace Mono.Addins.Database
33
34
{
34
 
        
35
 
        
36
 
        public class DefaultAssemblyReflector: IAssemblyReflector
 
35
        class DefaultAssemblyReflector: IAssemblyReflector
37
36
        {
38
37
                public void Initialize (IAssemblyLocator locator)
39
38
                {
43
42
                {
44
43
                        return Util.LoadAssemblyForReflection (file);
45
44
                }
 
45
                
 
46
                public string[] GetResourceNames (object asm)
 
47
                {
 
48
                        return ((Assembly)asm).GetManifestResourceNames ();
 
49
                }
 
50
                
 
51
                public System.IO.Stream GetResourceStream (object asm, string resourceName)
 
52
                {
 
53
                        return ((Assembly)asm).GetManifestResourceStream (resourceName);
 
54
                }
46
55
 
47
56
                public object[] GetCustomAttributes (object obj, Type type, bool inherit)
48
57
                {
60
69
                                        return att;
61
70
                        return null;
62
71
                }
63
 
 
 
72
                
 
73
                public List<CustomAttribute> GetRawCustomAttributes (object obj, Type type, bool inherit)
 
74
                {
 
75
                        ICustomAttributeProvider aprov = obj as ICustomAttributeProvider;
 
76
                        List<CustomAttribute> atts = new List<CustomAttribute> ();
 
77
                        if (aprov == null)
 
78
                                return atts;
 
79
                        
 
80
                        foreach (object at in aprov.GetCustomAttributes (type, inherit))
 
81
                                atts.Add (ConvertAttribute (at));
 
82
 
 
83
                        return atts;
 
84
                }
 
85
 
 
86
                CustomAttribute ConvertAttribute (object ob)
 
87
                {
 
88
                        CustomAttribute at = new CustomAttribute ();
 
89
                        Type type = ob.GetType ();
 
90
                        at.TypeName = type.FullName;
 
91
                        
 
92
                        foreach (PropertyInfo prop in type.GetProperties (BindingFlags.Public | BindingFlags.Instance)) {
 
93
                                object val = prop.GetValue (ob, null);
 
94
                                if (val != null) {
 
95
                                        NodeAttributeAttribute bt = (NodeAttributeAttribute) Attribute.GetCustomAttribute (prop, typeof(NodeAttributeAttribute), true);
 
96
                                        if (bt != null) {
 
97
                                                string name = string.IsNullOrEmpty (bt.Name) ? prop.Name : bt.Name;
 
98
                                                at [name] = Convert.ToString (val, System.Globalization.CultureInfo.InvariantCulture);
 
99
                                        }
 
100
                                }
 
101
                        }
 
102
                        foreach (FieldInfo field in type.GetFields (BindingFlags.Public | BindingFlags.Instance)) {
 
103
                                object val = field.GetValue (ob);
 
104
                                if (val != null) {
 
105
                                        NodeAttributeAttribute bt = (NodeAttributeAttribute) Attribute.GetCustomAttribute (field, typeof(NodeAttributeAttribute), true);
 
106
                                        if (bt != null) {
 
107
                                                string name = string.IsNullOrEmpty (bt.Name) ? field.Name : bt.Name;
 
108
                                                at [name] = Convert.ToString (val, System.Globalization.CultureInfo.InvariantCulture);
 
109
                                        }
 
110
                                }
 
111
                        }
 
112
                        return at;
 
113
                }
 
114
                
64
115
                public string GetTypeName (object type)
65
116
                {
66
117
                        return ((Type)type).Name;