2 // -------------------------------------------------------------------
3 // Copyright (c) Microsoft Corporation. All Rights Reserved.
4 // -------------------------------------------------------------------
5 //From \\authoring\Sparkle\Source\1.0.1083.0\Common\Source\Framework\Properties
6 namespace System.Activities.Presentation.Internal.PropertyEditing.FromExpression.Framework.PropertyInspector
8 using System.ComponentModel;
9 using System.Diagnostics;
10 using System.Collections.Generic;
11 using System.Collections.ObjectModel;
13 using System.Activities.Presentation.PropertyEditing;
14 using System.Collections;
15 using System.Globalization;
17 using System.Diagnostics.CodeAnalysis;
19 internal static class ExtensibilityMetadataHelper
22 // Returns an instance of the PropertyValueEditor specified in the provided attribute list.
24 // <param name="attributes">A list of attributes. If an EditorAttribute is not specified in this collection, will return null.</param>
25 // <param name="exceptionLogger">Interface for exception logging. If null, exceptions will be silently ignored.</param>
26 // <returns></returns>
27 [SuppressMessage("Microsoft.Design", "CA1031:DoNotCatchGeneralExceptionTypes", Justification = "Propagating the error might cause VS to crash")]
28 [SuppressMessage("Reliability", "Reliability108", Justification = "Propagating the error might cause VS to crash")]
29 public static PropertyValueEditor GetValueEditor(IEnumerable attributes, IMessageLogger exceptionLogger)
31 PropertyValueEditor propertyValueEditor = null;
32 if (attributes != null)
34 foreach (Attribute attribute in attributes)
36 EditorAttribute editorAttribute = attribute as EditorAttribute;
37 if (editorAttribute != null)
41 Type editorType = Type.GetType(editorAttribute.EditorTypeName);
42 if (editorType != null && typeof(PropertyValueEditor).IsAssignableFrom(editorType))
44 propertyValueEditor = (PropertyValueEditor)Activator.CreateInstance(editorType);
50 if (exceptionLogger != null)
52 exceptionLogger.WriteLine(string.Format(CultureInfo.CurrentCulture, ExceptionStringTable.ValueEditorLoadFailed, ExtensibilityMetadataHelper.GetExceptionMessage(e)));
58 return propertyValueEditor;
62 // Returns the type of the editor specified by the provided EditorAttribute.
64 // <param name="attribute">EditorAttribute that specifies a CategoryEditor type. If the type specified is not derived from CategoryEditor, or cannot be loaded, will return null.</param>
65 // <param name="exceptionLogger">Interface for exception logging. If null, exceptions will be silently ignored.</param>
66 // <returns></returns>
67 [SuppressMessage("Microsoft.Design", "CA1031:DoNotCatchGeneralExceptionTypes", Justification = "Propagating the error might cause VS to crash")]
68 [SuppressMessage("Reliability", "Reliability108", Justification = "Propagating the error might cause VS to crash")]
69 public static Type GetCategoryEditorType(EditorAttribute attribute, IMessageLogger exceptionLogger)
73 Type editorType = Type.GetType(attribute.EditorTypeName);
74 if (editorType != null && typeof(CategoryEditor).IsAssignableFrom(editorType))
81 if (exceptionLogger != null)
83 exceptionLogger.WriteLine(string.Format(CultureInfo.CurrentCulture, ExceptionStringTable.CategoryEditorTypeLoadFailed, ExtensibilityMetadataHelper.GetExceptionMessage(e)));
89 public static string GetExceptionMessage(Exception e)
91 return (e.InnerException != null) ? e.InnerException.ToString() : e.Message;
94 public static bool IsEditorReusable(IEnumerable attributes)
96 bool isEditorReusable = true;
97 if (attributes != null)
99 foreach (Attribute attribute in attributes)
101 EditorReuseAttribute editorReuseAttribute = attribute as EditorReuseAttribute;
102 if (editorReuseAttribute != null)
104 isEditorReusable = editorReuseAttribute.ReuseEditor;
109 return isEditorReusable;