FileInfo.BaseName exists in PowerShell but not in straight .NET

.net, powershell

Solution

Powershell adds that property for you. If you run get-member on a fileinfo object, you can see that it's a script property, and even the script itself:

get-item testfile1.txt | Get-Member BaseName | format-list

TypeName   : System.IO.FileInfo
Name       : BaseName
MemberType : ScriptProperty
Definition : System.Object BaseName {get=if ($this.Extension.Length -gt 0){$this.Name.Remove($this.Name.Length - 
         $this.Extension.Length)}else{$this.Name};}

Problem

Why is it that in .NET the `System.IO.FileInfo` object does not have a `BaseName` property, but I can use the property through PowerShell, e.g.: ``` $FolderItems = Get-ChildItem -Path "C:\" | Where-Object {$_ -isnot [IO.DirectoryInfo]} foreach ($FolderItem in $FolderItems) { write-host $FolderItem.BaseName } ```

Original source