private void _UpdateSetProperty(long entity_id, int property, byte[] buffer) { IGhost ghost = _FindGhost(entity_id); if (ghost == null) { return; } MemberMap map = _Protocol.GetMemberMap(); PropertyInfo info = map.GetProperty(property); object value = _Serializer.Deserialize(buffer); object instance = ghost.GetInstance(); Type type = _InterfaceProvider.Find(info.DeclaringType); FieldInfo field = type.GetField("_" + info.Name, BindingFlags.Instance | BindingFlags.Public); if (field != null) { object filedValue = field.GetValue(instance); IAccessable updateable = filedValue as IAccessable; updateable.Set(value); PackageSetPropertyDone pkg = new PackageSetPropertyDone(); pkg.EntityId = entity_id; pkg.Property = property; _Requester.Request(ClientToServerOpCode.UpdateProperty, pkg.ToBuffer(_Serializer)); } }
private IObjectAccessible _GetAccesser(PackagePropertySoul data, IGhost owner) { MemberMap map = _Protocol.GetMemberMap(); PropertyInfo info = map.GetProperty(data.PropertyId); var type = _InterfaceProvider.Find(info.DeclaringType); var fieldName = _GetFieldName(info); FieldInfo field = type.GetField(fieldName, BindingFlags.Instance | BindingFlags.Public); object filedValue = field.GetValue(owner.GetInstance()); return(filedValue as IObjectAccessible); }
private void _InvokeEvent(long ghost_id, int event_id, long handler_id, byte[][] event_params) { IGhost ghost = _FindGhost(ghost_id); if (ghost == null) { return; } MemberMap map = _Protocol.GetMemberMap(); EventInfo info = map.GetEvent(event_id); object instance = ghost.GetInstance(); Type type = instance.GetType(); var fieldName = _GetFieldName(info); FieldInfo eventInfos = type.GetField(fieldName, BindingFlags.Instance | BindingFlags.Public); object fieldValue = eventInfos.GetValue(instance); if (fieldValue is GhostEventHandler) { GhostEventHandler fieldValueDelegate = fieldValue as GhostEventHandler; object[] pars = (from a in event_params select _Serializer.Deserialize(a)).ToArray(); try { fieldValueDelegate.Invoke(handler_id, pars); } catch (TargetInvocationException tie) { Regulus.Utility.Log.Instance.WriteInfo(string.Format("Call event error in {0}:{1}. \n{2}", type.FullName, info.Name, tie.InnerException.ToString())); throw tie; } catch (Exception e) { Regulus.Utility.Log.Instance.WriteInfo(string.Format("Call event error in {0}:{1}.", type.FullName, info.Name)); throw e; } } }