Quantcast
Channel: SAP Business One SDK
Viewing all articles
Browse latest Browse all 49

applying c# extension methods to sdk classes

$
0
0

hello all,

i found particularly useful to extend sap b1 sdk objects with custom static methods to simplify and generalize common operations which need the same boring instructions to perform some basic tasks.

 

for example:

we have to set a particular cell value in a matrix

 

instead of writing every time we need to set a value:

 

 

((SAPbouiCOM.EditText)matrix.Columns.Item("U_CUSTOMTEXT").Cells.Item( 7 ).Specific).Value = "text value to set";
((SAPbouiCOM.EditText)matrix.Columns.Item("U_CUSTOMVALUE").Cells.Item( 12 ).Specific).Value = "value to set";

why not trying to extend the matrix object with an extension method?

 

 

public static class MatrixHelpers
{       public static void SetCellValue(this SAPbouiCOM.Matrix matrix, String colUID, int rowIdx, String value)        {            try            {                ((SAPbouiCOM.EditText)matrix.Columns.Item(colUID).Cells.Item(rowIdx).Specific).Value = value;            }            catch (Exception ex)            {                //log.Debug(ex);            }        }

 

now, as long as you include in the usings list in your classes the namespace containing the class above, you can set a value with only:

 

matrix0.SetCellValue("U_CUSTOMTEXT",7,"text value to set");

 

nice. less code.

 

bye.


Viewing all articles
Browse latest Browse all 49

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>