예제 #1
0
 public void ScanAssembly(IAssembly assembly)
 {
     foreach (var type in assembly.GetAllTypes())
     {
         ScanType(type);
     }
 }
예제 #2
0
 public override void TraverseChildren(IAssembly assembly)
 {
     foreach (var t in assembly.GetAllTypes())
     {
         this.Traverse(t);
     }
 }
예제 #3
0
        public override void Visit(IAssembly assembly)
        {
            AppendElementType(assembly);
            output.Append(assembly.Name.Value);

            Visit(assembly.GetAllTypes());
            System.Console.WriteLine(output);
        }
예제 #4
0
        static internal AssemblyReport CreateAssemblyReportFromRTA(IAssembly assembly, RapidTypeAnalysis rta)
        {
            AssemblyReport report = new AssemblyReport(assembly);

            int totalTypes   = 0;
            int totalFields  = 0;
            int totalMethods = 0;

            foreach (var t in assembly.GetAllTypes())
            {
                totalTypes++;
                if (rta.ReachableTypes().Contains(t) == false)
                {
                    report.UnreachableTypes.Add(t);
                    //Console.WriteLine("Unused type {0}", t);
                }
                else
                {
                    report.ReachableTypes.Add(t);
                }

                if (t.IsClass || t.IsStruct)
                {
                    foreach (var f in t.Fields)
                    {
                        totalFields++;
                        if (rta.ReachableFields().Contains(f) == false)
                        {
                            report.UnreachableFields.Add(f);
                            //Console.WriteLine("Unused field {0}", f);
                        }
                        else
                        {
                            report.ReachableFields.Add(f);
                        }
                    }

                    foreach (var m in t.Methods)
                    {
                        if (!m.IsAbstract)
                        {
                            totalMethods++;
                            if (rta.MethodIsReachable(m) == false)
                            {
                                report.UnreachableMethods.Add(m);
                                //Console.WriteLine("Unreachable method {0}", m);
                            }
                            else
                            {
                                report.ReachableMethods.Add(m);
                            }
                        }
                    }
                }
            }

            return(report);
        }
        public static bool IsFacade(this IAssembly assembly)
        {
            if (assembly.GetAllTypes().Any(t => t.Name.Value != "<Module>"))
            {
                return(false);
            }

            return(true);
        }
예제 #6
0
 public static INamedTypeDefinition GetTypeDefinition(this IAssembly assembly, Type type)
 {
     return((
                from t in assembly.GetAllTypes()
                let name = TypeHelper.GetTypeName(t, NameFormattingOptions.UseGenericTypeNameSuffix)
                           where name == type.FullName
                           select t
                ).First());
 }
예제 #7
0
        public static bool IsFacade(this IAssembly assembly)
        {
            if (assembly.GetAllTypes().Any(t => t.Name.Value != "<Module>"))
            {
                return(false);
            }

            Contract.Assert(assembly.ExportedTypes.Any());
            return(true);
        }
예제 #8
0
 private IEnumerable <IMethodDefinition> GetAllMethodsInAssembly(IAssembly assembly)
 {
     foreach (ITypeDefinition typeDefinition in assembly.GetAllTypes())
     {
         foreach (IMethodDefinition method in typeDefinition.Methods)
         {
             yield return(method);
         }
     }
 }
예제 #9
0
 private IEnumerable <IFieldDefinition> GetAllFieldsInAssembly(IAssembly assembly)
 {
     foreach (ITypeDefinition typeDefinition in assembly.GetAllTypes())
     {
         foreach (IFieldDefinition field in typeDefinition.Fields)
         {
             yield return(field);
         }
     }
 }
예제 #10
0
        private static IEnumerable <string> GetPublicVisibleTypes(IAssembly contractAssembly)
        {
            var typeForwardsToForward = contractAssembly.ExportedTypes.Select(alias => alias.AliasedType)
                                        .OfType <INamespaceTypeReference>();

            var typesToForward = contractAssembly.GetAllTypes().Where(t => TypeHelper.IsVisibleOutsideAssembly(t))
                                 .OfType <INamespaceTypeDefinition>();

            return(typeForwardsToForward.Concat(typesToForward)
                   .Select(type => TypeHelper.GetTypeName(type, NameFormattingOptions.UseGenericTypeNameSuffix)).ToList());
        }
