小编Kev*_*onn的帖子

在编译时检测c#版本

我有一个旧的c#代码行,看起来基本上是这样的:

foo.set_Parent(parent);
Run Code Online (Sandbox Code Playgroud)

它已经编好了多年.现在在VS2015中我收到错误:

CS0571'Foo.Parent.set':无法显式调用运算符或访问器

所以我可以改写这行:

foo.Parent=parent;
Run Code Online (Sandbox Code Playgroud)

这在VS2015中构建得很好,但是在VS2013中它给出了错误:

语言不支持'Foo.Parent'; 尝试直接调用访问器方法'Foo.get_Parent()'或Foo.set_Parent(Foo)'

因此,简单的解决方法是简单地根据正在运行的编译器版本来定义这两行.但是,如何检测正在执行的编译器版本?

而且,对于记录,不,我不能只是要求团队中的每个人同时升级到VS2015.

附加信息 - 对于每个闻到老鼠的人来说,我会继续拖出丑陋的真相,尽管我认为它不会改变任何东西.Foo类是来自一个古老的Borland集合体,它在Delphi中都是绑定的(是的,我们正在迁移,但还没有迁移).因此,编译为VS2013的实际代码如下所示:

using Borland.Vcl;
using RepGen;
using SnapReportsForm;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.InteropServices;

namespace MigrantCOM {
   [ComVisible(true)]
   [Guid("48245BA3-736B-4F98-BDC5-AD86F77E39F4")]
   [ProgId("MigrantCOM.Exports")]
   [ClassInterface(ClassInterfaceType.AutoDual)]
          public class MigrantCLRExports {   // : MarshalByRefObject 
      public string Test(string s) { return s+s; }
   }

   [ComVisible(true)]
   [Guid("1154D364-B588-4C31-88B9-141072303117")]
   [ProgId("MigrantCOM.SnapRepCOM")]
   [ClassInterface(ClassInterfaceType.AutoDual)]
   public class SnapRepCOM {
      TRepGen repGen;
      TStringList snapRefs=new TStringList();
      TForm parent=new TForm(null);
      TMemo designerMemo;
      List<TReference> references=new List<TReference>();
      TRunAsSnapContext runAsSnapContext=new TRunAsSnapContext();

      public SnapRepCOM() {
         designerMemo=new TMemo(parent); …
Run Code Online (Sandbox Code Playgroud)

c# preprocessor-directive

10
推荐指数
1
解决办法
379
查看次数

无需管理员即可从c#以编程方式检测BitLocker

从各种线程我拼凑如何以编程方式检查BitLocker像这样:

private void TestBitLockerMenuItem_Click(object sender, RoutedEventArgs e) {
   var path=new ManagementPath(@"\ROOT\CIMV2\Security\MicrosoftVolumeEncryption")
               { ClassName="Win32_EncryptableVolume" };
   var scope=new ManagementScope(path);
   path.Server=Environment.MachineName;
   var objectSearcher=new ManagementClass(scope, path, new ObjectGetOptions());
   foreach (var item in objectSearcher.GetInstances()) {
      MessageBox.Show(item["DeviceID"].ToString()+" "+item["ProtectionStatus"].ToString());
   }
}
Run Code Online (Sandbox Code Playgroud)

但它仅在进程具有管理员权限时才有效.

看起来奇怪的是,任何旧的Windows用户都可以转到资源管理器,右键单击某个驱动器,然后查看它是否已启用BitLocker,但程序似乎无法完成此操作.有谁知道这样做的方法?

c# bitlocker

7
推荐指数
1
解决办法
3466
查看次数

只能访问localhost上的asp.net应用程序

我正在尝试在Windows Server 2008计算机上的IIS上获取asp.net应用程序.我可以从localhost点击应用程序,没问题.但我无法在本地或从网络上的其他计算机使用服务器的域名访问应用程序.

但这是奇怪的部分.我可以使用域名访问IIS上的普通文件,无论是从服务器上运行的浏览器还是从网络上另一台机器上运行的浏览器.这是一个概要(下面的"http"转换为"htp",因为我没有足够的点来在我的消息中包含所有这些链接):

从IE上的服务器本身:
工作htp://localhost/foo.htm
工作htp:// localhost/App
工作原理htp://test.foo.com/foo.htm
dead htp://test.foo.com/应用

从另一台机器上的IE:
工作htp://test.foo.com/foo.htm
dead htp://test.foo.com/App

当我说"死"时,我的意思是请求超时.

有任何想法吗?

asp.net iis

5
推荐指数
1
解决办法
1万
查看次数

标签 统计

c# ×2

asp.net ×1

bitlocker ×1

iis ×1

preprocessor-directive ×1