private void EmitCreateIfNull(CompilerContext ctx, Local storage) { if (!this.ExpectedType.IsValueType) { CodeLabel codeLabel = ctx.DefineLabel(); ctx.LoadValue(storage); ctx.BranchIfTrue(codeLabel, false); ((IProtoTypeSerializer)this).EmitCreateInstance(ctx); if (this.callbacks != null) { TypeSerializer.EmitInvokeCallback(ctx, this.callbacks.BeforeDeserialize, true, null, this.forType); } ctx.StoreValue(storage); ctx.MarkLabel(codeLabel); } }
void ProtoBuf.Serializers.IProtoTypeSerializer.EmitCreateInstance(CompilerContext ctx) { bool flag = true; if (this.factory != null) { TypeSerializer.EmitInvokeCallback(ctx, this.factory, false, this.constructType, this.forType); } else if (!this.useConstructor) { ctx.LoadValue(this.constructType); ctx.EmitCall(ctx.MapType(typeof(BclHelpers)).GetMethod("GetUninitializedObject")); ctx.Cast(this.forType); } else if (!this.constructType.IsClass || !this.hasConstructor) { ctx.LoadValue(this.ExpectedType); ctx.EmitCall(ctx.MapType(typeof(TypeModel)).GetMethod("ThrowCannotCreateInstance", BindingFlags.Static | BindingFlags.Public)); ctx.LoadNullRef(); flag = false; } else { ctx.EmitCtor(this.constructType); } if (flag) { ctx.CopyValue(); ctx.LoadReaderWriter(); ctx.EmitCall(ctx.MapType(typeof(ProtoReader)).GetMethod("NoteObject", BindingFlags.Static | BindingFlags.Public)); } if (this.baseCtorCallbacks != null) { for (int i = 0; i < (int)this.baseCtorCallbacks.Length; i++) { TypeSerializer.EmitInvokeCallback(ctx, this.baseCtorCallbacks[i], true, null, this.forType); } } }
void ProtoBuf.Serializers.IProtoTypeSerializer.EmitCallback(CompilerContext ctx, Local valueFrom, TypeModel.CallbackType callbackType) { MethodInfo item; bool flag = false; if (this.CanHaveInheritance) { for (int i = 0; i < (int)this.serializers.Length; i++) { IProtoSerializer protoSerializer = this.serializers[i]; if (protoSerializer.ExpectedType != this.forType && ((IProtoTypeSerializer)protoSerializer).HasCallbacks(callbackType)) { flag = true; } } } if (this.callbacks == null) { item = null; } else { item = this.callbacks[callbackType]; } MethodInfo methodInfo = item; if (methodInfo == null && !flag) { return; } ctx.LoadAddress(valueFrom, this.ExpectedType); TypeSerializer.EmitInvokeCallback(ctx, methodInfo, flag, null, this.forType); if (flag) { CodeLabel codeLabel = ctx.DefineLabel(); for (int j = 0; j < (int)this.serializers.Length; j++) { IProtoSerializer protoSerializer1 = this.serializers[j]; Type expectedType = protoSerializer1.ExpectedType; if (expectedType != this.forType) { IProtoTypeSerializer protoTypeSerializer = (IProtoTypeSerializer)protoSerializer1; IProtoTypeSerializer protoTypeSerializer1 = protoTypeSerializer; if (protoTypeSerializer.HasCallbacks(callbackType)) { CodeLabel codeLabel1 = ctx.DefineLabel(); CodeLabel codeLabel2 = ctx.DefineLabel(); ctx.CopyValue(); ctx.TryCast(expectedType); ctx.CopyValue(); ctx.BranchIfTrue(codeLabel1, true); ctx.DiscardValue(); ctx.Branch(codeLabel2, false); ctx.MarkLabel(codeLabel1); protoTypeSerializer1.EmitCallback(ctx, null, callbackType); ctx.Branch(codeLabel, false); ctx.MarkLabel(codeLabel2); } } } ctx.MarkLabel(codeLabel); ctx.DiscardValue(); } }