How get the default namespace of project csproj (VS 2008)

前端 未结 5 1564
终归单人心
终归单人心 2020-12-20 14:05

I have VS 2008 and csproj project (C# Library).

In properties of project, has an assembly name, and default namespace. Note: each class has a namespace.

Is

5条回答
  •  有刺的猬
    2020-12-20 14:46

    I wrote an extension method for Assembly that just finds the resource by its filename within the included resources:

    public static Stream GetManifestResourceStreamByFileName(this Assembly assembly, string fileName)
    {
        var targetName = assembly.GetManifestResourceNames()
            .FirstOrDefault(x => x.EndsWith("." + fileName));
    
        return targetName == null ? null : assembly.GetManifestResourceStream(targetName);
    
    }
    

    then you just call like so:

        var assembly = Assembly.GetExecutingAssembly(); // or Assembly.GetAssembly(this.GetType()) or whatever
    
        var myResource = assembly.GetManifestResourceStreamByFileName("myResource.jpg");
    

提交回复
热议问题