Resolve() public method

public Resolve ( TypeReference typeReference ) : TypeReference
typeReference Mono.Cecil.TypeReference
return Mono.Cecil.TypeReference
Ejemplo n.º 1
0
        public static bool WillUnitySerialize(FieldDefinition fieldDefinition, TypeResolver typeResolver)
        {
            if (fieldDefinition == null)
            {
                return(false);
            }

            //skip static, const and NotSerialized fields before even checking the type
            if (fieldDefinition.IsStatic || IsConst(fieldDefinition) || fieldDefinition.IsNotSerialized || fieldDefinition.IsInitOnly)
            {
                return(false);
            }

            // Don't try to resolve types that come from Windows assembly,
            // as serialization weaver will fail to resolve that (due to it being in platform specific SDKs)
            if (ShouldNotTryToResolve(fieldDefinition.FieldType))
            {
                return(false);
            }

            //AND, the field must have correct visibility/decoration to be serialized.
            bool hasSerializeFieldAttribute = HasSerializeFieldAttribute(fieldDefinition);

            if (!fieldDefinition.IsPublic && !hasSerializeFieldAttribute &&
                !ShouldHaveHadAllFieldsPublic(fieldDefinition))
            {
                return(false);
            }

            if (fieldDefinition.FullName == "UnityScript.Lang.Array")
            {
                return(false);
            }

            // Resolving types is more complex and slower than checking their names or attributes,
            // thus keep those checks below

            //the type of the field must be serializable in the first place.
            if (!IsFieldTypeSerializable(typeResolver.Resolve(fieldDefinition.FieldType), fieldDefinition))
            {
                return(false);
            }

            if (IsDelegate(typeResolver.Resolve(fieldDefinition.FieldType)))
            {
                return(false);
            }

            return(true);
        }
        public static bool ShouldFieldBePPtrRemapped(FieldDefinition fieldDefinition, TypeResolver typeResolver)
        {
            if (!WillUnitySerialize(fieldDefinition, typeResolver))
            {
                return(false);
            }

            return(CanTypeContainUnityEngineObjectReference(typeResolver.Resolve(fieldDefinition.FieldType)));
        }
        private static bool CanFieldContainUnityEngineObjectReference(TypeReference typeReference, FieldDefinition t, TypeResolver typeResolver)
        {
            if (typeResolver.Resolve(t.FieldType) == typeReference)
            {
                return(false);
            }

            if (!WillUnitySerialize(t, typeResolver))
            {
                return(false);
            }

            if (UnityEngineTypePredicates.IsUnityEngineValueType(typeReference))
            {
                return(false);
            }

            return(true);
        }
        public static bool WillUnitySerialize(FieldDefinition fieldDefinition, TypeResolver typeResolver)
        {
            if (fieldDefinition == null)
            {
                return(false);
            }

            //skip static, const and NotSerialized fields before even checking the type
            if (fieldDefinition.IsStatic || IsConst(fieldDefinition) || fieldDefinition.IsNotSerialized || fieldDefinition.IsInitOnly)
            {
                return(false);
            }

            // The field must have correct visibility/decoration to be serialized.
            if (!fieldDefinition.IsPublic &&
                !ShouldHaveHadAllFieldsPublic(fieldDefinition) &&
                !HasSerializeFieldAttribute(fieldDefinition) &&
                !HasSerializeReferenceAttribute(fieldDefinition))
            {
                return(false);
            }

            // Don't try to resolve types that come from Windows assembly,
            // as serialization weaver will fail to resolve that (due to it being in platform specific SDKs)
            if (ShouldNotTryToResolve(fieldDefinition.FieldType))
            {
                return(false);
            }

            if (IsFixedBuffer(fieldDefinition))
            {
                return(true);
            }

            // Resolving types is more complex and slower than checking their names or attributes,
            // thus keep those checks below
            var typeReference = typeResolver.Resolve(fieldDefinition.FieldType);

            //the type of the field must be serializable in the first place.

            if (typeReference.MetadataType == MetadataType.String)
            {
                return(true);
            }

            if (typeReference.IsValueType)
            {
                return(IsValueTypeSerializable(typeReference));
            }

            if (typeReference is ArrayType || CecilUtils.IsGenericList(typeReference))
            {
                return(IsSupportedCollection(typeReference));
            }

            if (!IsReferenceTypeSerializable(typeReference) && !HasSerializeReferenceAttribute(fieldDefinition))
            {
                return(false);
            }

            if (IsDelegate(typeReference))
            {
                return(false);
            }

            return(true);
        }