예제 #11
0
 /// <summary>
 /// This is "ugly" but I don't know how to query a type by name
 /// Inspired in Zvonimir code
 /// </summary>
 /// <param name="host"></param>
 public static void InitializeScopeTypes(IMetadataHost host, IAssembly scopeRuntime)
 {
     foreach (var type in scopeRuntime.GetAllTypes())
     {
         if (type.GetFullName() == "ScopeRuntime.Reducer")
         {
             Reducer = type;
         }
         else if (type.GetFullName() == "ScopeRuntime.Processor")
         {
             Processor = type;
         }
         else if (type.GetFullName() == "ScopeRuntime.Producer")
         {
             Producer = type;
         }
         else if (type.GetFullName() == "ScopeRuntime.Row")
         {
             Row = type;
         }
         else if (type.GetFullName() == "ScopeRuntime.RowSet")
         {
             RowSet = type;
         }
         else if (type.GetFullName() == "ScopeRuntime.RowList")
         {
             RowList = type;
         }
         else if (type.GetFullName() == "ScopeRuntime.ColumnData")
         {
             ColumnData = type;
         }
         else if (type.GetFullName() == "ScopeRuntime.ColumnData<T>")
         {
             ColumnData_Generic = type;
         }
         else if (type.GetFullName() == "ScopeRuntime.Schema")
         {
             Schema = type;
         }
         else if (type.GetFullName() == "ScopeRuntime.Combiner")
         {
             Combiner = type;
         }
         else if (type.GetFullName() == "ScopeRuntime.ScopeMap<K, V>")
         {
             ScopeMap = type;
         }
         if (type.ContainingNamespace() == "ScopeRuntime")
         {
             scopeTypes.Add(type);
         }
     }
 }
예제 #12
0
        public static bool IsFacade(this IAssembly assembly)
        {
            if (assembly.GetAllTypes().Any(t => t.Name.Value != "<Module>"))
            {
                return(false);
            }

            // Don't assert here -- turns out empty assemblies are a thing.
            // Contract.Assert(assembly.ExportedTypes.Any());

            return(assembly.ExportedTypes.Any());
        }
예제 #13
0
파일: Assert.cs 프로젝트: ugurak/nemerle
        public TypeVerifier Type(string typeName, int genericParamsCount, Action <ITypeDefinition> typeVerifier)
        {
            var types      = assembly.GetAllTypes().Where(t => t.Name.Value == typeName);
            var targetType = types.FirstOrDefault(t => t.GenericParameterCount == genericParamsCount);

            if (targetType == null)
            {
                throw new ArgumentException(string.Format("Type {0} not found", typeName));
            }
            typeVerifier(targetType);
            return(new TypeVerifier(this, targetType, env));
        }
예제 #14
0
 public AssemblyBuilder Load(IAssembly assembly) {
   //first create (but do not initialize) all typeBuilder builders, since they are needed to create member builders.
   this.typeBuilderAllocator.Traverse(assembly);
   //next create (but do not initialize) builder for all other kinds of typeBuilder members, since there may be forward references during initialization
   this.memberBuilderAllocator.Traverse(assembly);
   //now initialize all the builders
   this.initializingTraverser.TraverseChildren(assembly);
   //create all of the types
   this.typeCreator.Traverse(assembly.GetAllTypes());
   //set entry point on assembly if defined
   if (!(assembly.EntryPoint is Dummy)) this.AssemblyBuilder.SetEntryPoint((MethodInfo)this.mapper.GetMethod(assembly.EntryPoint));
   //now the assembly is ready for action
   return this.AssemblyBuilder;
 }
