Features, algorithms creating and using dynamic properties

DynamicProperties - NameObjectCollection instance of a class (class extension 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 
}
Переведено сервисом «Яндекс.Переводчик» http://translate.yandex.ru