Helpers
Xafari Helpers is a set of special classes intended to expand the functionality of the DevExpress classes. In most cases, it is used to implement additional methods and properties or to grant access to the closed (non-public) members of the type being extended. The code below demonstrates Helpers for DevExpress.ExpressApp.IObjectSpace and System.Type:
- c#
- VB
this.ObjectSpace.Xafari().DataAccessor;
view.ObjectTypeInfo.Type.Xafari().AliveType;
this.ObjectSpace.Xafari().DataAccessor
view.ObjectTypeInfo.Type.Xafari().AliveType
All Xafari Helpers classes follow a specific set of rules listed below:
- Any Helper is a descendant of the XafariHelperBase<T> base class where T stands for the class being extended.
- Each Helper is named according to the TargetTypeHelper template.
- Helpers are located in the Helpers namespace. For example, the Xafari.BC module has its helper classes in the Xafari.BC.Helpers namespace.
- There is a special Xafari() extension method to access helper class objects.
- Access to the non-public members should be implemented through calling the corresponding methods of the XafariHelperBase<T> base class. Important things to remember here are the next:
- The signature of the helper class should be the same as the signature of the method being assigned public.
- When implementing the properties and fields to publish, their names should match the properties of the helper class.
- To publish a method, the signature of the corresponding method in Helper should be the same as the signature of the authentic method.
- To publish a property or field, implement the corresponding members of the Helper class with the same names.
- The same rules are applied to the extensions of the helper classes (see below).
Sample:
- c#
- VB
namespace Xafari.BC.Helpers
{
public class XafApplicationHelper : XafariHelperBase<XafApplication>
{
public XafApplicationHelper(XafApplication instance)
: base(instance)
{
}
public string GetDcAssemblyFilePath()
{
return this.InvokeFunc<string>("GetDcAssemblyFilePath");
}
public ControllersManager ControllersManager
{
get
{
return this.GetPropertyValue<ControllersManager>("ControllersManager");
}
}
public bool? isActualModulesVersionInfo
{
get
{
return this.GetFieldValue<bool?>("isActualModulesVersionInfo");
}
}
public bool IsSharedApplication()
{// any code
}
public bool IsSetupComplete
{
get
{
return ValueManager.GetValueManager<bool>(this.IsSetupCompleteKey).Value;
}
internal set
{
ValueManager.GetValueManager<bool>(this.IsSetupCompleteKey).Value = value;
}
}
}
}
namespace Xafari.BC
{
public static class XafariExtensions
{
public static XafApplicationHelper Xafari(this XafApplication application)
{
return new XafApplicationHelper(application);
}
}
}
Namespace Xafari.BC.Helpers
Public Class XafApplicationHelper
Inherits XafariHelperBase(Of XafApplication)
Public Sub New(ByVal instance As XafApplication)
MyBase.New(instance)
End Sub
Public Function GetDcAssemblyFilePath() As String
Return Me.InvokeFunc(Of String)("GetDcAssemblyFilePath")
End Function
Public ReadOnly Property ControllersManager As ControllersManager
Get
Return Me.GetPropertyValue(Of ControllersManager)("ControllersManager")
End Get
End Property
Public ReadOnly Property isActualModulesVersionInfo As Boolean?
Get
Return Me.GetFieldValue(Of Boolean?)("isActualModulesVersionInfo")
End Get
End Property
Public Function IsSharedApplication() As Boolean
' any code
End Function
Public Property IsSetupComplete As Boolean
Get
Return ValueManager.GetValueManager(Of Boolean)(Me.IsSetupCompleteKey).Value
End Get
Friend Set
ValueManager.GetValueManager(Of Boolean)(Me.IsSetupCompleteKey).Value = value
End Set
End Property
End Class
End Namespace
Namespace Xafari.BC
Public Module XafariExtensions
<System.Runtime.CompilerServices.Extension> _
Public Function Xafari(ByVal application As XafApplication) As XafApplicationHelper
Return New XafApplicationHelper(application)
End Function
End Module
End Namespace
Extensions for the Helper Class
It is possible to extend the Helper class in another module. For instance, there are helpers to support the Application Settings. But may arise a situation when the developer needs a custom method. When implementing extensions, it is recommended to follow a propositions listed below:
1. Extensions for the Helper class derived from XafariHelperExtensionBase<T, THelper> base class. T – extensible class, THelper – extensible Helper class.
2. The name of the implemented extension conform to the ModuleNameTargetTypeHelperExtension pattern.
3. Extensions for the Helper class is placed into the Helpers namespace. For instance, in the Xafari.BC.Settings module, helper extension class are placed in Xafari.BC.Settings.Helpers.
4. To access object of the extension class, it is necessary to call a special ModuleName() extension method. For instance, there is a SettingsTypeHelperExtension in the Xafari.BC.Settings module. AppSettings method provides access to the extension object:
- c#
- VB
public static SettingsTypeHelperExtension AppSettings(this TypeHelper typeHelper)
{
return new SettingsTypeHelperExtension(typeHelper);
}
<System.Runtime.CompilerServices.Extension> _
Public Shared Function AppSettings(ByVal typeHelper As TypeHelper) As SettingsTypeHelperExtension
Return New SettingsTypeHelperExtension(typeHelper)
End Function
5. To provide a required non-public members, use corresponding methods of the XafariHelperBase<T> base class. Note the following requirements:
- To publish a method, the signature of the corresponding method in extension should be the same as the signature of the authentic method.
- To publish a property or field, implement the corresponding members with the same names.
The code snippet below demonstrates how to access the extension for the Helper class:
