public MonitorProperty(string path, Func <object> getInstance, PropertyInfo propertyInfo) : base(path, getInstance) { this.propertyInfo = propertyInfo; this.typeHandler = TypeHandlersManager.GetTypeHandler(this.propertyInfo.PropertyType); this.isStruct = this.propertyInfo.PropertyType.IsStruct(); try { this.value = this.propertyInfo.GetValue(this.getInstance()); } catch (Exception ex) { InternalNGDebug.LogException("Monitoring property \"" + path + "\" (" + propertyInfo.PropertyType.FullName + ") failed.", ex); throw; } this.MonitorSubData(this.propertyInfo.PropertyType, () => this.propertyInfo.GetValue(this.getInstance())); }
public override Packet[] CreateUpdatePackets() { Packet[] packets = new Packet[this.lastSize + 1]; packets[0] = new NotifyFieldValueUpdatedPacket(this.path, this.sizeHandler.Serialize(this.lastSize)); Type subType = Utility.GetArraySubType(this.fieldInfo.Type); TypeHandler subTypeHandler = TypeHandlersManager.GetTypeHandler(subType); IEnumerable array = this.fieldInfo.GetValue(this.getInstance()) as IEnumerable; int i = 0; foreach (object element in array) { packets[i + 1] = new NotifyFieldValueUpdatedPacket(this.path + NGServerScene.ValuePathSeparator + i, subTypeHandler.Serialize(subType, element)); ++i; } return(packets); }
public static void Serialize(ByteBuffer buffer, object instance, IFieldModifier field) { using (SafeWrapByteBuffer.Get(buffer)) { buffer.AppendUnicodeString(field.Type.GetShortAssemblyType()); buffer.AppendUnicodeString(field.Name); buffer.Append(field.IsPublic); TypeHandler handler = TypeHandlersManager.GetTypeHandler(field.Type); if (handler != null) { if (field.MemberInfo.DeclaringType.IsGenericTypeDefinition == false || ((field is FieldModifier) == true && (field as FieldModifier).fieldInfo.IsLiteral == true)) { buffer.AppendUnicodeString(handler.GetType().GetShortAssemblyType()); try { buffer.Append((byte)TypeHandlersManager.GetTypeSignature(field.Type)); ByteBuffer handlerBuffer = Utility.GetBBuffer(); handler.Serialize(handlerBuffer, field.Type, field.GetValue(instance)); buffer.Append(Utility.ReturnBBuffer(handlerBuffer)); } catch (Exception ex) { buffer.Append((byte)TypeSignature.Null); InternalNGDebug.LogException("Member \"" + field.Name + "\" failed.", ex); throw; } } else // Leave it unsupported. { buffer.Append(0); } } else { buffer.Append(0); } } }
private NetField(ByteBuffer buffer) { using (SafeUnwrapByteBuffer unwrap = SafeUnwrapByteBuffer.Get(buffer, this.GetError)) { this.fieldType = Type.GetType(buffer.ReadUnicodeString()); this.name = buffer.ReadUnicodeString(); this.isPublic = buffer.ReadBoolean(); string typeHandlerType = buffer.ReadUnicodeString(); if (string.IsNullOrEmpty(typeHandlerType) == false) { this.handler = TypeHandlersManager.GetTypeHandler(typeHandlerType); if (this.handler != null) { this.typeSignature = (TypeSignature)buffer.ReadByte(); this.fieldType = this.fieldType ?? TypeHandlersManager.GetClientType(this.handler.type, this.typeSignature); if (this.typeSignature != TypeSignature.Null) { try { this.value = this.handler.Deserialize(buffer, this.fieldType ?? TypeHandlersManager.GetClientType(this.handler.type, this.typeSignature)); } catch (Exception ex) { InternalNGDebug.LogException("Member \"" + this.name + "\" of type \"" + this.fieldType + "\" failed.", ex); throw; } } } else // Client does not know how to deserialize this field. { unwrap.ForceFallback(); } } } }
public ClientUpdateFieldValuePacket(string fieldPath, byte[] rawValue, TypeHandler deserializer) { this.fieldPath = fieldPath; this.rawValue = rawValue; this.deserializer = deserializer; }
public MonitorColor(string path, Func <object> getInstance, IValueGetter valueGetter) : base(path, getInstance) { this.valueGetter = valueGetter; this.typeHandler = TypeHandlersManager.GetTypeHandler(valueGetter.Type); this.value = valueGetter.GetValue <Color>(this.getInstance()); }