예제 #15
0
        void CheckSurface(IAssembly contractAssembly, IAssembly originalAssembly)
        {
            Contract.Requires(contractAssembly != null);

            // Check each type in contract Assembly
            foreach (var type in contractAssembly.GetAllTypes())
            {
                if (type is INestedTypeDefinition)
                {
                    continue;                        // visited during parent type
                }
                CheckSurface(type, originalAssembly);
            }
        }
예제 #16
0
        public ISet <IDefinition> FindDefinitionsMatchingRegularExpressionInAssembly(Regex regex, IAssembly assembly)
        {
            // Maybe figure out how to factor out commons parts of this with FindDefinitionWithIdentifierInAssembly?

            ISet <IDefinition> results = new HashSet <IDefinition>(new DefinitionEqualityComparer());

            string regexPattern = regex.ToString();

            // We could be more efficient here, but for now we go with simplicity

            if (regexPattern.StartsWith("M:"))
            {
                foreach (IMethodDefinition method in GetAllMethodsInAssembly(assembly))
                {
                    if (regex.IsMatch(GarbageCollectHelper.GetIDStringForReference(method)))
                    {
                        results.Add(method);
                    }
                }
            }
            else if (regexPattern.StartsWith("T:"))
            {
                foreach (ITypeDefinition type in assembly.GetAllTypes())
                {
                    if (regex.IsMatch(GarbageCollectHelper.GetIDStringForReference(type)))
                    {
                        results.Add(type);
                    }
                }
            }
            else if (regexPattern.StartsWith("F:"))
            {
                foreach (IFieldDefinition field in GetAllFieldsInAssembly(assembly))
                {
                    if (regex.IsMatch(GarbageCollectHelper.GetIDStringForReference(field)))
                    {
                        results.Add(field);
                    }
                }
            }
            else
            {
                throw new Exception("Un recognized doc comment definition identifier prefix in: " + regexPattern + " (expected T:, M:, or F:)");
            }


            return(results);
        }
예제 #17
0
            private ICustomAttribute CreateAttribute(string typeName, IAssembly seedCoreAssembly, string argument = null)
            {
                var type = seedCoreAssembly.GetAllTypes().FirstOrDefault(t => t.FullName() == typeName);

                if (type == null)
                {
                    throw new FacadeGenerationException(String.Format("Cannot find {0} type in seed core assembly.", typeName));
                }

                IEnumerable <IMethodDefinition> constructors = type.GetMembersNamed(_seedHost.NameTable.Ctor, false).OfType <IMethodDefinition>();

                IMethodDefinition constructor = null;

                if (argument != null)
                {
                    constructor = constructors.SingleOrDefault(m => m.ParameterCount == 1 && m.Parameters.First().Type.AreEquivalent("System.String"));
                }
                else
                {
                    constructor = constructors.SingleOrDefault(m => m.ParameterCount == 0);
                }

                if (constructor == null)
                {
                    throw new FacadeGenerationException(String.Format("Cannot find {0} constructor taking single string argument in seed core assembly.", typeName));
                }

                var attribute = new CustomAttribute();

                attribute.Constructor = constructor;

                if (argument != null)
                {
                    var argumentExpression = new MetadataConstant();
                    argumentExpression.Type  = _seedHost.PlatformType.SystemString;
                    argumentExpression.Value = argument;

                    attribute.Arguments = new List <IMetadataExpression>(1);
                    attribute.Arguments.Add(argumentExpression);
                }

                return(attribute);
            }
예제 #18
0
        private static IEnumerable <string> EnumerateDocIdsToForward(IAssembly contractAssembly)
        {
            // Use INamedTypeReference instead of INamespaceTypeReference in order to also include nested
            // class type-forwards.
            var typeForwardsToForward = contractAssembly.ExportedTypes.Select(alias => alias.AliasedType)
                                        .OfType <INamedTypeReference>();

            var typesToForward = contractAssembly.GetAllTypes().Where(t => TypeHelper.IsVisibleOutsideAssembly(t))
                                 .OfType <INamespaceTypeDefinition>();
            List <string> result = typeForwardsToForward.Concat(typesToForward)
                                   .Select(type => TypeHelper.GetTypeName(type, NameFormattingOptions.DocumentationId)).ToList();

            foreach (var type in typesToForward)
            {
                AddNestedTypeDocIds(result, type);
            }

            return(result);
        }
