summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMaarten Bosmans <mkbosmans@gmail.com>2009-12-24 17:59:18 +0100
committerSebastian Dröge <sebastian.droege@collabora.co.uk>2010-01-04 09:55:29 +0100
commit0ab40256cdfc17d8f89f6e2caa0b74ea54837e57 (patch)
treee7124688abca75f8f0d8e3ee724ac956b2bf9c20
parent8b1869533d514f674261a7e73f93c749cdee914b (diff)
Only look for types in assemblies that reference gstreamer-sharp
-rw-r--r--gstreamer-sharp/Application.cs58
1 files changed, 35 insertions, 23 deletions
diff --git a/gstreamer-sharp/Application.cs b/gstreamer-sharp/Application.cs
index 4ada6f0..c6d0fa2 100644
--- a/gstreamer-sharp/Application.cs
+++ b/gstreamer-sharp/Application.cs
@@ -14,6 +14,7 @@ using System;
using System.Reflection;
using System.IO;
using System.Runtime.InteropServices;
+using System.Collections.Generic;
namespace Gst {
@@ -57,36 +58,47 @@ namespace Gst {
gst_deinit();
}
+ private static Dictionary<string,bool> AssemblyReferencesGstreamerSharp = new Dictionary<string,bool> ();
+
+ private static bool CheckAssemblyReferences (Assembly asm)
+ {
+ bool result = false;
+ AssemblyName asm_name = asm.GetName ();
+
+ // If already visited, return immediately
+ if (AssemblyReferencesGstreamerSharp.ContainsKey (asm_name.FullName))
+ return AssemblyReferencesGstreamerSharp[asm_name.FullName];
+
+ AssemblyReferencesGstreamerSharp.Add (asm_name.FullName, false);
+
+ // Result is true for gstreamer-sharp or if a referenced assembly results in true
+ if (asm_name.Name == "gstreamer-sharp")
+ result = true;
+ foreach (AssemblyName ref_name in asm.GetReferencedAssemblies ()) {
+ try {
+ result = result | CheckAssemblyReferences (Assembly.Load (ref_name));
+ } catch {
+ /* Failure to load a referenced assembly is not an error */
+ }
+ }
+
+ if (result)
+ AssemblyReferencesGstreamerSharp[asm_name.FullName] = true;
+ return result;
+ }
+
private static System.Type GstResolveType (Gst.GLib.GType gtype, string gtype_name) {
Assembly[] assemblies = (Assembly[]) AppDomain.CurrentDomain.GetAssemblies ().Clone ();
+ // Make sure all loaded assemblies are in the Dictionary
foreach (Assembly asm in assemblies) {
- Type[] ts = asm.GetTypes ();
- foreach (Type t in ts) {
- if (t.IsDefined (typeof (Gst.GTypeNameAttribute), false)) {
- GTypeNameAttribute gattr = (GTypeNameAttribute) Attribute.GetCustomAttribute (t, typeof (GTypeNameAttribute), false);
- if (gtype_name.Equals (gattr.TypeName)) {
- return t;
- }
- }
- }
+ CheckAssemblyReferences (asm);
}
- foreach (Assembly asm in assemblies) {
- foreach (AssemblyName ref_name in asm.GetReferencedAssemblies ()) {
+ foreach (string key in AssemblyReferencesGstreamerSharp.Keys) {
+ if (AssemblyReferencesGstreamerSharp[key]) {
try {
- Assembly ref_asm;
- if (asm.Location != String.Empty)
- {
- string asm_file = Path.Combine(Path.GetDirectoryName(asm.Location), ref_name.Name + ".dll");
- if (File.Exists(asm_file))
- ref_asm = Assembly.LoadFrom(asm_file);
- else
- ref_asm = Assembly.Load(ref_name);
- }
- else
- ref_asm = Assembly.Load(ref_name);
-
+ Assembly asm = Assembly.Load (key);
Type[] ts = asm.GetTypes ();
foreach (Type t in ts) {
if (t.IsDefined (typeof (Gst.GTypeNameAttribute), false)) {