How do i set an array by using SetDynamic()?

Options
JulianKaulitzki
edited December 2016 in Photon Bolt
Hey guys,

How do i change an array by using the IState.SetDynamic(propertyName, object) fuction?


I thought of this:

NetworkArray_String NA_S = (NetworkArray_String)state.GetDynamic("ItemDatas[]");
for(int i = 0; i < NA_S.Length; i++)
{
//i want to change the items here.
}
state.SetDynamic("ItemDatas[]", NA_S);

but that throws a null reference exception for "NA_S". So what am i doing wrong?

or this:

List PropertiesToReturn = new List();
NetworkArray_String nas = null;
foreach (PropertyInfo property in state.GetType().GetProperties())
{
object o = null;
if (!state.TryGetDynamic(property.Name, out o))
{
object obj = property.GetValue(state, null);

if (state.TryGetDynamic(property.Name + "[]", out o))
{
if (obj != null && obj is NetworkArray_String)
{
nas = (NetworkArray_String)obj;
for(int i = 0; i < nas.Length; i ++)
{
nas[i] = "New Item " + i;
}
foreach (var s in nas)
{
if (s != null)
{

}
}
}
}
}
}

state.SetDynamic("ItemDatas[]", nas);

which throws:
InvalidCastException: Cannot cast from source type to destination type.
Bolt.NetworkProperty_String.SetDynamic (Bolt.NetworkObj obj, System.Object value)

Cheers Julian Kaulitzki

Comments