public void WriteKey(IKey key, object instance, ILogPrinter inLogger) { Vector3 v = (Vector3)instance; key.AddValue(v.x); key.AddValue(v.y); key.AddValue(v.z); }
public void WriteKey(IKey key, object instance, ILogPrinter inLogger) { NamedId[] arr = (NamedId[])instance; for (int i = 0; i < arr.Length; i++) { key.AddValue(arr[i].name); } }
void AddValueToKey(IKey key, object instance) { if (instance == null) { key.AddValue(0); } else if (instance is bool) { key.AddValue(Convert.ToBoolean(instance)); } else if (instance is float) { key.AddValue(Convert.ToSingle(instance)); } else if (instance is double) { key.AddValue(Convert.ToDouble(instance)); } else if (instance is byte) { key.AddValue(Convert.ToByte(instance)); } else if (instance is short) { key.AddValue(Convert.ToInt16(instance)); } else if (instance is ushort) { key.AddValue(Convert.ToUInt16(instance)); } else if (instance is int) { key.AddValue(Convert.ToInt32(instance)); } else if (instance is uint) { key.AddValue(Convert.ToUInt32(instance)); } else if (instance is long) { key.AddValue(Convert.ToInt64(instance)); } else if (instance is ulong) { key.AddValue(Convert.ToUInt64(instance)); } else { key.AddValue(instance.ToString()); } }
void SerializeClass(object instance, Type type, IKey inKey, int inInheriteDeep, ILogPrinter inLogger) { MethodInfo mi = type.GetMethod("SerializationToCscd", new Type[] { typeof(CascadeParser.IKey), typeof(CascadeParser.ILogPrinter) }); if (mi != null) { if (string.IsNullOrEmpty(inKey.GetName())) { inKey.SetName("Value"); } mi.Invoke(instance, new object[] { inKey, inLogger }); return; } MemberInfo[] member_infos = _reflectionProvider.GetSerializableMembers(type); foreach (MemberInfo memberInfo in member_infos) { object value = _reflectionProvider.GetValue(memberInfo, instance); if (value == null) { continue; } SCustomMemberParams member_params = GetMemberParams(memberInfo); if (member_params.DefaultValue != null) { if (member_params.DefaultValue.GetType() != value.GetType()) { LogError(inLogger, string.Format("DefaultValue and member {2} of class {3} have difference types: {0} and {1}", member_params.DefaultValue.GetType().Name, value.GetType().Name, member_params.Name, type.Name)); } else if (member_params.DefaultValue.Equals(value)) { continue; } } else if (ReflectionHelper.IsDefault(value, _reflectionProvider, inLogger)) { continue; } IKey child = inKey.CreateChildKey(member_params.ChangedName); Type real_type = value.GetType(); Type member_type = memberInfo.GetMemberType(); if (member_params.Converter != null && member_params.Converter.CanConvert(real_type)) { member_params.Converter.WriteKey(child, value, inLogger); } else { Serialize(value, real_type, child, 0, inLogger); } // Write the runtime type if different (except nullables since they get unboxed) if (real_type != member_type && !member_type.IsNullable()) { IKey obj_type_key = child.CreateChildKey("RealObjectType"); obj_type_key.AddValue(real_type.FullName); obj_type_key.AddValue(real_type.Assembly.FullName); } } }
public void SerializationToCscd(IKey key, ILogPrinter inLogger) { key.AddValue(x); key.AddValue(y); key.AddValue(z); }
public void SerializationToCscd(IKey key, ILogPrinter inLogger) { key.AddValue(name); }