EnumArray Method Call

An EnumArray Method Call is a Complex Method Call that returns an EnumArray.

Code Example

The example exists of an Operation and a Form. In the operation the Entity Collection(s) and Dataview(s) are defined. The definitions of Lists and Method Call(s) for composing the data, based on input from the user, are also defined in the Forms.

Code example Operation

protected override IForm CreateStartupForm()
{
   return new EnumArrayMethodCallDemoFrm(this);
}

public IEntityCollection<EnumArrayMethodCallDemoEntity> EnumArray
{
   get { return Property(() => new VolatileTable("enum array").Select<EnumArrayMethodCallDemoEntity>().All()); }
}

public IDataView<EnumArrayMethodCallDemoEntity> EnumArrayView
{
   get { return Property(() => EnumArray.ToView()); }
}

 public IEntityCollection<EnumEntity<Weeks>> Weeks
{
    return Property(() => 
        new EnumTable<Weeks>("week", "weeks", GrammaticalGender.Masculine)
        .Select<EnumEntity<Weeks>, Weeks>().All());
}

 

Explanation Code example Operation

  1. Lines 1-4: Definition of the Form (see code of the Form below).
  2. Lines 6-9: Definition of a Volatile Table. We fill this in the Form (below).
  3. Lines 11-14: Definition of the View, which is used to display the data in the Form.
  4. Lines 8 and 11: The necessary EnumArrayMethodCallDemoEntity is defined elsewhere. Type 'Volatile Table' in the Search box to read more about the working of the Volatile Table.
  5. This EnumArrayMethodCallDemoEntity is also used in the Form below, on line 14.
  6. Lines 16-21: We also need an EntityCollection, based on EnumEntity<Weekss> for this Code example.

Note: In this example, a Volatile Table is used. It is also possible to make a EnumArray based on a Database Table.


Code example Form

public EnumArrayMethodCallDemoFrm(EnumArrayMethodCallDemoOp operation) : base(operation)
{

}

protected override IUIElement CreateGui()
{
   return new VBox
   {
       new HBox
       {
           new GroupBox("example",2, alignV:AlignV.Top)
           {
               new DataGrid<EnumArrayMethodCallDemoEntity>(Operation.EnumArrayView, showColumnHeaders:false)
               {
                   e => e.Value
               }
           }
       },

       new HBox(alignH:AlignH.Fill)
       {
           new Button(GetEnumArray()),
           EmptySpace.FillH,
           new Button(Close())
       }
   };
}

private EnumArray<Weeks> ComposeEnumArray()
{
   return Method(() =>
   {
       return new Body
       {
            new Return(Operation.Weeks.Select(f => f.EnumValue).ToEnumArray())
       };
   });
}

private IMethodCall GetEnumArray()
{
   return Method(() =>
   {
       var newListItem = Operation.EnumArray.CreateItemReference();
       var array = new EnumArray<Weeks>();
       return new Body
       {
           Operation.EnumArray.DeleteAll(),
           array.Assign(ComposeEnumArray()),
           array.Foreach(arrayItem => new Body
           {
               newListItem.Assign(Operation.EnumArray.New()),
               newListItem.Omschrijving.Assign(listItem)
           })
       };

   })
   .SetWorkDescription("get enum array")
   .SetImage(WikiImages.Directory)
   .Call();
}

 

Warning:

All Method Calls and Complex Method Calls need a new Return(). They are like C# functions that need a return type.
The exception is an IMethodCall. In C# this is like a void method.


Explanation Code example Form

  • Lines 6-28: The definition of the form.
  • Line 14: The View, based on the Entity (see explanation 3 and 4 of the Operation), are passed to a DataGrid.
  • Lines 30-39: This is a private property of the type EnumArray. In it, the list is composed and returned (line 36). This EnumArray was defined in the Operation as a Volatile Table.
  • Line 36: Building up this EnumArray is done with the function .ToEnumArray that collects the records collected with the Select.
  • Lines 41-62: This MethodCall, named GetEnumArray(), starts a new instance of EnumArray on line 45.
  • Line 49: any previous data is deleted.
  • Line 50-55: The composed EnumArray is assigned to an array. By looping through this array (line 50) the items are assigned (line 53-54).

Example of the result

A form like the one defined above, could look like this.

When starting the application:

 

After clicking the button: