Пример #1
0
        private static IEnumerable <IScriptField> CreateFields(TypeDefinition type)
        {
            List <IScriptField> fields = new List <IScriptField>();

            foreach (FieldDefinition field in type.Fields)
            {
                if (field.HasConstant)
                {
                    continue;
                }
                if (field.IsStatic)
                {
                    continue;
                }
                if (field.IsInitOnly)
                {
                    continue;
                }
                if (!MonoField.IsSerializableField(field))
                {
                    continue;
                }

                MonoField monoField = new MonoField(field);
                fields.Add(monoField);
            }
            return(fields);
        }
Пример #2
0
        private bool IsTypeValid(TypeReference reference)
        {
            if (m_validTypes.TryGetValue(reference.FullName, out bool isValid))
            {
                return(isValid);
            }

            // set value at the beginning to prevent loop referencing
            m_validTypes[reference.FullName] = true;
            if (MonoType.IsPrime(reference))
            {
                return(true);
            }
            if (reference.Module == null)
            {
                m_validTypes[reference.FullName] = false;
                return(false);
            }

            TypeDefinition definition = reference.Resolve();

            isValid = IsTypeValid(definition.BaseType);
            if (!isValid)
            {
                m_validTypes[reference.FullName] = false;
                return(false);
            }

            foreach (FieldDefinition field in definition.Fields)
            {
                if (!MonoField.IsSerializableField(field))
                {
                    continue;
                }

                isValid = IsTypeValid(field.FieldType);
                if (!isValid)
                {
                    m_validTypes[reference.FullName] = false;
                    return(false);
                }
            }
            return(true);
        }