public void Visualizer_MapTypeFromAssembly_Should_Map_All_Types()
        {
            var debuggerVisualizerTargetName = Path.Combine(_thisAssemblyDirectoryName, "TestC.dll");
            var visualizerLocation = typeof(DynamicDebuggerVisualizerObjectSourceV11).Assembly.Location;
            var injector = new VisualizerAttributeInjector(visualizerLocation);

         
            injector.MapTypesFromAssembly(_thisAssemblyLocation);
            injector.SaveDebuggerVisualizer(debuggerVisualizerTargetName);

            var generatedAssembly = AssemblyDefinition.ReadAssembly(debuggerVisualizerTargetName);
            var currentAssemblytypes = 
                GetType()
                .Assembly
                .GetTypes()
                .Where(typeDef => typeDef.IsPublic && !typeDef.IsInterface && !typeDef.IsAbstract);

            var mappedTypeNames = generatedAssembly
                .CustomAttributes
                .SelectMany(p =>
                    p.Properties.Where(n => n.Name.Equals("TargetTypeName"))
                    .Select(l => l.Argument.Value.ToString()));

            var allTypesArePresent = currentAssemblytypes
                .All(type =>
                    mappedTypeNames.Any(mappedType => mappedType.Equals(type.AssemblyQualifiedName)));

            Assert.IsTrue(allTypesArePresent);
        }
        public void Visualizer_MapType_Should_Create_DegguberVisualizerAttribute_OfType_IList_In_Target_Assembly()
        {
            var debuggerVisualizerTargetName = Path.Combine(_thisAssemblyDirectoryName, "TestB.dll");
            var visualizerLocation = typeof(DynamicDebuggerVisualizerObjectSourceV11).Assembly.Location;
            var injector = new VisualizerAttributeInjector(visualizerLocation);
            injector.MapType(typeof(IList<>));
            injector.SaveDebuggerVisualizer(debuggerVisualizerTargetName);

            var generatedAssembly = AssemblyDefinition.ReadAssembly(debuggerVisualizerTargetName);
            var mappedTypeNames = generatedAssembly
                .CustomAttributes
                .SelectMany(p =>
                    p.Properties.Where(n => n.Name.Equals("TargetTypeName"))
                    .Select(l => l.Argument.Value));

            Assert.IsTrue(mappedTypeNames.Contains(typeof(IList<>).AssemblyQualifiedName), "Mapping was not succesful");
        }
Exemplo n.º 3
0
        /// <summary>
        /// Maps the dot net framework types. If the file already exists for a given vs version it won't be
        /// regenerated.
        /// </summary>
        /// <param name="targetVisualizerInstallationPath">The target visualizer installation path.</param>
        /// <param name="vsVersion">The vs version.</param>
        /// <param name="sourceVisualizerAssemblyLocation">The source visualizer assembly location.</param>
        /// <returns></returns>
        public static void MapDotNetFrameworkTypes(IEnumerable<string> targetVisualizerInstallationPath,
            string vsVersion, string sourceVisualizerAssemblyLocation)
        {
            if (targetVisualizerInstallationPath == null)
                throw new ArgumentException(@"Installation Path/s cannot be null", "targetVisualizerInstallationPath");

            if (string.IsNullOrEmpty(vsVersion))
                throw new ArgumentException(@"Visual Studio Version cannot be null", "vsVersion");

            if (string.IsNullOrEmpty(sourceVisualizerAssemblyLocation))
                throw new ArgumentException(@"Visualizer Assembly Location cannot be null",
                    "sourceVisualizerAssemblyLocation");


            var visualizerFileName = string.Format(DotNetFrameworkVisualizerName, vsVersion);

            var visualizerInstallationPath = targetVisualizerInstallationPath as IList<string> ??
                                             targetVisualizerInstallationPath.ToList();

            var visualizerInjector = new VisualizerAttributeInjector(sourceVisualizerAssemblyLocation);

            //Map all the possible System  types
            var systemLinqTypes = typeof(IOrderedEnumerable<>).Assembly
                .GetTypes()
                .Where(type => type != null
                               && (
                                   (type.IsClass && type.IsSerializable)
                                   ||
                                   type.IsInterface
                                   ||
                                   type.Name.Contains("Iterator")
                                  )
                               && !(type.Name.Contains("Func") || type.Name.Contains("Action"))
                               && !string.IsNullOrEmpty(type.Namespace));

            //Map all the possible list types
            var systemGenericsTypes = typeof(IList<>).Assembly
                .GetTypes()
                .Where(type => type != null
                               && (
                                   (type.IsClass && type.IsSerializable)
                                   ||
                                   type.IsInterface
                                  )
                               && !string.IsNullOrEmpty(type.Namespace)
                               && type.IsPublic)
                .Where(type =>
                    !type.Name.Contains("ValueType")
                    && !type.Name.Contains("IFormattable")
                    && !type.Name.Contains("IComparable")
                    && !type.Name.Contains("IConvertible")
                    && !type.Name.Contains("IEquatable")
                    && !type.Name.Contains("Object")
                    && !type.Name.Contains("ICloneable")
                    && !type.Name.Contains("String")
                    && !type.Name.Contains("IDisposable"));


            systemLinqTypes.ForEach(visualizerInjector.MapType);
            systemGenericsTypes.ForEach(visualizerInjector.MapType);

            visualizerInstallationPath.ForEach(debuggerVisualizerPath =>
            {
                CreateDirWithPermission(debuggerVisualizerPath);
                var location = Path.Combine(debuggerVisualizerPath, visualizerFileName);
                visualizerInjector.SaveDebuggerVisualizer(location);
            });
        }
