IModel.SetField Method
Namespace: NextDesign.Core
Description
Sets the specified value to the specified field of this instance.
If a value that cannot be set to the specified field is specified, an exception is thrown.
If the multiplicity of the specified field is 2 or more, the first element of the field is set.
Arguments
Name | Type | Description |
---|---|---|
fieldName | string | Field name Null or an empty string cannot be specified. |
value | object | Field value |
Return value
- void
Exception
Name | Exception class | Description |
---|---|---|
Invalid argument | ExtensionArgumentException | If null or an empty string is specified for fieldName |
Field not found | ExtensionFieldNotFoundException | If the specified field is not found in the metaclass of this instance |
Does not match the field type | ExtensionInvalidTypeException | If a value that cannot be set for the specified field is specified for value - A null value is specified for a primitive type field other than string or rich text - An incompatible primitive type is specified - A different enumeration type is specified - A primitive type value or an enumeration value is specified for a class type field - An incompatible class type is specified. |
Invalid operation | ExtensionInvalidOperationException | If the model itself is a deleted model or a temporary proxy. If an inoperable field is specified for the field name. - Feature assignment field of a product line - Field with the System.Core tag If an invalid field is specified. |
Circular reference | ExtensionCircularReferenceException | When calling an owned field of a class type, if the target of this method or its ancestor is specified in the argument value, the method is called on itself or its ancestor. |
An invalid model is specified. | ExtensionInvalidModelException | If a deleted model or temporary proxy is specified for the field value. |
Annotation
About API specification changes and migration method in Ver.1.1
From Ver.1.1, this method can now set null to string and rich text type fields.
If you are using this API, you will need to change the relevant part in the extension when upgrading to Ver.1.1 or later.
About the values that can be set depending on the field type
The values that can be set are determined by the field type as follows.
- Primitive type fields (integer, real number, boolean, string, rich text)
In primitive type fields, you can set values that can be implicitly cast to the corresponding C# type.
However, in rich text type fields, only the string type can be set. In this case, decoration as rich text format by specifying tags such as <b>
is not interpreted.
In addition, in primitive type fields, you can set a string that can be converted to the desired type value by the Parse method associated with the corresponding C# type.
In the case of string type and rich text type, null is allowed, and the following values can also be set.
-
object type: value converted to a string by the ToString method
-
enumeration field
In an enumeration field, you can set a string that corresponds to a literal.
Conversion to a literal is possible in the following cases.
-
If there is a literal name that matches the string, it will be converted to that literal.
-
If there is no matching literal name, and if there is a string that matches the display name of the literal, it will be converted to the first literal found.
-
class type field
In a class type field, you can set an instance of IModel type and null.
If an IModel type value is specified, the specified model will be set instead of the model that was already set.
In this case, the behavior differs depending on whether the field is owned or referenced.
- If it is owned, the model specified in the argument will be moved as a child of the model that called the method. Also, the already set model will be deleted.
- In the case of a reference, a reference relationship is added to the model specified in the argument. Also, any reference relationship that existed with the model that was already set is deleted. The model that was already set is not deleted.
If null is specified, only the setting of the model that was already set is unset.
- In the case of ownership, the model that was already set is deleted.
- In the case of a reference, any reference relationship that existed with the model that was already set is deleted. The model that was already set is not deleted.
If the multiplicity limit of the field is 2 or more, the 0th element is deleted and subsequent elements are moved forward.