protected override void EmitInstructionsFor(FieldReference fieldDef) { this.CallDeserializationMethod(fieldDef); TypeReference typeRef = base.TypeOf(fieldDef); if ((!MethodEmitterBase.IsStruct(base.TypeDef) || !UnityEngineTypePredicates.IsUnityEngineValueType(base.TypeDef)) && (MethodEmitterBase.IsStruct(typeRef) || MethodEmitterBase.RequiresAlignment(typeRef))) { this.EmitAlign(); } }
private void EmitInlineDeserializationFor(FieldReference fieldRef, TypeReference typeRef) { base.Ldarg_0(); this.EmitDeserializeInvocationFor(fieldRef); if ((!typeRef.IsPrimitive && !MethodEmitterBase.IsEnum(typeRef)) && (!UnityEngineTypePredicates.IsMatrix4x4(typeRef) && !UnityEngineTypePredicates.IsColor32(typeRef))) { base.Isinst(typeRef); } base.EmitStoreField(fieldRef); }
private void CallDeserializationMethod(FieldReference fieldDef) { if (MethodEmitterBase.IsIUnitySerializable(base.TypeOf(fieldDef))) { base.EmitWithDepthCheck <FieldReference>(new Action <FieldReference>(this.InlinedDeserializeInvocationFor), fieldDef); } else { this.EmitDeserializationFor(fieldDef); } }
private void EmitDeserializeOfIUnitySerializableItem(FieldReference fieldDef, TypeReference elementTypeRef) { if (MethodEmitterBase.IsStruct(elementTypeRef)) { this.EmitDeserializeOfStructItem(fieldDef, elementTypeRef); } else { this.EmitDeserializeOfIUnitySerializableClassItem(fieldDef, elementTypeRef); } }
private void InlinedDeserializeInvocationFor(FieldReference fieldDef) { TypeReference typeRef = base.TypeOf(fieldDef); if (!MethodEmitterBase.IsStruct(typeRef)) { base.EmitWithNullCheckOnField(fieldDef, new Action <FieldReference>(this.ConstructAndStoreSerializableObject)); base.EmitLoadField(fieldDef); this.CallDeserializeMethodFor(fieldDef.Name, typeRef); } else { base.EmitLoadField(fieldDef); this.CallDeserializeMethodFor(fieldDef.Name, typeRef); } }
private void EmitDeserializeOfItem(FieldReference fieldDef, TypeReference elementTypeRef) { if (!MethodEmitterBase.IsIUnitySerializable(elementTypeRef)) { TypeReference type = base.TypeOf(fieldDef); if (CecilUtils.IsGenericList(type)) { base.EmitLoadField(fieldDef); base.LoadStateInstance(this.SerializedStateReaderInterface); this.CallReaderMethod(this.ReadMethodNameFor(elementTypeRef), null); if (!elementTypeRef.IsValueType) { base.Isinst(elementTypeRef); base.Callvirt(this.AddMethodRefFor(type)); } else { base.Callvirt(this.AddMethodRefFor(type)); } } else { base.EmitLoadField(fieldDef); base.EmitLoadItemIndex(); base.LoadStateInstance(this.SerializedStateReaderInterface); this.CallReaderMethod(this.ReadMethodNameFor(elementTypeRef), null); if (!elementTypeRef.IsValueType) { base.Isinst(elementTypeRef); base.Stelem_Ref(); } else { this.Stelem_Any(elementTypeRef); } } } else { this.EmitDeserializeOfIUnitySerializableItem(fieldDef, elementTypeRef); } }
private void EmitDeserializationFor(FieldReference fieldDef) { TypeReference typeReference = base.TypeOf(fieldDef); if (!MethodEmitterBase.CanInlineLoopOn(typeReference)) { if (base.NeedsDepthCheck(typeReference)) { base.EmitWithDepthCheck <FieldReference, TypeReference>(new Action <FieldReference, TypeReference>(this.EmitInlineDeserializationFor), fieldDef, typeReference); } else { this.EmitInlineDeserializationFor(fieldDef, typeReference); } } else { base.EmitWithDepthCheck <FieldReference, TypeReference>(new Action <FieldReference, TypeReference>(this.EmitDeserializationLoopFor), fieldDef, typeReference); } }
private MethodReference DeserializeMethodRefFor(TypeReference typeReference) { MethodReference reference = new MethodReference(this.DeserializeMethodName, base.Import(typeof(void)), MethodEmitterBase.TypeReferenceFor(typeReference)) { HasThis = true }; reference.Parameters.Add(new ParameterDefinition("depth", ParameterAttributes.None, base.Import(typeof(int)))); return(reference); }
private MethodReference ListConstructorRefFor(TypeReference typeReference) => new MethodReference(".ctor", base.Import(typeof(void)), MethodEmitterBase.TypeReferenceFor(typeReference)) { HasThis = true, Parameters = { base.ParamDef("count", typeof(int)) } };
private MethodReference AddMethodRefFor(TypeReference typeReference) { GenericParameter parameterType = ((GenericInstanceType)typeReference).ElementType.GenericParameters[0]; MethodReference method = new MethodReference("Add", base.Import(typeof(void)), MethodEmitterBase.TypeReferenceFor(typeReference)) { Parameters = { new ParameterDefinition("item", ParameterAttributes.None, parameterType) }, HasThis = true }; return(base.Module.ImportReference(method)); }