Version 1

Version 2

The approach shown below is only compatible with version 2.0 of the Vault Application Framework, where the target audience runs M-Files 2018 or higher. If using version 1.0, or to maintain compatibility with M-Files 2015.3 and lower, configuration attributes should be used instead.

In some situations, using nested configuration objects may be needed to express complex configuration structures. One such example would be where an application requires the user to configure a collection of rules, similarly to the Metadata Card Configuration. The sample below defines two configuration classes (Configuration and ConfigurationChild). Members exposed by either configuration class could be simple strings (as below), or any other configuration value for which an editor exists.

Using nested configuration

An example of nested configuration objects

using System.Collections.Generic;
using System.Runtime.Serialization;
using MFiles.VAF;
using MFiles.VAF.AdminConfigurations;

namespace MFVaultApplication1
{
	[DataContract]
	public class Configuration
	{
		[DataMember]
		public ConfigurationChild MySubConfiguration { get; set; }

		[DataMember]
		public List<ConfigurationChild> Children { get; set; }
	}

	[DataContract]
	public class ConfigurationChild
	{
		[DataMember]
		public string Value1 { get; set; }
	}

	public class VaultApplication
		: VaultApplicationBase, IUsesAdminConfigurations
	{

		private ConfigurationNode<Configuration> config { get; set; }

		/// <inheritdoc />
		public void InitializeAdminConfigurations(IAdminConfigurations adminConfigurations)
		{

			// Add it to the configuration screen.
			this.config = adminConfigurations.AddSimpleConfigurationNode<Configuration>("My Vault Application");
		}
	}
}

Customising array element names

In the example screenshot above, adding new items to the Children collection results in items being added named ConfigurationChild[1], ConfigurationChild[1], etc. In some situations, it is more useful to show a different value for the item name to make locating the correct item more simple.

This can be done by ensuring that the class in question (ConfigurationChild, below) exposes a Name property:

Customising array element names

using System.Collections.Generic;
using System.Runtime.Serialization;
using MFiles.VAF;
using MFiles.VAF.AdminConfigurations;

namespace MFVaultApplication1
{
	[DataContract]
	public class Configuration
	{
		[DataMember]
		public ConfigurationChild MySubConfiguration { get; set; }

		[DataMember]
		public List<ConfigurationChild> Children { get; set; }
	}

	[DataContract]
	public class ConfigurationChild
	{
		[DataMember]
		public string Value1 { get; set; }

		[DataMember]
		[TextEditor(IsRequired = true)]
		public string Name { get; set; }
	}

	public class VaultApplication
		: VaultApplicationBase, IUsesAdminConfigurations
	{

		private ConfigurationNode<Configuration> config { get; set; }

		/// <inheritdoc />
		public void InitializeAdminConfigurations(IAdminConfigurations adminConfigurations)
		{

			// Add it to the configuration screen.
			this.config = adminConfigurations.AddSimpleConfigurationNode<Configuration>("My Vault Application");
		}
	}
}

Alternatively, if the name should be derived from a different property then it can declared using the JsonConfEditor attribute on the class itself. In the case of the example below, the NameProperty property has been explicitly marked as the property to use for the object names.

using System.Collections.Generic;
using System.Runtime.Serialization;
using MFiles.VAF;
using MFiles.VAF.AdminConfigurations;

namespace MFVaultApplication1
{
	[DataContract]
	public class Configuration
	{
		[DataMember]
		public ConfigurationChild MySubConfiguration { get; set; }

		[DataMember]
		public List<ConfigurationChild> Children { get; set; }
	}

	[DataContract]
	[JsonConfEditor(NameMember = "NameProperty")]
	public class ConfigurationChild
	{
		[DataMember]
		public string Value1 { get; set; }

		[DataMember]
		[TextEditor(IsRequired = true)]
		public string NameProperty { get; set; }
	}

	public class VaultApplication
		: VaultApplicationBase, IUsesAdminConfigurations
	{

		private ConfigurationNode<Configuration> config { get; set; }

		/// <inheritdoc />
		public void InitializeAdminConfigurations(IAdminConfigurations adminConfigurations)
		{

			// Add it to the configuration screen.
			this.config = adminConfigurations.AddSimpleConfigurationNode<Configuration>("My Vault Application");
		}
	}
}