Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Skip Adding Types If they exist #1233

Open
wants to merge 3 commits into
base: modularize
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
43 changes: 39 additions & 4 deletions build/Beta-TypeDefs.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# ------------------------------------------------------------------------------
# Type definitios required for commands inputs
# Type definitions required for commands inputs
# ------------------------------------------------------------------------------

$def = @"
Expand Down Expand Up @@ -962,9 +962,44 @@ namespace Microsoft.Open.MSGraph.Model
}
}
"@
try{ Add-Type -TypeDefinition $def }
catch{}

# Extract namespaces and types from the type definitions
$lines = $def -split "`n"
$namespace = $null
$types = @()

foreach ($line in $lines) {
# Check for a namespace declaration
if ($line -match '^\s*namespace\s+([\w\.]+)') {
$namespace = $matches[1]
}
# Check for public classes or enums within a namespace
elseif ($line -match '^\s*public\s+(class|enum)\s+(\w+)') {
if ($namespace) {
$types += "$namespace.$($matches[2])"
}
}
}

# Check if each type exists in the currently loaded assemblies
$missingTypes = @()
foreach ($type in $types) {
if (-not [Type]::GetType($type, $false, $false)) {
$missingTypes += $type
}
}

# Add the $def if any type is missing
if ($missingTypes.Count -gt 0) {
try {
# Define parameters for dynamic compilation
Add-Type -TypeDefinition $def
emmanuel-karanja marked this conversation as resolved.
Show resolved Hide resolved
} catch {
}
}

#Don't add the types

# ------------------------------------------------------------------------------
# End of Type definitios required for commands inputs
# End of Type definitions required for commands inputs
# ------------------------------------------------------------------------------
13 changes: 9 additions & 4 deletions build/V1.0-TypeDefs.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# ------------------------------------------------------------------------------
# Type definitios required for commands inputs
# Type definitions required for commands inputs
# ------------------------------------------------------------------------------

$def = @"
Expand Down Expand Up @@ -765,9 +765,14 @@ namespace Microsoft.Open.MSGraph.Model
}
}
"@
try{ Add-Type -TypeDefinition $def }
catch{}

try {
Add-Type -TypeDefinition $def -ErrorAction SilentlyContinue
} catch {
# No error message will be displayed, and type will be added if it doesn't exist
}


# ------------------------------------------------------------------------------
# End of Type definitios required for commands inputs
# End of Type definitions required for commands inputs
# ------------------------------------------------------------------------------