所以我在C#中有以下代码:
public Container ConfigureSimpleInjector(IAppBuilder app)
{
var container = new Container();
container.Options.DefaultScopedLifestyle = new AsyncScopedLifestyle();
container.RegisterPackages();
app.Use(async (context, next) =>
{
using (AsyncScopedLifestyle.BeginScope(container))
{
await next();
}
});
container.Verify();
return container;
}
Run Code Online (Sandbox Code Playgroud)
在app.Use()被定义为Owin.AppBuilderUserExtensions.Use(),看起来像这样:
public static IAppBuilder Use(this IAppBuilder app, Func<IOwinContext, Func<Task>, Task> handler);
VB等价如下:
Public Function ConfigureSimpleInjector(app As IAppBuilder) As Container
Dim container = New Container()
container.Options.DefaultScopedLifestyle = New AsyncScopedLifestyle()
container.RegisterPackages()
app.Use(Async Sub(context, [next])
Using AsyncScopedLifestyle.BeginScope(container)
Await [next]()
End Using
End Sub)
container.Verify()
Return container
End …Run Code Online (Sandbox Code Playgroud) 所以我使用angular-2-local-storage将一个对象存储到本地存储中:
this.localStorage.set('myObject', {'prop1': "string", 'prop2': "string"});
然后我试图获取该对象的特定属性,如下所示:
this.localStorage.get('myObject').prop1;
但是这样做给了我错误 Property 'prop1' does not exist on type '{}'
我还尝试将对象存储在局部变量中,然后尝试访问该属性,但它给了我同样的错误。
var myObject = this.localStorage.get('myObject');
var myProperty = myObject.prop1;
我做错了什么,如何访问数据?
我正在尝试将以下C#代码转换为VB.NET.问题在于lambda表达式.
public class UserStore
{
private readonly IDatabaseFactory _databaseFactory;
private DataContext _db;
protected DataContext Db => _db ?? (_db = _databaseFactory.GetDataContext());
public UserStore(IDatabaseFactory databaseFactory)
{
_databaseFactory = databaseFactory;
}
}
Run Code Online (Sandbox Code Playgroud)
以下是我将代码转换为:
Public Class UserStore
Private ReadOnly _databaseFactory As IDatabaseFactory
Private _db As DataContext
Protected Db As DataContext = Function() As DataContext
If _db Is Nothing Then
_db = _databaseFactory.GetDataContext()
End If
Return _db
End Function
Public Sub New(databaseFactory As IDatabaseFactory)
_databaseFactory = databaseFactory
End Sub
End Class
Run Code Online (Sandbox Code Playgroud)
由于某种原因,转换后的lambda会给出错误 Lambda expression …
所以我正在调用一个API,它返回我的Angular文件,如下所示:
getFile(fileInformation) {
const req = new HttpRequest('POST', 'filedownload', fileInformation, { reportProgress: true, responseType: "blob" });
return this.http.request(req);
}
Run Code Online (Sandbox Code Playgroud)
在API控制器中(我按照这个SO的最佳答案来说明这一步):
Public Function GetFile(fileInformation As FileDto) As HttpResponseMessage
Dim filePath = Path.Combine(FileConstants.FilePath, fileInformation.FileType, fileInformation.FileName)
Dim fileStream = New FileStream(filePath, FileMode.Open, FileAccess.Read)
Dim result = new HttpResponseMessage(HttpStatusCode.OK)
result.Content = New StreamContent(fileStream)
result.Content.Headers.ContentType = new MediaTypeHeaderValue("application/octet-stream")
Return result
End Function
Run Code Online (Sandbox Code Playgroud)
此调用返回的结果是HttpResponse,而body是类型Blob.
HttpResponse: {
blob: {
size: 289940,
type: "application/octet-stream"
},
headers: ...,
status: 200,
...
}
Run Code Online (Sandbox Code Playgroud)
现在,我如何在收到响应的Angular组件中触发此文件的下载?