取消
显示结果 
搜索替代 
您的意思是: 

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 项奖励
1 条消息(共 7 条)
5,943 次查看

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 项奖励
2 条消息(共 7 条)
5,924 次查看
解答
接受人 bestchun1

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

 

3 条消息(共 7 条)
5,908 次查看

Yes, I fixed it. Thank you very much

0 项奖励
4 条消息(共 7 条)
5,870 次查看

@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 项奖励
5 条消息(共 7 条)
5,797 次查看

Hi,

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

Thx

0 项奖励
6 条消息(共 7 条)
5,767 次查看

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 项奖励
7 条消息(共 7 条)
5,750 次查看