Пример #1
0
        // Token: 0x060035AF RID: 13743 RVA: 0x00134D64 File Offset: 0x00133164
        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);
        }
Пример #2
0
        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);
        }