Getting data using Dynamic object from Winforms
Dynamic objects are a very useful tools, when you are trying to get a data object or data element that you can't access fully.
You could use this in instead of an interface method. (In principle)

Get User Id method
The below method will access the active form and convert the form object to a dynamic object.
Then dynamic object, will access the UserDetail public object and retrieves the Id property.
The dynamic object, does not know until runtime, if the object or property exists. So its up to the developer to make sure the Naming of of the Properties are correct.


If you do use dynamic object always make sure you know what objects are referenced. Because if you change the main object, you will need to re-test the dynamic logic



public static int getUserId()
{
try
{

Dynamic dynamicForm = System.Windows.Forms.Application.OpenForms["FormName"];
return dynamicForm.UserDetails.Id;

}
catch(Exception e)
{

Logging.Exception(e);
}

return 0;
}

Created: 27/09/2016 Total Comment: 0

Comments

(Not Displayed)
Human validation
Enter 4730 number, before submitting to confirm your human
[Home] [All Blogs] [Contact] [Me]