我有一个名为的类库项目MyWidget,唯一的类被命名MyWidget.
在另一个项目中,我添加了对类库的引用,在我的新类中,我尝试过输入
Imports MyWidget
Run Code Online (Sandbox Code Playgroud)
和
Imports MyWidget.MyWidget
Run Code Online (Sandbox Code Playgroud)
但是,当我尝试创建新引用时,我的课程稍后,Visual Studio不允许我输入:
Private widget As MyWidget
Run Code Online (Sandbox Code Playgroud)
但是,Visual Studio给了我一个"预期的类型".错误并强迫我也包含命名空间,如下所示:
Private widget As MyWidget.MyWidget
Run Code Online (Sandbox Code Playgroud)
我阅读了有关该声明的MSDN文档Imports.在声明对象时我应该可以不使用命名空间,因为我在程序顶部有import语句.我已经使用标准命名空间对它进行了测试,它工作正常,但是当我在课堂上尝试时,它没有.
我是否遗漏了MyWidget类中的某些内容,这些内容允许我在声明对象时放弃命名空间?
我也尝试重命名命名空间MyClasses,想也许是Visual Studio中渐渐与类混淆了命名空间.然而,即使有
Imports MyClasses.MyWidget
Run Code Online (Sandbox Code Playgroud)
尝试在MyWidget没有MyClasses命名空间的情况下定义对象时仍然会出错.
我创建了一个名为Personstore name,address等的自定义类.这个类/模型与其他模型交叉引用,包括ApplicationUser:
public class ApplicationUser : IdentityUser
{
public Person Person { get; set; }
public async Task<ClaimsIdentity> GenerateUserIdentityAsync(UserManager<ApplicationUser> manager)
{
// Note the authenticationType must match the one defined in CookieAuthenticationOptions.AuthenticationType
var userIdentity = await manager.CreateIdentityAsync(this, DefaultAuthenticationTypes.ApplicationCookie);
// Add custom user claims here
return userIdentity;
}
}
Run Code Online (Sandbox Code Playgroud)
在我的一个控制器中,我使用以下代码来获取当前用户登录并获取它的Person对象,如下所示:
var user = UserManager.FindById(User.Identity.GetUserId());
var person = user.Person;
Run Code Online (Sandbox Code Playgroud)
我的Person课程也定义在ApplicationDbContext:
public class ApplicationDbContext : IdentityDbContext<ApplicationUser>
{
public ApplicationDbContext()
: base("MyContext", throwIfV1Schema: false) …Run Code Online (Sandbox Code Playgroud)