Enable C# Add-Type type definition loading

Use this forum to ask questions after your subscription maintenance expires or before you buy. Need information on licensing or pricing? Questions about a trial version? This is the right place for you. No scripting questions, please.
Forum rules
DO NOT POST SUBSCRIPTION NUMBERS, LICENSE KEYS OR ANY OTHER LICENSING INFORMATION IN THIS FORUM.
Only the original author and our tech personnel can reply to a topic that is created in this forum. If you find a topic that relates to an issue you are having, please create a new topic and reference the other in your post.
This topic is 1 year and 3 months old and has exceeded the time allowed for comments. Please begin a new topic or use the search feature to find a similar but newer topic.
davider360
Posts: 18
Last visit: Wed Nov 23, 2022 2:35 am

Enable C# Add-Type type definition loading

Post by davider360 »

Product: PowerShell Studio 2022 (64 Bit)
Build: v5.8.213
OS: Windows 7 Professional (64 Bit)
powershell: v5.1

about Enable C# Add-Type type definition loading ,I encountered the following problem (See the following demo)

1.There is no namespace and class name in the [ ] auto-completion list
It will be more convenient to display them in the auto-complete list, both VSC and ISE include this feature

2.There is no New constructor
Static classes(Contains all built-in classes) should have New constructor, both VSC and ISE include this feature

3.No output return value
Values can be output in IDEs such as ISE and VSC

Solving the above problems is very important for using C# classes, I look forward to developers reviewing them, thank you very much

Code: Select all

$cs = @'
namespace Ns1
{
	public class Cl1
	{
		public static void Hi()
		{
			System.Console.WriteLine("hello!");
		}
	}
}
'@
Add-Type -TypeDefinition $cs

[Ns1.Cl1]::Hi()
zzz.gif
zzz.gif (357.59 KiB) Viewed 2261 times
User avatar
brittneyr
Site Admin
Posts: 1649
Last visit: Mon Mar 18, 2024 1:47 pm
Answers: 38
Been upvoted: 30 times

Re: Enable C# Add-Type type definition loading

Post by brittneyr »

The setting Enable C# Add-Type type definition loading was originally to provide basic auto completion for C# add-type definitions. I will pass your information along to development team.

As for your third issue, you are writing to a console, but there is no console in PowerShell Studio to capture that output when running a script (Ctrl + F5).
Brittney
SAPIEN Technologies, Inc.
davider360
Posts: 18
Last visit: Wed Nov 23, 2022 2:35 am

Re: Enable C# Add-Type type definition loading

Post by davider360 »

about third issue:

Console.Writeline method is very convenient for debugging output
brittneyr wrote: Fri Nov 18, 2022 2:55 pm The setting Enable C# Add-Type type definition loading was originally to provide basic auto completion for C# add-type definitions. I will pass your information along to development team.

As for your third issue, you are writing to a console, but there is no console in PowerShell Studio to capture that output when running a script (Ctrl + F5).
User avatar
Alexander Riedel
Posts: 8473
Last visit: Tue Mar 19, 2024 12:38 am
Answers: 19
Been upvoted: 37 times

Re: Enable C# Add-Type type definition loading

Post by Alexander Riedel »

You cannot write to a console where there is no console.
If you insist on doing that you need to run your script in the console. Only then will you actually have a console to write to.

However, normally people would use
Write-Output or Write-Debug to be host independent. The write-* methods are the prescribed PowerShell methods to effect output.
Alexander Riedel
SAPIEN Technologies, Inc.
This topic is 1 year and 3 months old and has exceeded the time allowed for comments. Please begin a new topic or use the search feature to find a similar but newer topic.