Features, algorithms creating and using dynamic properties

DynamicProperties - an instance of the class NameObjectCollection (extension class NameObjectCollectionBase)that is, in fact, a dictionary that stores pairs of values a string object.

Dynamic properties allow you to store additional information about the object and help in situations where the logic of the use of the object differs from the circumstances (call with different shapes, different users, etc.).

Dynamic properties do not remain in base.

The use of dynamic properties

To access dynamic properties of an object, use the following:

dataObject.DynamicProperties

Добавление свойства

var someObject = new object();
dataObject.DynamicProperties.Add("propertyName", someObject);

Проверка on the availability of properties at объекта

if (dataObject.DynamicProperties.ContainsKey("propertyName"))
{
    ...
}

Удаление properties объекта

dataObject.DynamicProperties.Remove("propertyName");

The basic scenario using dynamic object properties

The main usage scenario for the application projects the following:

  • In the dynamic properties of the object is added to a flag.
  • In business server update object, check for this flag and is running or not running a set of certain actions.

Example

Object СтрокаПланаПогашения. For example, you must enter a payment template, which contains information about КредитнойКарте and Кредите, but blank ДатыОплаты and Суммы. However, in the business server update the object already is check responsible for filling these fields. Hence, the object will not be updated and saved back into the database.

On the form create a template of payment before sending the object to save, you need to add a dynamic property

dataObject.DynamicProperties.Add("Template", true); @@

And the business server to modify the test as follows:

if (!UpdatedObject.DynamicProperties.ContainsKey("Template"))
{
    // Check for mandatory filling of fields, the Amount and Dataplate 
}