Exemplo n.º 4
0
 /// <summary>
 /// Initializes a new instance of the <see cref="VisualizerTypeMapper"/> class.
 /// </summary>
 /// <param name="sourceVisualizerAssemblyLocation"></param>
 public VisualizerTypeMapper(string sourceVisualizerAssemblyLocation)
 {
     Log.Configure("LINQBridgeVs", "Type Mapper");
     _visualizerAttributeInjector = new VisualizerAttributeInjector(sourceVisualizerAssemblyLocation);
 }
Exemplo n.º 5
0
        /// <summary>
        /// Maps the dot net framework types. If the file already exists for a given vs version it won't be
        /// regenerated.
        /// </summary>
        /// <param name="targetVisualizerInstallationPath">The target visualizer installation path.</param>
        /// <param name="vsVersion">The vs version.</param>
        /// <param name="sourceVisualizerAssemblyLocation">The source visualizer assembly location.</param>
        /// <returns></returns>
        public static void MapDotNetFrameworkTypes(IEnumerable <string> targetVisualizerInstallationPath,
                                                   string vsVersion, string sourceVisualizerAssemblyLocation)
        {
            if (targetVisualizerInstallationPath == null)
            {
                throw new ArgumentException(@"Installation Path/s cannot be null", "targetVisualizerInstallationPath");
            }

            if (string.IsNullOrEmpty(vsVersion))
            {
                throw new ArgumentException(@"Visual Studio Version cannot be null", "vsVersion");
            }

            if (string.IsNullOrEmpty(sourceVisualizerAssemblyLocation))
            {
                throw new ArgumentException(@"Visualizer Assembly Location cannot be null",
                                            "sourceVisualizerAssemblyLocation");
            }


            var visualizerFileName = string.Format(DotNetFrameworkVisualizerName, vsVersion);

            var visualizerInstallationPath = targetVisualizerInstallationPath as IList <string> ??
                                             targetVisualizerInstallationPath.ToList();

            var visualizerInjector = new VisualizerAttributeInjector(sourceVisualizerAssemblyLocation);

            //Map all the possible System  types
            var systemLinqTypes = typeof(IOrderedEnumerable <>).Assembly
                                  .GetTypes()
                                  .Where(type => type != null &&
                                         (
                                             (type.IsClass && type.IsSerializable)
                                             ||
                                             type.IsInterface
                                             ||
                                             type.Name.Contains("Iterator")
                                         ) &&
                                         !(type.Name.Contains("Func") || type.Name.Contains("Action")) &&
                                         !string.IsNullOrEmpty(type.Namespace));

            //Map all the possible list types
            var systemGenericsTypes = typeof(IList <>).Assembly
                                      .GetTypes()
                                      .Where(type => type != null &&
                                             (
                                                 (type.IsClass && type.IsSerializable)
                                                 ||
                                                 type.IsInterface
                                             ) &&
                                             !string.IsNullOrEmpty(type.Namespace) &&
                                             type.IsPublic)
                                      .Where(type =>
                                             !type.Name.Contains("ValueType") &&
                                             !type.Name.Contains("IFormattable") &&
                                             !type.Name.Contains("IComparable") &&
                                             !type.Name.Contains("IConvertible") &&
                                             !type.Name.Contains("IEquatable") &&
                                             !type.Name.Contains("Object") &&
                                             !type.Name.Contains("ICloneable") &&
                                             !type.Name.Contains("String") &&
                                             !type.Name.Contains("IDisposable"));


            systemLinqTypes.ForEach(visualizerInjector.MapType);
            systemGenericsTypes.ForEach(visualizerInjector.MapType);

            visualizerInstallationPath.ForEach(debuggerVisualizerPath =>
            {
                CreateDirWithPermission(debuggerVisualizerPath);
                var location = Path.Combine(debuggerVisualizerPath, visualizerFileName);
                visualizerInjector.SaveDebuggerVisualizer(location);
            });
        }
Exemplo n.º 6
0
 /// <summary>
 /// Initializes a new instance of the <see cref="VisualizerTypeMapper"/> class.
 /// </summary>
 /// <param name="sourceVisualizerAssemblyLocation"></param>
 public VisualizerTypeMapper(string sourceVisualizerAssemblyLocation)
 {
     Log.Configure("LINQBridgeVs", "Type Mapper");
     _visualizerAttributeInjector = new VisualizerAttributeInjector(sourceVisualizerAssemblyLocation);
 }