private void LoadComponent(ComponentXML xmlComponent) { Type tipoComponente; if (xmlComponent.type == typeof(Script).FullName) { FieldValueXML fvScriptName = xmlComponent.FindAttribute("__ScriptName__"); if (fvScriptName != null && fvScriptName.value != null) { ScriptResource scriptRes = (ScriptResource)Resource.FindResource(typeof(ScriptResource), (String)fvScriptName.ValueAs(typeof(String))); if (scriptRes != null) { tipoComponente = scriptRes.ScriptType; } else { tipoComponente = null; } } else { tipoComponente = null; } } else { tipoComponente = Type.GetType(xmlComponent.type); } if (tipoComponente != null) { Component comp = (Component)tipoComponente.GetConstructor(Type.EmptyTypes).Invoke(null); comp.ForceId(xmlComponent.id); handledComponents.Add(comp.Id, comp); AccesorValor[] accesoresValores = comp.GetAccesoresValores(); object val; foreach (AccesorValor accesor in accesoresValores) { if (LoadValueComponent(xmlComponent, accesor, out val)) { accesor.Value = val; } } } }
private bool LoadValueComponent(ComponentXML xmlComponent, AccesorValor accesor, out object val) { FieldValueXML fv = xmlComponent.FindAttribute(accesor.ValueName); Type tipo = accesor.ValueType; if (fv != null && fv.value != null) { if (typeof(Component).IsAssignableFrom(tipo)) { uint id = (uint)fv.ValueAs(typeof(uint)); Component otComp; if (id != uint.MaxValue) { if (handledComponents.TryGetValue(id, out otComp) == false) { otComp = null; } } else { otComp = Entity.Root; } if (otComp != null && tipo.IsAssignableFrom(otComp.GetType())) { val = otComp; return(true); } } else if (typeof(Resource).IsAssignableFrom(tipo)) { String resName = (String)fv.ValueAs(typeof(string)); Resource res = Resource.FindResource(tipo, resName); if (res != null) { val = res; return(true); } else { val = null; return(false); } } else if (tipo.IsEnum) { try { val = Enum.Parse(tipo, (String)fv.ValueAs(typeof(String)), true); return(true); } catch (ArgumentException) { } } else { val = fv.ValueAs(tipo); return(true); } } val = null; return(false); }