Didn't realize this was already fixed for GACType[MyType].... but it 
still did not work for MyType[MyType] or generics with more than one 
type parameter.

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"Rhino Tools Dev" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to 
[email protected]
For more options, visit this group at 
http://groups.google.com/group/rhino-tools-dev?hl=en
-~----------~----~----~----~------~----~------~--~---

Index: Rhino.ServiceBus.Tests/DefaultReflectionTests.cs
===================================================================
--- Rhino.ServiceBus.Tests/DefaultReflectionTests.cs    (revision 2161)
+++ Rhino.ServiceBus.Tests/DefaultReflectionTests.cs    (working copy)
@@ -72,6 +72,21 @@
                        
                        
Assert.DoesNotContain("Rhino.ServiceBus.Tests,Version=",output.Replace(" ",""));
                }
+               [Fact]
+               public void 
Gets_assembly_name_without_version_for_generic_types_in_local_assemblies()
+               {
+                       var output = 
reflection.GetAssemblyQualifiedNameWithoutVersion(typeof(GenericConsumer<SomeMsg>));
+               
+                       
Assert.DoesNotContain("Rhino.ServiceBus.Tests,Version=", output.Replace(" ", 
""));
+               }
+               [Fact]
+               public void 
Gets_assembly_name_with_more_than_one_type_parameter()
+               {
+                       string name = 
reflection.GetAssemblyQualifiedNameWithoutVersion(typeof(Dictionary<object, 
object>));
+                       Assert.Equal(
+                               typeof(Dictionary<object, 
object>).AssemblyQualifiedName,
+                               name);
+               }
                public class SomeMsg{}
                public class SomeMsgConsumer:GenericConsumer<SomeMsg>{}
                public class GenericConsumer<T>:ConsumerOf<T>
Index: Rhino.ServiceBus/Impl/DefaultReflection.cs
===================================================================
--- Rhino.ServiceBus/Impl/DefaultReflection.cs  (revision 2161)
+++ Rhino.ServiceBus/Impl/DefaultReflection.cs  (working copy)
@@ -3,6 +3,7 @@
 using System.Diagnostics;
 using System.Linq;
 using System.Reflection;
+using System.Text;
 using System.Xml.Linq;
 using Castle.MicroKernel.Proxy;
 using log4net;
@@ -275,34 +276,41 @@
             return typeName.Substring(0,typeName.Length-1);
         }
 
-        public string GetAssemblyQualifiedNameWithoutVersion(Type type)
-        {
-            string value;
-            if(typeToWellKnownTypeName.TryGetValue(type, out value))
-                return value;
+          public string GetAssemblyQualifiedNameWithoutVersion(Type type)
+          {
+                  string value;
+                  if (typeToWellKnownTypeName.TryGetValue(type, out value))
+                          return value;
 
-            Assembly assembly = type.Assembly;
-            if (assembly.GlobalAssemblyCache == false)
-            {
-                string fullName = assembly.FullName ?? assembly.GetName().Name;
-                return type.FullName + ", " + fullName.Split(',')[0];
-            }
-                       var genericParameterNameMap = new 
Dictionary<string,string>();
-                       if(type.IsGenericType)
-                       {
-                               foreach (var argument in 
type.GetGenericArguments())
-                               {
-                                       
genericParameterNameMap.Add(argument.AssemblyQualifiedName,GetAssemblyQualifiedNameWithoutVersion(argument));
-                               }
-                       }
+                  Assembly assembly = type.Assembly;
+                  string fullName = assembly.FullName ?? 
assembly.GetName().Name;
+                  if (type.IsGenericType)
+                  {
+                          var builder = new StringBuilder();
+                          builder.Append(type.Namespace).Append(".")
+                                  .Append(type.Name).Append("[")
+                                  .Append(String.Join(",",
+                                                                  
type.GetGenericArguments()
+                                                                          
.Select(t => "[" + GetAssemblyQualifiedNameWithoutVersion(t) + "]")
+                                                                          
.ToArray()))
+                                  .Append("], ");
+                          if (assembly.GlobalAssemblyCache)
+                          {
+                                  builder.Append(fullName);
+                          }
+                          else
+                          {
+                                  builder.Append(fullName.Split(',')[0]);
+                          }
+                          return builder.ToString();
+                  }
 
-                       var qualified = type.AssemblyQualifiedName;
-               foreach (var genericParamToVersionless in 
genericParameterNameMap)
-               {
-                       qualified = 
qualified.Replace(genericParamToVersionless.Key, 
genericParamToVersionless.Value);
-               }
-               return qualified;
-        }
+                  if (assembly.GlobalAssemblyCache == false)
+                  {
+                          return type.FullName + ", " + fullName.Split(',')[0];
+                  }
+                  return type.AssemblyQualifiedName;
+          }
 
         public IEnumerable<string> GetProperties(object value)
         {

Reply via email to