コード例 #1
0
ファイル: Program.cs プロジェクト: OpenSharp/UnitWrappers
        //TODO: add extensions methods calculator
        static void Main(string[] args)
        {
            // stripped out interface version of some framework class with less control above underlying instance
            // no corresponding direct implementation
            var narrowMembers = new[] { typeof(IDispatcherService).FullName, typeof(ILocalProcessSystem).FullName,typeof(IWindowState).FullName,typeof(ILocalProcess).FullName };

            // static members and constuctors of class
            var staticMembers = "System";

            // namespace wide factories
            string factory = "Factory";
            // base classes when wrapping abstract types like Stream
            string abstractBase = "Base";


            Assembly unitWrappers = typeof(IDateTimeSystem).Assembly;
            Assembly wpfWrappers = typeof(IDispatcher).Assembly;

            IEnumerable<Assembly> unitRefrencedAssemblies = unitWrappers.GetReferencedAssemblies().Select(Assembly.Load);
            IEnumerable<Assembly> wpfRefrencedAssemblies = wpfWrappers.GetReferencedAssemblies().Select(Assembly.Load);

            var unitClasses =
                from r in unitRefrencedAssemblies
                from t in r.GetExportedTypes()
                orderby t.FullName
                select t;

            var wpfClasses =
    from r in wpfRefrencedAssemblies
    from t in r.GetExportedTypes()
    orderby t.FullName
    select t;

            var frameworkClasses = unitClasses.Union(wpfClasses).ToArray();

            var unitInterfaces = unitWrappers.GetExportedTypes().Where(x => x.IsInterface);
            var wpfInterfaces = wpfWrappers.GetExportedTypes().Where(x => x.IsInterface);

            var wrapInterfaces = unitInterfaces.Union(wpfInterfaces);

            var strippedInterfaceNames = wrapInterfaces
                                        .Where(x => !narrowMembers.Contains(x.FullName))
                                        .Select(x => x.Name)
                                        .Select(x =>
                                                                          {
                                                                              string name = x.Remove(0, 1); // remove I
                                                                              name = cutEnd(name, staticMembers);
                                                                              return name;
                                                                          })
                                                                             .Distinct()
                                                                           
                                                                             .ToArray();
            // next dictionary should be 
            // framework type short name = collection of correspoding wrap interfaces
            var combinedInterfaces = new Dictionary<string, Type[]>();
            foreach (var name in strippedInterfaceNames)
            {
                var wraps = new List<Type>();
                foreach (var i in wrapInterfaces)
                {
                    if (i.Name.Equals("I" + name) || i.Name.Equals("I" + name + staticMembers))
                    {
                        wraps.Add(i);
                    }
                }
                combinedInterfaces.Add(name, wraps.ToArray());
            }

            // next dictionary should be 
            // framework type= collection of correspoding wrap classes
            var counterParts = new List<FrameworkWrapsMap>();
            foreach (var wraps in combinedInterfaces)
            {
                string frameworkNameSpace = wraps.Value[0].Namespace.Replace("UnitWrappers.", "");
                string frameworkTypeName = frameworkNameSpace + "." + wraps.Key;

                // exclude namespace wide factories
                if (wraps.Key.EndsWith(factory)
                    && frameworkNameSpace.EndsWith(wraps.Key.Replace(factory, "")))
                {
                    continue;
                }
                 // exclude namespace wide factories
                if (wraps.Key.EndsWith(abstractBase)
                    && frameworkNameSpace.EndsWith(wraps.Key.Replace(abstractBase, "")))
                {
                    continue;
                }
                

                // exclude utilitary types
                var accessor = typeof (IWrap<>).Name.Remove(0, 1);
                if (wraps.Key.StartsWith(accessor))
                {
                    continue;
                }
                var type = frameworkClasses.Where(x => x.FullName == frameworkTypeName).Single();
                counterParts.Add(new FrameworkWrapsMap(type, wraps.Value));
            }

            counterParts = counterParts.OrderBy(x => x.Wrapped.FullName).ToList();
            
            var output = "Coverage.txt";
            using (var fileStream = new FileStreamWrap(output, FileMode.Create))
            {
                using (StreamWriterWrap streamWriter = new StreamWriterWrap(fileStream))
                {
                    streamWriter.WriteLine("Total number of wraps: " + counterParts.Count);
                    foreach (var counterPart in counterParts)
                    {
                        string entry = CalculateEntry(counterPart.Wrapped, counterPart.Wraps);
                        streamWriter.WriteLine(entry);
                        streamWriter.WriteLine();
                        streamWriter.Flush();
                    }

                }
            }
            Console.WriteLine("See " + output);
            Console.ReadKey();
        }
コード例 #2
0
 internal static IFileStream[] ConvertFileStreamArrayIntoIFileStreamWrapArray(FileStream[] fileStreams)
 {
     var fileStreamWraps = new FileStreamWrap[fileStreams.Length];
     for (int i = 0; i < fileStreams.Length; i++)
         fileStreamWraps[i] = new FileStreamWrap(fileStreams[i]);
     return fileStreamWraps;
 }