/// <summary> /// Creates a new instance from a protocol-buffer stream /// </summary> /// <param name="type">The type to be created.</param> /// <param name="source">The binary stream to apply to the new instance (cannot be null).</param> /// <returns>A new, initialized instance.</returns> public static object Deserialize(System.Type type, Stream source) { if (typeof(IParseable).IsAssignableFrom(type)) { ProtoReader reader = null; object obj = null; try { reader = ProtoReader.Create(source, RuntimeTypeModel.Default, null, -1); //if (value != null) reader.SetRootObject(value); //object obj = DeserializeCore(reader, type, value, autoCreate); obj = Activator.CreateInstance(type); IParseable objProxy = obj as IParseable; objProxy.Parse(reader); reader.CheckFullyConsumed(); return(obj); } finally { ProtoReader.Recycle(reader); } return(obj); } UnityEngine.Debug.LogWarning("Old Form Load Table " + type.Name + "!!"); return(RuntimeTypeModel.Default.Deserialize(source, null, type)); }
/// <summary> /// Convert string to any of the supported types. /// </summary> /// <param name="param"></param> /// <param name="paramType"></param> /// <returns></returns> object ParseParameter(string param, Type paramType) { if (typeof(string).IsAssignableFrom(paramType)) { return(param); } if (typeof(int).IsAssignableFrom(paramType) && int.TryParse(param, out int result)) { return(result); } if (typeof(ulong).IsAssignableFrom(paramType) && ulong.TryParse(param, out ulong uResult)) { return(uResult); } if (typeof(bool).IsAssignableFrom(paramType) && bool.TryParse(param, out bool boolResult)) { return(boolResult); } if (typeof(Enum).IsAssignableFrom(paramType)) { object enumResult = null; Enum.TryParse(paramType, param, out enumResult); return(enumResult); } else if (typeof(IParseable).IsAssignableFrom(paramType)) { try { IParseable obj = (IParseable)Activator.CreateInstance(paramType); obj.Parse(param); return(obj); } catch (Exception) { return(null); } } return(null); }
public static object ParseEx(System.Type type, Stream source) { ProtoReader reader = null; object obj = null; try { reader = ProtoReader.Create(source, RuntimeTypeModel.Default, null, -1); //if (value != null) reader.SetRootObject(value); //object obj = DeserializeCore(reader, type, value, autoCreate); obj = Activator.CreateInstance(type); IParseable objProxy = obj as IParseable; objProxy.Parse(reader); reader.CheckFullyConsumed(); return(obj); } finally { ProtoReader.Recycle(reader); } return(obj); }
public override ParseTree Parse(Lexer lexer, ParserState state) { return(implementation.Parse(lexer, state)); }