Mgen spa Engineering 2 tutorial (Part 1): Data Flow and type exceptions

Source: Internet
Author: User

Back to the tutorial directory

Update record:

: Added to spa project 2.5.

Directory

  • 1. Data Stream
  • 2. Type exception

 

Returned directory

1. Data Stream

When I talk about the validators in the previous section, you will find that the SPA project supports some type of validators, but does not support this type of controls, so the data flow is used to solve this problem, obviously, the controls are limited, so the types supported by the controls are also very limited. When the types supported by the core data storage or validators are different from those supported by the controls, the data stream is responsible for converting the type of the control to the required type. If the conversion fails, the SPA project will output an error.

 

All data streams are defined in the mgen. spa. dataflow namespace. Like the control of the SPA project, data streams are also defined Based on. NET. The naming rules for all data streams are as follows:

[Control data type] to [core data type] Flow

 

For example, the data stream name of string type to double type is stringtodoubleflow.

 

Note that the data flow is bidirectional. When you change the control, the data of the control is converted to the core by the data flow. When the interface generated by the SPA project tries to read the value of the core data, the value of the core data is also converted into the data type required by the control by the data flow, then, assign the converted value to the control.

 

The current SPA project defines four data streams, which are:

Stringtodoubleflow

Stringtointflow

Stringtoulongflow

Stringtolines (convert string to string [] by system line break and add it to spa project 2.5)

 

You don't need to explain them more. You can see their meanings from the names. In addition, the three data streams are converted from strings to numbers. Let's take an example.

 

For example, to define a double interface with a range of 0.0 to 1.0, the type definition is as follows:

// + Using mgen. spa;

// + Using mgen. spa. controls;

// + Using mgen. spa. validators;

// + Using mgen. spa. dataflow;

Class myspatype

{

[Spaheader ("key1")]

[Textboxstringcontrol] // Control

[Doublerangerule (0, 1)] // validators

[Stringtodoubleflow] // data stream

Public double data {Get; set ;}

}

 

Generation interface:

 

 

Returned directory

2. Type exception

Readers of the four major components of the SPA project: the core, validators, data streams, and controls have some knowledge about the code, and these components all have their own types. You will find the validators, each Feature Definition type of a data stream and a control has a targettype attribute that represents the specific type of the component, and the core target type is the corresponding.. Net Property type. If any type matching error occurs, the spafatalexception will be thrown.

 

It is very easy to trigger spafatalexception. We will slightly modify the above Type Definition and delete the data stream. In this way, we will apply a text box control for the string type to the core storage of the double type:

Class myspatype

{

[Spaheader ("key1")]

[Textboxstringcontrol]

Public double data {Get; set ;}

}

 

Run F5 to debug the spafatalexception. The error message is as follows:

Data Type Mismatch: Control Storage: system. String, core storage: system. Double

 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.