Esempio n. 1
0
        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();
            }
        }
Esempio n. 2
0
 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);
 }
Esempio n. 3
0
 private void CallDeserializationMethod(FieldReference fieldDef)
 {
     if (MethodEmitterBase.IsIUnitySerializable(base.TypeOf(fieldDef)))
     {
         base.EmitWithDepthCheck <FieldReference>(new Action <FieldReference>(this.InlinedDeserializeInvocationFor), fieldDef);
     }
     else
     {
         this.EmitDeserializationFor(fieldDef);
     }
 }
Esempio n. 4
0
 private void EmitDeserializeOfIUnitySerializableItem(FieldReference fieldDef, TypeReference elementTypeRef)
 {
     if (MethodEmitterBase.IsStruct(elementTypeRef))
     {
         this.EmitDeserializeOfStructItem(fieldDef, elementTypeRef);
     }
     else
     {
         this.EmitDeserializeOfIUnitySerializableClassItem(fieldDef, elementTypeRef);
     }
 }
Esempio n. 5
0
        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);
            }
        }
Esempio n. 6
0
 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);
     }
 }
Esempio n. 7
0
        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);
            }
        }
Esempio n. 8
0
        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);
        }
Esempio n. 9
0
 private MethodReference ListConstructorRefFor(TypeReference typeReference) =>
 new MethodReference(".ctor", base.Import(typeof(void)), MethodEmitterBase.TypeReferenceFor(typeReference))
 {
     HasThis    = true,
     Parameters = { base.ParamDef("count", typeof(int)) }
 };
Esempio n. 10
0
        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));
        }