/// <summary>
        ///     This API supports the Entity Framework Core infrastructure and is not intended to be used
        ///     directly from your code. This API may change or be removed in future releases.
        /// </summary>
        public virtual bool HasField([CanBeNull] string fieldName, ConfigurationSource configurationSource)
        {
            if (Metadata.FieldInfo?.Name == fieldName)
            {
                Metadata.SetField(fieldName, configurationSource);
                return(true);
            }

            if (!configurationSource.Overrides(Metadata.GetFieldInfoConfigurationSource()))
            {
                return(false);
            }

            if (fieldName != null)
            {
                var fieldInfo = PropertyBase.GetFieldInfo(
                    fieldName, Metadata.DeclaringType.ClrType, Metadata.Name,
                    shouldThrow: configurationSource == ConfigurationSource.Explicit);
                Metadata.SetFieldInfo(fieldInfo, configurationSource);
                return(true);
            }

            Metadata.SetField(fieldName, configurationSource);
            return(true);
        }
        /// <summary>
        ///     This is an internal API that supports the Entity Framework Core infrastructure and not subject to
        ///     the same compatibility standards as public APIs. It may be changed or removed without notice in
        ///     any release. You should only use it directly in your code with extreme caution and knowing that
        ///     doing so can result in application failures when updating to a new Entity Framework Core release.
        /// </summary>
        public virtual bool CanSetField([CanBeNull] string fieldName, ConfigurationSource?configurationSource)
        {
            if (fieldName != null &&
                configurationSource.Overrides(Metadata.GetFieldInfoConfigurationSource()))
            {
                var fieldInfo = PropertyBase.GetFieldInfo(
                    fieldName, Metadata.DeclaringType, Metadata.Name,
                    shouldThrow: false);
                return(fieldInfo != null &&
                       PropertyBase.IsCompatible(
                           fieldInfo, Metadata.ClrType, Metadata.DeclaringType.ClrType, Metadata.Name,
                           shouldThrow: false));
            }

            return(Metadata.FieldInfo?.GetSimpleMemberName() == fieldName);
        }
Пример #3
0
        /// <summary>
        ///     This is an internal API that supports the Entity Framework Core infrastructure and not subject to
        ///     the same compatibility standards as public APIs. It may be changed or removed without notice in
        ///     any release. You should only use it directly in your code with extreme caution and knowing that
        ///     doing so can result in application failures when updating to a new Entity Framework Core release.
        /// </summary>
        public virtual bool CanSetField(string?fieldName, ConfigurationSource?configurationSource)
        {
            if (configurationSource.Overrides(Metadata.GetFieldInfoConfigurationSource()))
            {
                if (fieldName == null)
                {
                    return(true);
                }

                var fieldInfo = PropertyBase.GetFieldInfo(
                    fieldName, Metadata.DeclaringType, Metadata.Name,
                    shouldThrow: configurationSource == ConfigurationSource.Explicit);

                return(fieldInfo != null &&
                       PropertyBase.IsCompatible(
                           fieldInfo, Metadata.ClrType, Metadata.DeclaringType.ClrType, Metadata.Name,
                           shouldThrow: configurationSource == ConfigurationSource.Explicit));
            }

            return(Metadata.FieldInfo?.GetSimpleMemberName() == fieldName);
        }