예제 #19
0
        private static IEnumerable <string> EnumerateDocIdsToForward(IAssembly contractAssembly)
        {
            // Make note that all type forwards (including nested) implement INamespaceAliasForType, so do
            // not be tempted to filter using it, instead, we look at the aliased type to them.
            var typeForwardsToForward = contractAssembly.ExportedTypes.Select(alias => alias.AliasedType)
                                        .OfType <INamespaceTypeReference>();

            var typesToForward = contractAssembly.GetAllTypes().Where(t => TypeHelper.IsVisibleOutsideAssembly(t))
                                 .OfType <INamespaceTypeDefinition>();
            List <string> result = typeForwardsToForward.Concat(typesToForward)
                                   .Select(type => TypeHelper.GetTypeName(type, NameFormattingOptions.DocumentationId)).ToList();

            foreach (var type in typesToForward)
            {
                AddNestedTypeDocIds(result, type);
            }

            return(result);
        }
예제 #20
0
        public IDefinition FindDefinitionWithIdentifierInAssembly(string docCommentIdentifier, IAssembly assembly)
        {
            // We could be more efficient here, but for now we go with simplicity

            if (docCommentIdentifier.StartsWith("M:"))
            {
                foreach (IMethodDefinition method in GetAllMethodsInAssembly(assembly))
                {
                    if (GarbageCollectHelper.GetIDStringForReference(method) == docCommentIdentifier)
                    {
                        return(method);
                    }
                }
            }
            else if (docCommentIdentifier.StartsWith("T:"))
            {
                foreach (ITypeDefinition type in assembly.GetAllTypes())
                {
                    if (GarbageCollectHelper.GetIDStringForReference(type) == docCommentIdentifier)
                    {
                        return(type);
                    }
                }
            }
            else if (docCommentIdentifier.StartsWith("F:"))
            {
                foreach (IFieldDefinition field in GetAllFieldsInAssembly(assembly))
                {
                    if (GarbageCollectHelper.GetIDStringForReference(field) == docCommentIdentifier)
                    {
                        return(field);
                    }
                }
            }
            else
            {
                throw new Exception("Un recognized doc comment definition identifier prefix in: " + docCommentIdentifier + " (expected T:, M:, or F:)");
            }


            return(null);
        }
예제 #21
0
        public void DoStuff()
        {
            var host = new PeReader.DefaultHost();

            foreach (string file in Directory.GetFiles(Directory.GetCurrentDirectory(), "*.exe"))
            {
                Console.WriteLine(file);
                IAssembly assembly = host.LoadUnitFrom(file) as IAssembly;
                if (assembly != null)
                {
                    foreach (INamedTypeDefinition type in assembly.GetAllTypes())
                    {
                        foreach (IMethodDefinition method in type.Methods)
                        {
                            Console.WriteLine(String.Format("{0}::{1}", type.Name, method.Name));
                        }
                    }
                }
            }
        }
예제 #22
0
 public override void TraverseChildren(IAssembly assembly) {
   foreach (var t in assembly.GetAllTypes()) this.Traverse(t);
 }
예제 #23
0
파일: Program.cs 프로젝트: halllo/MTSS12
 private static IEnumerable<INamedTypeDefinition> getTypesNotGenerated(IAssembly assembly)
 {
     return from t in assembly.GetAllTypes()
            where !HasAnyGeneratedCodeAttributes(t)
            select t;
 }
예제 #24
0
    void CheckSurface(IAssembly contractAssembly, IAssembly originalAssembly)
    {
      Contract.Requires(contractAssembly != null);

      // Check each type in contract Assembly
      foreach (var type in contractAssembly.GetAllTypes())
      {
        if (type is INestedTypeDefinition) continue; // visited during parent type
        CheckSurface(type, originalAssembly);
      }
    }
