/// <summary> /// Add the type information of a metric to the metric collection. /// This allows the editor to instantiate it. /// </summary> /// <param name="type">type of the metric</param> /// <returns>true if the type is compatible (has a metric attribute and is instantiable)</returns> public bool TryRegisterMetric(Type type) { MetricAttribute metricAttrib = null; try { metricAttrib = (MetricAttribute)type.GetCustomAttribute(typeof(MetricAttribute)); } catch (Exception) { return(false); } if (metricAttrib == null) { return(false); } if (metricAttrib.Instantiable) { var metricInfo = new MetricInfo( metricAttrib.Name, metricAttrib.Category, type.FullName, _genericFactoryGuid, FactoryForType(type), FactoryXmlForType(type) ); _metrics.Add(metricInfo); MetricAdded?.Invoke(this, new MetricAddedEventArgs(metricInfo)); } return(true); }
private static string GetMetricName(PropertyInfo propertyInfo, MetricAttribute attribute) { return(attribute == null || string.IsNullOrEmpty(attribute.MetricName) ? propertyInfo.Name : attribute.MetricName); }