Home > Code Samples > How to detect if DXCore is loaded from another add-in

How to detect if DXCore is loaded from another add-in

January 17th, 2011

Note, this article has been moved to the official DevExpress Support Center site. Please refer to the moved article as it might have further updates or additional comments. Thank you.

Here is a sample code illustrating how to detect if the DXCore is installed and loaded from another add-in (without static dependencies on the DXCore assemblies) using reflection. This could be helpful if your add-in functionality somehow intersects with the DXCore’s.

From inside a usual DXCore plug-in, you can detect if the DXCore is loaded by calling the “CodeRush.IsLoaded”┬áproperty. In case you are not going to reference the DXCore assemblies inside your add-in, this sample might help.

CSharp code:

bool DXCoreIsLoaded
      const string CodeRushObjectTypeName = "DevExpress.CodeRush.Core.CodeRush";
      const string IsLoadedPropertyName = "IsLoaded";

      Assembly DXCoreMainAssembly = GetDXCoreMainAssembly();
      if (DXCoreMainAssembly == null)
        return false;

      Type CodeRushObjectType = DXCoreMainAssembly.GetType(CodeRushObjectTypeName);
      if (CodeRushObjectType == null)
        return false;

      PropertyInfo IsLoadedProperty = CodeRushObjectType.GetProperty(IsLoadedPropertyName, BindingFlags.IgnoreCase | BindingFlags.Public | BindingFlags.Static);
      if (IsLoadedProperty == null)
        return false;

      object IsLoadedValue = IsLoadedProperty.GetValue(null, null);
      if (IsLoadedValue == null)
        return false;

      return (bool)IsLoadedValue;
      return false;
Assembly GetDXCoreMainAssembly()
  const string DXCoreMainAssemblyName = "DevExpress.CodeRush.Core";

  Assembly[] assemblies = AppDomain.CurrentDomain.GetAssemblies();
  foreach (Assembly assembly in assemblies)
    if (assembly.FullName.StartsWith(DXCoreMainAssemblyName))
      return assembly;

  return null;

Visual Basic code:

ReadOnly Property DXCoreIsLoaded() As Boolean
      Const CodeRushObjectTypeName As String = "DevExpress.CodeRush.Core.CodeRush"
      Const IsLoadedPropertyName As String = "IsLoaded"

      Dim DXCoreMainAssembly As Assembly = GetDXCoreMainAssembly()
      If DXCoreMainAssembly Is Nothing Then
        Return False
      End If

      Dim CodeRushObjectType As Type = DXCoreMainAssembly.GetType(CodeRushObjectTypeName)
      If CodeRushObjectType Is Nothing Then
        Return False
      End If

      Dim IsLoadedProperty As PropertyInfo = CodeRushObjectType.GetProperty(IsLoadedPropertyName, BindingFlags.IgnoreCase Or BindingFlags.Public Or BindingFlags.Static)
      If IsLoadedProperty Is Nothing Then
        Return False
      End If

      Dim IsLoadedValue As Object = IsLoadedProperty.GetValue(Nothing, Nothing)
      If IsLoadedValue Is Nothing Then
        Return False
      End If

      Return CType(IsLoadedValue, Boolean)
      Return False
    End Try
  End Get
End Property
Function GetDXCoreMainAssembly() As Assembly
  Const DXCoreMainAssemblyName As String = "DevExpress.CodeRush.Core"

  Dim assemblies As Assembly() = AppDomain.CurrentDomain.GetAssemblies()
  For Each assembly As Assembly In assemblies
    If assembly.FullName.StartsWith(DXCoreMainAssemblyName) Then
      Return assembly
    End If

  Return Nothing
End Function
Products: DXCore
Versions: 12.1 and up
VS IDEs: any
Updated: Nov/01/2012
ID: D058

Similar Posts:

  1. No comments yet. Be the first and leave a comment!