예제 #25
0
            private ICustomAttribute CreateAttribute(string typeName, IAssembly seedCoreAssembly, string argument = null)
            {
                var type = seedCoreAssembly.GetAllTypes().FirstOrDefault(t => t.FullName() == typeName);
                if (type == null)
                {
                    throw new FacadeGenerationException(String.Format("Cannot find {0} type in seed core assembly.", typeName));
                }

                IEnumerable<IMethodDefinition> constructors = type.GetMembersNamed(_seedHost.NameTable.Ctor, false).OfType<IMethodDefinition>();

                IMethodDefinition constructor = null;
                if (argument != null)
                {
                    constructor = constructors.SingleOrDefault(m => m.ParameterCount == 1 && m.Parameters.First().Type.AreEquivalent("System.String"));
                }
                else
                {
                    constructor = constructors.SingleOrDefault(m => m.ParameterCount == 0);
                }

                if (constructor == null)
                {
                    throw new FacadeGenerationException(String.Format("Cannot find {0} constructor taking single string argument in seed core assembly.", typeName));
                }

                var attribute = new CustomAttribute();
                attribute.Constructor = constructor;

                if (argument != null)
                {
                    var argumentExpression = new MetadataConstant();
                    argumentExpression.Type = _seedHost.PlatformType.SystemString;
                    argumentExpression.Value = argument;

                    attribute.Arguments = new List<IMetadataExpression>(1);
                    attribute.Arguments.Add(argumentExpression);
                }

                return attribute;
            }
예제 #26
0
        private static IEnumerable<string> EnumerateDocIdsToForward(IAssembly contractAssembly)
        {
            // Make note that all type forwards (including nested) implement INamespaceAliasForType, so do
            // not be tempted to filter using it, instead, we look at the aliased type to them.
            var typeForwardsToForward = contractAssembly.ExportedTypes.Select(alias => alias.AliasedType)
                                                                      .OfType<INamespaceTypeReference>();

            var typesToForward = contractAssembly.GetAllTypes().Where(t => TypeHelper.IsVisibleOutsideAssembly(t))
                                                               .OfType<INamespaceTypeDefinition>();
            List<string> result = typeForwardsToForward.Concat(typesToForward)
                                        .Select(type => TypeHelper.GetTypeName(type, NameFormattingOptions.DocumentationId)).ToList();
            
            foreach(var type in typesToForward)
            {
                AddNestedTypeDocIds(result, type);
            }

            return result;
        }
예제 #27
0
        private static IEnumerable<string> EnumerateDocIdsToForward(IAssembly contractAssembly)
        {
            // Use INamedTypeReference instead of INamespaceTypeReference in order to also include nested
            // class type-forwards.
            var typeForwardsToForward = contractAssembly.ExportedTypes.Select(alias => alias.AliasedType)
                                                                      .OfType<INamedTypeReference>();

            var typesToForward = contractAssembly.GetAllTypes().Where(t => TypeHelper.IsVisibleOutsideAssembly(t))
                                                               .OfType<INamespaceTypeDefinition>();
            List<string> result = typeForwardsToForward.Concat(typesToForward)
                                        .Select(type => TypeHelper.GetTypeName(type, NameFormattingOptions.DocumentationId)).ToList();
            
            foreach(var type in typesToForward)
            {
                AddNestedTypeDocIds(result, type);
            }

            return result;
        }
예제 #28
0
 private IEnumerable <TypeMetricsWithMethodMetrics> AnalyzeTypes(IAssembly assembly, PdbReader pdb, IMetadataHost host)
 {
     return(from type in assembly.GetAllTypes()
            where type.Name.ToString() != "<Module>"
            select TypeAndMethods(pdb, host, type));
 }
예제 #29
0
 private IEnumerable<TypeMetricsWithMethodMetrics> AnalyzeTypes(IAssembly assembly, PdbReader pdb, IMetadataHost host)
 {
     return from type in assembly.GetAllTypes()
            where type.Name.ToString() != "<Module>"
            select TypeAndMethods(pdb, host, type);
 }