Невозможно привести объект типа «System.Object []» к «MyObject []», что дает?
Альтернативный ответ: дженерики.
public static T[] CreateProperties(IProperty[] properties)
where T : class, new()
{
//Empty so return null
if (properties==null || properties.Length == 0)
return null;
//Check the type is allowed
CheckPropertyTypes("CreateProperties(Type,IProperty[])",typeof(T));
//Convert the array of intermediary IProperty objects into
// the passed service type e.g. Service1.Property
T[] result = new T[properties.Length];
for (int i = 0; i < properties.Length; i++)
{
T[i] = new T();
ServiceUtils.CopyProperties(properties[i], t[i]);
}
return result;
}
Тогда c#.net ваш вызывающий код станет:
Property[] props = ObjectFactory.CreateProperties(properties);
_service.SetProperties(folderItem.Path, props);
Намного bytearray чище :)
c#
.net
arrays
reflection
casting
2021-12-06T23:42:15+00:00
2022-01-20T16:00:48+00:00
LynxTheCatYet
Вопросы с похожей тематикой, как у вопроса:
Невозможно привести объект типа «System.Object []» к «MyObject []», что дает?
Предупреждение о файлах Cookies
Мы используем файлы cookies для улучшения работы сайта. Оставаясь на нашем сайте, вы соглашаетесь с условиями использования файлов cookies. Чтобы ознакомиться с нашими Положениями о конфиденциальности и об использовании файлов cookie, нажмите здесь.