I've previously asked a question "How to get the Type of an Array of Nullable Primitive?" How to get the Type of an Array of Nullable Primitive?.
In that question, I have a class in my c# program and I was able to use reflection to find out the properties name/type/array(or not)/nullable(or not).
Now, I want to do the same but the class is read in from a file (and not part of the c# program). I check online for some codes that I can compile the file using CSharpCompilation.Create() into an assembly. By trial and error, I manage to print out the name and type.
Assembly a = Assembly.Load(ms.ToArray());
var _prop = a.GetType("ClassName").GetProperties();
foreach (var _p in _prop)
{
Console.WriteLine(_p.Name);
Console.WriteLine(_p.GetMethod.ReturnType.Name);
Console.WriteLine();
}
I don't know if this is the correct way to get the information. But my problem now is that I cannot find out if the type is an array and/or a nullable type. In my previous question, I learnt that I can use
var type = _propertyType.GetElementType();
type = Nullable.GetUnderylingType(type) ?? type;
var UType = type.Name;
to get the nullable. In my current example, how do I know if the property is an array and/or nullable ? The package I'm using:
using Microsoft.CodeAnalysis;
using Microsoft.CodeAnalysis.CSharp;
using Microsoft.CodeAnalysis.Emit;
using System.Reflection;
Thanks.