Esempio n. 1
0
        private void dgvAssemblies_SelectionChanged(object sender, EventArgs e)
        {
            DataGridView thisDataGridView = (DataGridView)sender;

            if (thisDataGridView.SelectedRows.Count > 0)
            {
                string    selectedAssemblyName = thisDataGridView.SelectedRows[0].Cells[0].Value.ToString();
                IAssembly assembly             = codeElementsManager.GetAssemblyByName(selectedAssemblyName);

                List <NDependMetricDefinition> assemblyMetricsDefinionsList = new NDependXMLMetricsDefinitionLoader().LoadMetricsDefinitions("AssemblyMetrics.xml");
                FillMetricsListView(thisDataGridView.SelectedRows[0], assemblyMetricsDefinionsList);

                this.lblCodeElementType.Text = "Assembly";
                this.lblCodeElementName.Text = selectedAssemblyName;

                List <NDependMetricDefinition> namespaceMetricsDefinionsList = new NDependXMLMetricsDefinitionLoader().LoadMetricsDefinitions("NamespaceMetrics.xml");
                DataTable namespaceMetricsDataTable = CreateCodeElemetMetricsDataTable <INamespace>(assembly.ChildNamespaces, namespaceMetricsDefinionsList);
                FillCodeElementsDataGridView(this.dgvNamespaces, namespaceMetricsDataTable);
            }
        }
Esempio n. 2
0
        public IList GetMetricHistory(string codeElementName, NDependMetricDefinition metricDefinition)
        {
            CodeBaseManager codeBaseManager = new CodeBaseManager(analysisResultRefsList[0].Project);
            CodeElementsManagerReflectionHelper reflectionHelper = new CodeElementsManagerReflectionHelper();

            Type  metricType         = Type.GetType(metricDefinition.NDependMetricType);
            Type  nullableMetricType = typeof(Nullable <>).MakeGenericType(metricType);
            var   metricValue        = Activator.CreateInstance(nullableMetricType);
            IList metricValues       = (IList)Activator.CreateInstance(typeof(List <>).MakeGenericType(nullableMetricType));

            foreach (var analysisResultRef in analysisResultRefsList)
            {
                ICodeBase           currentAnalysisResultCodeBase       = codeBaseManager.LoadCodeBase(analysisResultRef);
                CodeElementsManager currenAnalysisResultCodeBaseManager = new CodeElementsManager(currentAnalysisResultCodeBase);
                metricValue = null;

                switch (metricDefinition.NDependCodeElementType)
                {
                case "NDepend.CodeModel.IAssembly":
                    IAssembly selectedAssemblyFromCurrentAnalysisResultCodebase = currenAnalysisResultCodeBaseManager.GetAssemblyByName(codeElementName);
                    if (selectedAssemblyFromCurrentAnalysisResultCodebase != null)
                    {
                        metricValue = reflectionHelper.GetCodeElementMetric(
                            selectedAssemblyFromCurrentAnalysisResultCodebase,
                            typeof(IAssembly),
                            metricDefinition.InternalPropertyName,
                            metricDefinition.NDependMetricType);
                    }
                    break;

                case "NDepend.CodeModel.INamespace":
                    INamespace selectedNamespaceFromCurrentAnalysisResultCodebase = currenAnalysisResultCodeBaseManager.GetNamespaceByName(codeElementName);
                    if (selectedNamespaceFromCurrentAnalysisResultCodebase != null)
                    {
                        metricValue = reflectionHelper.GetCodeElementMetric(
                            selectedNamespaceFromCurrentAnalysisResultCodebase,
                            typeof(INamespace),
                            metricDefinition.InternalPropertyName,
                            metricDefinition.NDependMetricType);
                    }
                    break;

                case "NDepend.CodeModel.IType":
                    IType selectedTypeFromCurrentAnalysisResultCodebase = currenAnalysisResultCodeBaseManager.GetTypeByName(codeElementName);
                    if (selectedTypeFromCurrentAnalysisResultCodebase != null)
                    {
                        metricValue = reflectionHelper.GetCodeElementMetric(
                            selectedTypeFromCurrentAnalysisResultCodebase,
                            typeof(IType),
                            metricDefinition.InternalPropertyName,
                            metricDefinition.NDependMetricType);
                    }
                    break;

                case "NDepend.CodeModel.IMethod":
                    IMethod selectedMethodFromCurrentAnalysisResultCodebase = currenAnalysisResultCodeBaseManager.GetMethodByName(codeElementName);
                    if (selectedMethodFromCurrentAnalysisResultCodebase != null)
                    {
                        metricValue = (reflectionHelper.GetCodeElementMetric(
                                           selectedMethodFromCurrentAnalysisResultCodebase,
                                           typeof(IMethod),
                                           metricDefinition.InternalPropertyName,
                                           metricDefinition.NDependMetricType));
                    }
                    break;
                }
                metricValues.Add(metricValue);
            }
            return(metricValues);
        }