Exemple #1
0
        /// <summary>
        ///    Returns a collection of standard values for the data type this type converter is designed for when provided
        ///    with a format context.
        /// </summary>
        /// <param name="context">
        ///    An <see cref="T:System.ComponentModel.ITypeDescriptorContext" /> that provides a format context
        ///    that can be used to extract additional information about the environment from which this converter is invoked. This
        ///    parameter or properties of this parameter can be null.
        /// </param>
        /// <returns>
        ///    A <see cref="T:System.ComponentModel.TypeConverter.StandardValuesCollection" /> that holds a standard set of
        ///    valid values, or null if the data type does not support a standard set of values.
        /// </returns>
        public override StandardValuesCollection GetStandardValues(ITypeDescriptorContext context)
        {
            base.GetStandardValues(context);
            List <string> values = new List <string>();

            Store store = GetStore(context.Instance);

            if (store != null)
            {
                ModelRoot modelRoot = store.ModelRoot();

                // Value set changes at EFCore3
                if (modelRoot.EntityFrameworkVersion == EFVersion.EF6)
                {
                    return(new StandardValuesCollection(values));
                }

                if (modelRoot.GetEntityFrameworkPackageVersionNum() < 3)
                {
                    values.AddRange(new[]
                    {
                        "Field"
                        , "FieldDuringConstruction"
                        , "Property"
                    });
                }
                else
                {
                    values.AddRange(new[]
                    {
                        "Field"
                        , "FieldDuringConstruction"
                        , "PreferField"
                        , "PreferFieldDuringConstruction"
                        , "PreferProperty"
                        , "Property"
                    });
                }
            }

            return(new StandardValuesCollection(values));
        }
Exemple #2
0
        /// <summary>
        /// Called by TypeDescriptors to determine what should be shown in a property editor. Removing a property hides
        /// it from the property editor in Visual Studio, nothing more.
        /// </summary>
        /// <param name="propertyDescriptors"></param>
        /// <param name="element"></param>
        public static void RemoveHiddenProperties(PropertyDescriptorCollection propertyDescriptors, ModelRoot element)
        {
            ModelRoot modelRoot = element;

            for (int index = 0; index < propertyDescriptors.Count; index++)
            {
                bool shouldRemove = false;
                switch (propertyDescriptors[index].Name)
                {
                case "InstallNugetPackages":
                    shouldRemove = !ModelRoot.CanLoadNugetPackages;
                    break;

                case "DatabaseInitializerType":
                    shouldRemove = modelRoot.EntityFrameworkVersion == EFVersion.EFCore;
                    break;

                case "AutomaticMigrationsEnabled":
                    shouldRemove = modelRoot.EntityFrameworkVersion == EFVersion.EFCore;
                    break;

                case "ProxyGenerationEnabled":
                    shouldRemove = modelRoot.EntityFrameworkVersion == EFVersion.EFCore;
                    break;

                case "DatabaseType":
                    shouldRemove = modelRoot.EntityFrameworkVersion == EFVersion.EFCore;
                    break;

                case "InheritanceStrategy":
                    shouldRemove = modelRoot.EntityFrameworkVersion == EFVersion.EFCore;
                    break;

                case "LazyLoadingEnabled":
                    shouldRemove = modelRoot.EntityFrameworkVersion == EFVersion.EFCore && modelRoot.GetEntityFrameworkPackageVersionNum() < 2.1;
                    break;
                }

                if (shouldRemove)
                {
                    propertyDescriptors.Remove(propertyDescriptors[index--]);
                }
            }
        }