Skip to content

Instantly share code, notes, and snippets.

@SeeminglyScience
SeeminglyScience / emca-335-i.11.md
Last active May 15, 2024 20:25
Rules for CLS-compliance

[I.11 Collected Common Language Specification rules][§I.11]

The complete set of CLS rules are collected here for reference. Recall that these rules apply only to "externally visible" items—types that are visible outside of their own assembly and members of those types that have public, family, or family-or-assembly accessibility. Furthermore, items can be explicitly marked as CLS-compliant or not using the System.CLSCompliantAttribute. The CLS rules apply only to items that are marked as CLS-compliant.

  1. CLS rules apply only to those parts of a type that are accessible or visible outside of the defining assembly. ([§I.7.3])

  2. Members of non-CLS compliant types shall not be marked CLS-compliant. ([§I.7.3.1])

  3. Boxed value types are not CLS-compliant. ([§I.8.2.4].)

using namespace System
using namespace System.Linq
using namespace System.Collections
using namespace System.Collections.Generic
using namespace System.Management.Automation
using namespace System.Management.Automation.Language
using namespace System.Reflection
# Hey person reading this! Don't do this, alright? You'll have a bad time. ty
@SeeminglyScience
SeeminglyScience / PSClassCmdlet.psm1
Last active January 12, 2024 11:00
Cmdlet example using only PowerShell.
# https://seeminglyscience.github.io/powershell/2017/04/13/cmdlet-creation-with-powershell
using namespace System.Management.Automation
using namespace System.Reflection
[Cmdlet([VerbsDiagnostic]::Test, 'Cmdlet')]
class TestCmdletCommand : PSCmdlet {
[Parameter(ValueFromPipeline)]
[object]
$InputObject;
@SeeminglyScience
SeeminglyScience / ForceClassExportExample.ps1
Created April 17, 2017 02:07
Proof of concept for forcing external type definitions to export in a module.
using namespace System.Management.Automation.Language
using namespace System.Collections.Generic
using namespace System.Reflection
# The current contents of the psm1 file would go here, including dot sourcing the class definition
# files normally and exporting module members.
# The rest can most likely be loaded into a function but I haven't tested it yet. It could also
# use some cleaning up.
$usingStatements = [List[UsingStatementAst]]::new()
using namespace System.Management.Automation
# Use of StopUpstreamCommandsException is obviously not supported. Subject to breaking at any time.
function Select-FirstObject {
[Alias('first', 'top')]
[CmdletBinding(PositionalBinding = $false)]
param(
[Parameter(ValueFromPipeline)]
[psobject] $InputObject,
using namespace System.Collections.Generic
using namespace System.Management.Automation
using namespace System.Security.AccessControl
using namespace Microsoft.Win32
function Get-InstalledSoftware {
[CmdletBinding()]
param(
[Parameter(ValueFromPipeline)]
[ValidateNotNullOrEmpty()]
@SeeminglyScience
SeeminglyScience / Microsoft.VSCode_profile.ps1
Last active July 15, 2023 02:43
Snippet for enabling cross module "Find All References", "Go to Definition" and intellisense in VSCode PowerShell
if ($psEditor) {
# Don't reference any files whose FullName match this regex.
${Exclude Files Regex} = '\\Release\\|\\\.vscode\\|build.*\.ps1|debugHarness\.ps1|\.psd1'
# Get the PowerShellEditorServices assemblies.
${editor services assemblies} = [System.AppDomain]::CurrentDomain.GetAssemblies() |
Where-Object Location -Match 'PowerShell.EditorServices.*.dll' |
ForEach-Object -MemberName Location
# Add some C# that essentially lets us add a hook to the event that is called when VSCode opens a file.
Add-Type -Language CSharp -ReferencedAssemblies ${editor services assemblies} -WarningAction SilentlyContinue -TypeDefinition @'
<Configuration>
<ViewDefinitions>
<View>
<Name>Utility.PullRequest</Name>
<ViewSelectedBy>
<TypeName>Utility.PullRequest</TypeName>
</ViewSelectedBy>
<CustomControl>
<CustomEntries>
<CustomEntry>
@SeeminglyScience
SeeminglyScience / Enter-PSSessionWithEdit.ps1
Last active May 4, 2023 03:27
Proof of concept for "psedit" working outside of PSES.
function Enter-PSSessionWithEdit {
[CmdletBinding()]
param(
[Parameter(Mandatory)]
[ValidateNotNullOrEmpty()]
[string] $ComputerName
)
end {
$enterEventName = 'RemoteSessionEditor.Enter'
if (-not $Host.Runspace.Events.GetEventSubscribers($enterEventName)) {
{
"version": "0.1.0",
"description": "Decode and deflate base64 strings of gzip data",
"homepage": "https://github.com/SeeminglyScience/psudad",
"license": "MIT",
"architecture": {
"64bit": {
"url": "https://github.com/SeeminglyScience/psudad/releases/download/v0.1.0/psudad-0.1.0-win-x64.zip",
"hash": "fd1b7200021221f071033ec3c40007fcc21372086f4aa1d3999d212f581db3c4"
}