// Token: 0x0600022C RID: 556 RVA: 0x0000EFF0 File Offset: 0x0000D1F0 public static ParseableSerializer TryCreate(Type type, TypeModel model) { if (type == null) { throw new ArgumentNullException("type"); } MethodInfo method = type.GetMethod("Parse", BindingFlags.DeclaredOnly | BindingFlags.Static | BindingFlags.Public, null, new Type[] { model.MapType(typeof(string)) }, null); if (method != null && method.ReturnType == type) { if (Helpers.IsValueType(type)) { MethodInfo customToString = ParseableSerializer.GetCustomToString(type); if (customToString == null || customToString.ReturnType != model.MapType(typeof(string))) { return(null); } } return(new ParseableSerializer(method)); } return(null); }
void ProtoBuf.Serializers.IProtoSerializer.EmitWrite(CompilerContext ctx, Local valueFrom) { Type expectedType = this.ExpectedType; if (!expectedType.IsValueType) { ctx.EmitCall(ctx.MapType(typeof(object)).GetMethod("ToString")); } else { using (Local localWithValue = ctx.GetLocalWithValue(expectedType, valueFrom)) { ctx.LoadAddress(localWithValue, expectedType); ctx.EmitCall(ParseableSerializer.GetCustomToString(expectedType)); } } ctx.EmitBasicWrite("WriteString", valueFrom); }