29
29
using System.Reflection;
30
30
using System.Collections;
31
using System.Collections.Generic;
32
33
namespace Mono.Addins.Database
36
public class DefaultAssemblyReflector: IAssemblyReflector
35
class DefaultAssemblyReflector: IAssemblyReflector
38
37
public void Initialize (IAssemblyLocator locator)
44
43
return Util.LoadAssemblyForReflection (file);
46
public string[] GetResourceNames (object asm)
48
return ((Assembly)asm).GetManifestResourceNames ();
51
public System.IO.Stream GetResourceStream (object asm, string resourceName)
53
return ((Assembly)asm).GetManifestResourceStream (resourceName);
47
56
public object[] GetCustomAttributes (object obj, Type type, bool inherit)
73
public List<CustomAttribute> GetRawCustomAttributes (object obj, Type type, bool inherit)
75
ICustomAttributeProvider aprov = obj as ICustomAttributeProvider;
76
List<CustomAttribute> atts = new List<CustomAttribute> ();
80
foreach (object at in aprov.GetCustomAttributes (type, inherit))
81
atts.Add (ConvertAttribute (at));
86
CustomAttribute ConvertAttribute (object ob)
88
CustomAttribute at = new CustomAttribute ();
89
Type type = ob.GetType ();
90
at.TypeName = type.FullName;
92
foreach (PropertyInfo prop in type.GetProperties (BindingFlags.Public | BindingFlags.Instance)) {
93
object val = prop.GetValue (ob, null);
95
NodeAttributeAttribute bt = (NodeAttributeAttribute) Attribute.GetCustomAttribute (prop, typeof(NodeAttributeAttribute), true);
97
string name = string.IsNullOrEmpty (bt.Name) ? prop.Name : bt.Name;
98
at [name] = Convert.ToString (val, System.Globalization.CultureInfo.InvariantCulture);
102
foreach (FieldInfo field in type.GetFields (BindingFlags.Public | BindingFlags.Instance)) {
103
object val = field.GetValue (ob);
105
NodeAttributeAttribute bt = (NodeAttributeAttribute) Attribute.GetCustomAttribute (field, typeof(NodeAttributeAttribute), true);
107
string name = string.IsNullOrEmpty (bt.Name) ? field.Name : bt.Name;
108
at [name] = Convert.ToString (val, System.Globalization.CultureInfo.InvariantCulture);
64
115
public string GetTypeName (object type)
66
117
return ((Type)type).Name;