Exemple #1
0
        /// <summary>
        /// Create a Type record in the database
        /// </summary>
        /// <param name="command">Command factory object</param>
        /// <param name="typeDefinition">Type definition</param>
        private void CreateTypeRecord(CommandFactory command, TypeDefinition typeDefinition)
        {
            command.Insert<TypeField>(
                command.GetLastId<AssemblyField>(),
                command.GetLastId<ModuleField>(),
                typeDefinition.Name,
                typeDefinition.FullName,
                GetTypeName(typeDefinition, false, true),
                typeDefinition.Namespace,
                typeDefinition.Methods.Count
            );

            foreach (MethodDefinition methodDefinition in typeDefinition.Methods)
            {
                CreateMethodRecord(command, methodDefinition);
            }

            foreach (TypeDefinition nestedType in typeDefinition.NestedTypes)
            {
                CreateTypeRecord(command, nestedType);
            }
        }
Exemple #2
0
 /// <summary>
 /// Create a Resource record in the database
 /// </summary>
 /// <param name="command">Command factory object</param>
 /// <param name="resource">Resource</param>
 private void CreateResourceRecord(CommandFactory command, Resource resource)
 {
     command.Insert<ResourceField>(
         command.GetLastId<AssemblyField>(),
         command.GetLastId<ModuleField>(),
         resource.Name,
         Utility.ConvertEnum<ResourceType>(resource.ResourceType).ToString(),
         resource.IsPublic
     );
 }
Exemple #3
0
        /// <summary>
        /// Create a Module record in the database
        /// </summary>
        /// <param name="command">Command factory object</param>
        /// <param name="moduleDefinition">Module definition</param>
        private void CreateModuleRecord(CommandFactory command, ModuleDefinition moduleDefinition)
        {
            int methodCount = 0;
            foreach (TypeDefinition typeDefinition in moduleDefinition.Types)
            {
                methodCount += typeDefinition.Methods.Count;
            }

            string name = moduleDefinition.Name;
            if (name == null || name.Trim() == string.Empty)
            {
                name = Path.GetFileName(moduleDefinition.FullyQualifiedName);
            }

            ModuleType moduleType = ModuleType.Library;
            if (moduleDefinition.Kind != ModuleKind.Dll)
            {
                moduleType = Utility.ConvertEnum<ModuleType>(moduleDefinition.Kind);
            }

            TargetPlatform? platform = null;
            if (moduleDefinition.Architecture == TargetArchitecture.I386 &&
                (moduleDefinition.Attributes & ModuleAttributes.ILOnly) == ModuleAttributes.ILOnly &&
                (moduleDefinition.Attributes & ModuleAttributes.Required32Bit) != ModuleAttributes.Required32Bit)
            {
                platform = TargetPlatform.AnyCPU;
            }
            else if (moduleDefinition.Architecture == TargetArchitecture.I386)
            {
                platform = TargetPlatform.x86;
            }
            else if (moduleDefinition.Architecture == TargetArchitecture.AMD64)
            {
                platform = TargetPlatform.x64;
            }
            else if (moduleDefinition.Architecture == TargetArchitecture.IA64)
            {
                platform = TargetPlatform.Itanium;
            }

            command.Insert<ModuleField>(
                command.GetLastId<AssemblyField>(),
                name,
                moduleDefinition.FullyQualifiedName,
                moduleType,
                moduleDefinition.Runtime.ToString().Replace("Net_", "").Replace("_", "."),
                platform,
                (moduleDefinition.Attributes & ModuleAttributes.ILOnly) != ModuleAttributes.ILOnly,
                (moduleDefinition.Attributes & ModuleAttributes.StrongNameSigned) == ModuleAttributes.StrongNameSigned,
                null, // EntryPointMethodId
                moduleDefinition.Resources.Count,
                moduleDefinition.Types.Count,
                methodCount
            );

            if (moduleDefinition.Assembly != null && moduleDefinition == moduleDefinition.Assembly.MainModule)
            {
                command.Update(AssemblyField.MainModuleId, command.GetLastId<ModuleField>());
            }

            foreach (Resource resource in moduleDefinition.Resources)
            {
                CreateResourceRecord(command, resource);
            }

            foreach (CustomAttribute attribute in moduleDefinition.CustomAttributes)
            {
                CreateAttributeRecord(command, attribute, AttributeType.Module);
            }

            foreach (TypeDefinition typeDefinition in moduleDefinition.Types)
            {
                CreateTypeRecord(command, typeDefinition);
            }
        }
Exemple #4
0
        /// <summary>
        /// Create a Method record in the database
        /// </summary>
        /// <param name="command">Command factory object</param>
        /// <param name="methodDefinition">Method definition</param>
        private void CreateMethodRecord(CommandFactory command, MethodDefinition methodDefinition)
        {
            command.Insert<MethodField>(
                command.GetLastId<AssemblyField>(),
                command.GetLastId<ModuleField>(),
                command.GetLastId<TypeField>(),
                methodDefinition.Name,
                methodDefinition.FullName,
                GetTypeName(methodDefinition.ReturnType, true, false),
                GetTypeName(methodDefinition.ReturnType, false, false)
            );

            CreateTypeReferenceRecord(command, methodDefinition.ReturnType);

            if (methodDefinition == methodDefinition.Module.EntryPoint)
            {
                command.Update(ModuleField.EntryPointMethodId, command.GetLastId<MethodField>());
            }

            /*if (methodDefinition.Body != null)
            {
                foreach (Instruction instruction in methodDefinition.Body.Instructions)
                {
                    CreateInstructionRecord(command, instruction);
                }
            }*/
        }
Exemple #5
0
 /// <summary>
 /// Create an Instruction record in the database
 /// </summary>
 /// <param name="command">Command factory object</param>
 /// <param name="instruction">Instruction</param>
 private void CreateInstructionRecord(CommandFactory command, Instruction instruction)
 {
     command.Insert<InstructionField>(
         command.GetLastId<AssemblyField>(),
         command.GetLastId<ModuleField>(),
         command.GetLastId<TypeField>(),
         command.GetLastId<MethodField>(),
         instruction.ToString()
     );
 }
Exemple #6
0
 /// <summary>
 /// Create an Attribute record in the database
 /// </summary>
 /// <param name="command">Command factory object</param>
 /// <param name="attribute">Custom attribute</param>
 /// <param name="attributeType">Attribute type</param>
 private void CreateAttributeRecord(CommandFactory command, CustomAttribute attribute, AttributeType attributeType)
 {
     command.Insert<AttributeField>(
         attributeType == AttributeType.Assembly ? command.GetLastId<AssemblyField>() : new long?(),
         attributeType == AttributeType.Module ? command.GetLastId<ModuleField>() : new long?(),
         attribute.AttributeType.Name,
         attribute.AttributeType.FullName,
         attributeType
     );
 }