private static ComponentAttribute ComponentDynamic(this Type component) { // The dynamic version is necessary when the component type was obtained using the type service foreach (var attribute in component.GetCustomAttributes(true)) { if (IsComponentMetadata(attribute.GetType())) { var componentAttribute = new ComponentAttribute(); foreach (var property in attribute.GetType().GetProperties( BindingFlags.Instance | BindingFlags.Public | BindingFlags.GetProperty | BindingFlags.SetProperty)) { var componentAttributeProperty = componentAttribute.GetType().GetProperty(property.Name); if (componentAttributeProperty != null && componentAttributeProperty.CanWrite) componentAttributeProperty.SetValue(componentAttribute, property.GetValue(attribute, null), null); } return componentAttribute; } } return null; }
private static ComponentAttribute ComponentDynamic(this Type component) { // The dynamic version is necessary when the component type was obtained using the DynamicTypeService // So the component will be in another (temp) assembly and the cast to IComponentMetadata won't work. foreach (Attribute attribute in component.GetCustomAttributes(true)) { if (IsComponentMetadata(attribute.GetType())) { var ComponentAttribute = new ComponentAttribute(); foreach (var property in attribute.GetType().GetProperties(BindingFlags.Instance | BindingFlags.Public | BindingFlags.GetProperty | BindingFlags.SetProperty)) { var ComponentAttributeProperty = ComponentAttribute.GetType().GetProperty(property.Name); if (ComponentAttributeProperty != null && ComponentAttributeProperty.CanWrite) ComponentAttributeProperty.SetValue(ComponentAttribute, property.GetValue(attribute, null), null); } return ComponentAttribute; } } return null; }