07-16-2018 03:53 AM
Hello,
I need to implement this simple data casting of c# objects in LV
object o = "MyString"; SqlString t1 = o as String
How this can be done in LV??
Solved! Go to Solution.
07-16-2018 03:58 AM
"To .NET Object.vi" in Connectivity>.NET.
Simply wire a string, and get a string object.
07-16-2018 04:36 AM
Thanks for the reply
But in this scenario I have .Net string and I need .Net SqlString as attached below:
07-16-2018 05:59 AM
Why don't you use the SqlString(string Data) constructor?
You can't cast a string to an SqlString, because the string object is not an SqlString.
07-16-2018 07:52 AM
Thanks for reply.
When I compile c# code it works fine and there is no exception.
There is implicit conversion possible and I need to force this in LV code.
https://msdn.microsoft.com/en-us/library/system.data.sqltypes.sqlstring.op_implicit(v=vs.110).aspx
07-16-2018 08:07 AM
07-16-2018 08:47 AM
The problem is string object is returned by some other functions, I do not create it.
I could force object to string and back but i think this will work only for string type.
I have other situations where I need for it to behave like this simple c# code snipped where AS statement is used.
07-16-2018 11:08 AM
You don't have access to c#- operators from LabVIEW, because they are a part of the C# language. With LabVIEW you access the .NET- Framework, not the C# langage features.
I think, your own solution is a good approach.
07-17-2018 03:03 AM
@daveTW wrote:
You don't have access to c#- operators from LabVIEW, because they are a part of the C# language. With LabVIEW you access the .NET- Framework, not the C# langage features.
I think, your own solution is a good approach.
I agree, not much alternatives in LabVIEW, besides doing it manually for each data type. If you really want this to be done automatically for all types, you'll need to make a .NET assembly in c#. You don't need VS or anything, there is a c# compiler included in .NET.
I you're really adventurous (=masochistic), you might be able to do it with .NET reflection, but I'm certain it won't be easy nor productive (=time consuming with small change of success).
07-17-2018 04:33 AM
Thanks for the interest in this topic.
Simple dll to handle conversions will do it. I try to avoid making to many dlls because it gets out of controll sooner or later.
The more i dig into how things can be solved in C# the more I realise how LV is limited...