Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/334.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
在c#SemanticModel中,有没有一种方法可以区分可空值类型和引用类型?_C#_Refactoring_Nullable - Fatal编程技术网

在c#SemanticModel中,有没有一种方法可以区分可空值类型和引用类型?

在c#SemanticModel中,有没有一种方法可以区分可空值类型和引用类型?,c#,refactoring,nullable,C#,Refactoring,Nullable,我正试图在使用新的可空语法的类上编写一个自定义c#8重构 我告诉你“实际”类型和“可空”类型之间的区别 通过检查类型名称末尾的“?”来输入 问题是如何知道哪些变量需要“.Value”来获取值 哪些变量没有 例如: #nullable enable public class C { public int actualInt {get; set;} public int? nullableInt {get; set;} public string actualString {g

我正试图在使用新的可空语法的类上编写一个自定义c#8重构

我告诉你“实际”类型和“可空”类型之间的区别 通过检查类型名称末尾的“?”来输入

问题是如何知道哪些变量需要“.Value”来获取值 哪些变量没有

例如:

#nullable enable

public class C 
{
   public int actualInt {get; set;}
   public int? nullableInt {get; set;}
   public string actualString {get; set;}
   public string? nullableString {get; set;}
}
一旦我有了symantic模型,我可以得到如下符号信息:

IPropertySymbol symbolInfo = SemanticModel.GetDeclaredSymbol(property) as IPropertySymbol;
但对于“现实”,我看到它是有

symbolInfo.Type.Name==“Int32”(良好)

IsReferenceType==真(嗯?)

IsValueType==false(嗯?)


我希望看到IsValueType==true

您这样做只是为了确定属性的类型是否可以为null?如果是这样的话,您是否尝试过使用PropertyInfo执行此操作?@Tayyab:我认为PropertyInfo是System.Reflection的一部分,可以在运行时使用它查看有关属性的信息。在运行应用程序之前,我需要我的信息。我正在尝试创建一个重构,可以从编译中查看语法树和语义模型,但它不会创建要反映的类实例。