Невозможно привести объект типа «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

2022-01-20T16:00:48+00:00