ShouldHaveHadSerializableAttribute() public static method

public static ShouldHaveHadSerializableAttribute ( TypeReference type ) : bool
type Mono.Cecil.TypeReference
return bool
        public static bool ShouldImplementIDeserializable(TypeReference typeDeclaration)
        {
            if (typeDeclaration.FullName == "UnityEngine.ExposedReference`1")
            {
                return(true);
            }

            if (IsNonSerialized(typeDeclaration))
            {
                return(false);
            }

            try
            {
                if (UnityEngineTypePredicates.ShouldHaveHadSerializableAttribute(typeDeclaration))
                {
                    return(true);
                }

                var resolvedTypeDeclaration = typeDeclaration.CheckedResolve();
                if (resolvedTypeDeclaration.IsValueType)
                {
                    return(resolvedTypeDeclaration.IsSerializable && !resolvedTypeDeclaration.CustomAttributes.Any(a => a.AttributeType.FullName.Contains("System.Runtime.CompilerServices.CompilerGenerated")));
                }
                else
                {
                    return((resolvedTypeDeclaration.IsSerializable && !resolvedTypeDeclaration.CustomAttributes.Any(a => a.AttributeType.FullName.Contains("System.Runtime.CompilerServices.CompilerGenerated"))) ||
                           resolvedTypeDeclaration.IsSubclassOf(UnityEngineTypePredicates.MonoBehaviour, UnityEngineTypePredicates.ScriptableObject));
                }
            }
            catch (Exception)
            {
                return(false);
            }
        }
Esempio n. 2
0
        public static bool ShouldImplementIDeserializable(TypeReference typeDeclaration)
        {
            if (typeDeclaration.FullName == "UnityEngine.ExposedReference`1")
            {
                return(true);
            }

            if (IsNonSerialized(typeDeclaration))
            {
                return(false);
            }

            var genericInstance = typeDeclaration as GenericInstanceType;

            if (genericInstance != null)
            {
                if (genericInstance.ElementType.FullName == "UnityEngine.ExposedReference`1")
                {
                    return(true);
                }

                return(false);
            }

            try
            {
                return(UnityEngineTypePredicates.IsMonoBehaviour(typeDeclaration) ||
                       UnityEngineTypePredicates.IsScriptableObject(typeDeclaration) ||
                       (typeDeclaration.CheckedResolve().IsSerializable&& !typeDeclaration.CheckedResolve().IsAbstract&& !typeDeclaration.CheckedResolve().CustomAttributes.Any(a => a.AttributeType.FullName.Contains("System.Runtime.CompilerServices.CompilerGenerated"))) ||
                       UnityEngineTypePredicates.ShouldHaveHadSerializableAttribute(typeDeclaration));
            }
            catch (Exception)
            {
                return(false);
            }
        }