internal static ExpressionEditor GetExpressionEditorInternal(Type expressionBuilderType, string expressionPrefix, IWebApplication webApp, IServiceProvider serviceProvider) { if (expressionBuilderType == null) { throw new ArgumentNullException("expressionBuilderType"); } ExpressionEditor editor = null; object[] customAttributes = expressionBuilderType.GetCustomAttributes(typeof(ExpressionEditorAttribute), true); ExpressionEditorAttribute attribute = null; if (customAttributes.Length > 0) { attribute = (ExpressionEditorAttribute)customAttributes[0]; } if (attribute != null) { string editorTypeName = attribute.EditorTypeName; Type c = Type.GetType(editorTypeName); if (c == null) { ITypeResolutionService service = (ITypeResolutionService)serviceProvider.GetService(typeof(ITypeResolutionService)); if (service != null) { c = service.GetType(editorTypeName); } } if ((c != null) && typeof(ExpressionEditor).IsAssignableFrom(c)) { editor = (ExpressionEditor)Activator.CreateInstance(c); editor.SetExpressionPrefix(expressionPrefix); } IDictionary expressionEditorsCache = GetExpressionEditorsCache(webApp); if (expressionEditorsCache != null) { expressionEditorsCache[expressionPrefix] = editor; } IDictionary expressionEditorsByTypeCache = GetExpressionEditorsByTypeCache(webApp); if (expressionEditorsByTypeCache != null) { expressionEditorsByTypeCache[expressionBuilderType] = editor; } } return(editor); }
public static ExpressionEditor GetExpressionEditor(Type expressionBuilderType, IServiceProvider serviceProvider) { object[] attrs = expressionBuilderType.GetCustomAttributes(typeof(ExpressionEditorAttribute), false); if (attrs == null || attrs.Length == 0) { return(null); } ExpressionEditorAttribute ee = (ExpressionEditorAttribute)attrs[0]; Type editor_type = Type.GetType(ee.EditorTypeName); ExpressionEditor editor = (ExpressionEditor)Activator.CreateInstance(editor_type); editor.ExpressionBuilderType = expressionBuilderType; return(editor); }