Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to access Add-Type defined type in other Add-Type type definition?

Tags:

How to access a type defined by Add-Type -TypeDefinition "..." in another Add-Type -TypeDefinition "..."?

In the following code example, in spite of the same namespace, a compiler cannot find the UserCode type.

Add-Type -TypeDefinition @"
namespace SampleCode {
    public struct UserCode {
         public string Name;
         public string Id;
    }
}
"@

#.... do something ....

Add-Type -TypeDefinition @"
namespace SampleCode {
    public struct UserInformation {
        public UserCode User;
        public string Note;
    }
}
"@
# => Error ... Add-Type : <temporary source path>(3) : The type or namespace name
# 'UserCode' could not be found (are you missing a using directive or an assembly
# reference?)