cancel
Showing results for 
Search instead for 
Did you mean: 
Reply

to access function or properties in sealed singleton objects(classes) in .NET

Solved!
Go to solution

to access function or properties in sealed singleton objects(classes) in .NET

I have a dll developed in vc 2010 with .NET Framework 4 in Microsoft Visual C# 2010. I am trying to access .NET Objects using .NET Constructor. And I can assess some of objects(classes) successfully.

But some of classes(objects) are fully sealed and  no constructor is available. In C#, I could access functions of such class using Instance. For example I would like access  function, F, of class A, and I could use "A.instance.F"... Is there similar tool in labview 2012?

Thanks a lot.

Best,

Michael 

0 Kudos
Message 1 of 7
(1,209 Views)

Re: to access function or properties in sealed singleton objects(classes) in .NET

Hi Michael,

 

Good question! I am not sure exactly what you mean by sealed classes. To clarify, you are using the .NET constructor node, but some classes are not appearing as options?

 

Another option would be to create your DLL as Win32 DLL and call it in LabVIEW using a Call Library Function Node.

 

This Help document gives a good overview of our .NET functionality.

 

Joey S.
Senior Product Manager, Software
National Instruments
0 Kudos
Message 2 of 7
(1,190 Views)
Highlighted
Solution
Accepted by topic author bestchun1
08-27-2015 04:09 PM

Re: to access function or properties in sealed singleton objects(classes) in .NET

Michael,

 

When you say "sealed" do you mean "static"?  Sealed means you can't inherit from that class but you should be able to create instances using a constructor. Static means you can't instantiate a new instance of that class (i.e. there is no constructor). Static classes are also sealed.

 

For example, System.Math in mscorlib.dll is static. It has no constructor:

Screen Shot 2013-03-08 at 4.13.27 PM.png

 

However I can still use it's functions if I use a .NET constant rather than a constructor. I hope there's an easier to find way to do this but I always just right click on the output of the contructor node and select Create>>Constant.

 

Screen Shot 2013-03-08 at 4.16.27 PM.png

 

Then right click on your new constant and select Select .NET Class>>Browse and go find your assembly and object (in our case System.Math in mscorlib)

 

Screen Shot 2013-03-08 at 4.19.25 PM.png

 

Now you can wire this reference to an invoke node to use the functions within the static class. I also like to label the reference with the name of the class to make the code easier to read, like so:

 

Screen Shot 2013-03-08 at 4.21.15 PM.png

 

Hope this helps.

 

SimonH

National Instruments

 

Message 3 of 7
(1,174 Views)

Re: to access function or properties in sealed singleton objects(classes) in .NET

Yes, I fixed it. Thank you very much

0 Kudos
Message 4 of 7
(1,136 Views)

Re: to access function or properties in sealed singleton objects(classes) in .NET


@SimonH wrote:
However I can still use it's functions if I use a .NET constant rather than a constructor. I hope there's an easier to find way to do this but I always just right click on the output of the contructor node and select Create>>Constant.

Since you mentioned wanting an easier way to do this: drop an invoke or property node on the block diagram, right-click, Select Class -> .NET -> Browse, choose the appropriate assembly. The .NET class constant is not needed. You can still wire the reference output to another node even though there's nothing connected to the reference input.

0 Kudos
Message 5 of 7
(1,063 Views)

Re: to access function or properties in sealed singleton objects(classes) in .NET

Hi,

is it needed that the reference is closedafter execution with Connectivity >> .NET >> Close Reference after the execution?

Thx

0 Kudos
Message 6 of 7
(1,033 Views)

Re: to access function or properties in sealed singleton objects(classes) in .NET

It is always a good idea to close .NET references when you are done with them. I'm not certain if it is necessary in this case but it won't hurt to close it.

0 Kudos
Message 7 of 7
(1,016 Views)