public static ProtoSerializer BuildSerializer(IProtoSerializer head, TypeModel model) { ProtoSerializer protoSerializer; Type expectedType = head.ExpectedType; try { CompilerContext compilerContext = new CompilerContext(expectedType, true, true, model, typeof(object)); compilerContext.LoadValue(compilerContext.InputValue); compilerContext.CastFromObject(expectedType); compilerContext.WriteNullCheckedTail(expectedType, head, null); compilerContext.Emit(OpCodes.Ret); protoSerializer = (ProtoSerializer)compilerContext.method.CreateDelegate(typeof(ProtoSerializer)); } catch (Exception exception1) { Exception exception = exception1; string fullName = expectedType.FullName; if (string.IsNullOrEmpty(fullName)) { fullName = expectedType.Name; } throw new InvalidOperationException(string.Concat("It was not possible to prepare a serializer for: ", fullName), exception); } return(protoSerializer); }
public static ProtoSerializer BuildSerializer(IProtoSerializer head) { Type type = head.ExpectedType; CompilerContext ctx = new CompilerContext(type, true, true); ctx.LoadValue(Local.InputValue); ctx.CastFromObject(type); ctx.WriteNullCheckedTail(type, head, null); ctx.Emit(OpCodes.Ret); return (ProtoSerializer)ctx.method.CreateDelegate( typeof(ProtoSerializer)); }
public static ProtoSerializer BuildSerializer(IProtoSerializer head, TypeModel model) { Type type = head.ExpectedType; CompilerContext ctx = new CompilerContext(type, true, true, model); ctx.LoadValue(Local.InputValue); ctx.CastFromObject(type); ctx.WriteNullCheckedTail(type, head, null); ctx.Emit(OpCodes.Ret); return((ProtoSerializer)ctx.method.CreateDelegate( typeof(ProtoSerializer))); }
public static ProtoSerializer BuildSerializer(IProtoSerializer head, TypeModel model) { Type type = head.ExpectedType; try { CompilerContext ctx = new CompilerContext(type, true, true, model, typeof(object)); ctx.LoadValue(ctx.InputValue); ctx.CastFromObject(type); ctx.WriteNullCheckedTail(type, head, null); ctx.Emit(OpCodes.Ret); return (ProtoSerializer)ctx.method.CreateDelegate( typeof(ProtoSerializer)); } catch (Exception ex) { string name = type.FullName; if(string.IsNullOrEmpty(name)) name = type.Name; throw new InvalidOperationException("It was not possible to prepare a serializer for: " + name, ex); } }
public static ProtoSerializer BuildSerializer(IProtoSerializer head, TypeModel model) { Type type = head.ExpectedType; try { CompilerContext ctx = new CompilerContext(type, true, true, model, typeof(object)); ctx.LoadValue(ctx.InputValue); ctx.CastFromObject(type); ctx.WriteNullCheckedTail(type, head, null); ctx.Emit(OpCodes.Ret); return((ProtoSerializer)ctx.method.CreateDelegate( typeof(ProtoSerializer))); } catch (Exception ex) { string name = type.FullName; if (string.IsNullOrEmpty(name)) { name = type.Name; } throw new InvalidOperationException("It was not possible to prepare a serializer for: " + name, ex); } }