-1
아래 코드를 기반으로 리플렉션을 사용하여 배열 속성을 인스턴스화하려면 어떻게해야합니까?리플렉션을 사용하여 배열 요소의 형식을 검색하는 중
는public class Foo
{
public Foo()
{
foreach(var property in GetType().GetProperties())
{
if (property.PropertyType.IsArray)
{
// the line below creates a 2D array of type Bar. How to fix?
var array = Array.CreateInstance(property.PropertyType, 0);
property.SetValue(this, array, null);
}
}
}
public Bar[] Bars {get;set;}
}
public class Bar
{
public string Name {get;set;}
}
감사의 말. –