编辑:我已将结果写成博客文章.
C#编译器有点神奇地处理COM类型.例如,这个陈述看起来很正常......
Word.Application app = new Word.Application();
Run Code Online (Sandbox Code Playgroud)
......直到你意识到这Application是一个界面.在接口上调用构造函数?Yoiks!这实际上被转换为对Type.GetTypeFromCLSID()另一个的调用Activator.CreateInstance.
此外,在C#4中,您可以对ref参数使用非ref 参数,并且编译器只是添加一个局部变量以通过引用传递,丢弃结果:
// FileName parameter is *really* a ref parameter
app.ActiveDocument.SaveAs(FileName: "test.doc");
Run Code Online (Sandbox Code Playgroud)
(是的,有一堆参数丢失.不是可选参数好吗?:)
我正在尝试调查编译器的行为,我没有假装第一部分.我可以做第二部分没有问题:
using System;
using System.Runtime.InteropServices;
using System.Runtime.CompilerServices;
[ComImport, GuidAttribute("00012345-0000-0000-0000-000000000011")]
public interface Dummy
{
void Foo(ref int x);
}
class Test
{
static void Main()
{
Dummy dummy = null;
dummy.Foo(10);
}
}
Run Code Online (Sandbox Code Playgroud)
我想能够写:
Dummy dummy = new Dummy();
Run Code Online (Sandbox Code Playgroud)
虽然.显然它会在执行时爆炸,但没关系.我只是在试验.
编译器为链接的COM PIA(CompilerGenerated和TypeIdentifier)添加的其他属性似乎没有做到这一点......什么是神奇的酱油?
var types=from m in System.Reflection.Assembly.Load("System").GetTypes()
where m.IsClass
where // something to check whether or not the type is a static class.
select m;
Run Code Online (Sandbox Code Playgroud)
我想从我的结果中填写任何静态类.
我正在使用AzureAd Powershell 模块进行用户管理。但是,它没有我需要的所有功能,特别是,我无法将应用程序扩展值分配给对象(尽管我可以通过创建删除和删除应用程序扩展本身[Get/New/Remove]-AzureADApplicationExtensionProperty)。
通过使用Fiddler观察 API 调用,我知道图形调用正在使用不记名令牌,并且我已直接从 Postman 手动调用图形 API,因此我知道如何使用不记名令牌(如果可以获得)。我怎样才能得到它?