Skip to main content

Type Properties in XPO

The following example illustrates how to implement Type Properties in an XPO persistent class.

private string dataTypeName;
[Browsable(false)]
[Persistent("DataType")]
public string DataTypeName {
    get { return dataTypeName; }
    set {
        Type type = XafTypesInfo.Instance.FindTypeInfo(value) == null ? null : 
            XafTypesInfo.Instance.FindTypeInfo(value).Type;
        if (_dataType != type) {
            _dataType = type;
        }
        //if (!IsLoading && value != dataTypeName) {

        //}
        SetPropertyValue<string>(nameof(DataTypeName), ref dataTypeName, value);
    }
}

private Type _dataType;
[TypeConverter(typeof(LocalizedClassInfoTypeConverter))]
[ImmediatePostData, NonPersistent]
[HideInUI(HideInUI.FilterEditor)]
public Type DataType {
    get { return _dataType; }
    set {
        if (_dataType != value) {
            _dataType = value;
            DataTypeName = (value == null) ? null : value.FullName;
        }
    }
}

Filter Editor does not support Type properties, so we hide these properties with the HideInUI(HideInUI.FilterEditor) attribute. If you want to filter by type, add a string property as follows:

[HideInUI(HideInUI.DetailView | HideInUI.ReportCustomizationForm | HideInUI.DashboardCustomizationForm | HideInUI.ListView)]
[System.ComponentModel.DisplayName("Data Type")]
public string DataTypeCaption {
    get {
        if(_dataType != null) {
            return CaptionHelper.GetClassCaption(_dataType.FullName);
        }
        else {
            return null;
        }
    }
}

If the view is not editable, use the following combination of attributes:

[HideInUI(HideInUI.DetailView | HideInUI.ReportCustomizationForm | HideInUI.DashboardCustomizationForm)]
[System.ComponentModel.DisplayName("Data Type")]
 public string DataTypeCaption {...}

[HideInUI(HideInUI.FilterEditor | HideInUI.ListView)]
public Type DataType {...}