public static string DisplayName([NotNull] this ITypeBase type)
        {
            if (!(type is IEntityType entityType) ||
                !entityType.HasDefiningNavigation())
            {
                return(type.DisplayNameDefault());
            }

            var builder = new StringBuilder();
            var path    = new Stack <string>();
            var root    = entityType;

            while (true)
            {
                var definingNavigationName = root.DefiningNavigationName;
                if (definingNavigationName == null)
                {
                    break;
                }

                root = root.DefiningEntityType;
                path.Push("#");
                path.Push(definingNavigationName);
                path.Push(".");
                path.Push(root.DisplayNameDefault());
            }

            if (root != entityType)
            {
                builder.AppendJoin(path, "");
            }

            builder.Append(type.DisplayNameDefault());
            return(builder.ToString());
        }
示例#2
0
        private static void SetAuditableEntities(this ModelBuilder modelBuilder, ITypeBase entityType)
        {
            if (entityType.ClrType.GetCustomAttributes(typeof(AuditableAttribute), true).Any())
            {
                modelBuilder
                .Entity(entityType.Name)
                .Property <string>("CreatedBy")
                .IsRequired()
                .HasColumnType("nvarchar(50)");

                modelBuilder
                .Entity(entityType.Name)
                .Property <string>("LastModifiedBy")
                .IsRequired()
                .HasColumnType("nvarchar(50)");

                modelBuilder
                .Entity(entityType.Name)
                .Property <DateTime>("Created");

                modelBuilder
                .Entity(entityType.Name)
                .Property <DateTime?>("LastModified");
            }
        }
        public static string DisplayName([NotNull] this ITypeBase type)
        {
            if (type.ClrType == null)
            {
                return(type.Name);
            }

            if (!type.HasSharedClrType)
            {
                return(type.ClrType.ShortDisplayName());
            }

            var shortName = type.Name;
            var hashIndex = shortName.IndexOf("#", StringComparison.Ordinal);

            if (hashIndex == -1)
            {
                return(type.Name + " (" + type.ClrType.ShortDisplayName() + ")");
            }

            var plusIndex = shortName.LastIndexOf("+", StringComparison.Ordinal);

            if (plusIndex != -1)
            {
                shortName = shortName[(plusIndex + 1)..];
示例#4
0
        public static string GetEntityTypeString(ITypeBase typeBase, string appending)
        {
            StringBuilder sb = new StringBuilder();

            sb.AppendFormat("{0}.GetInstance(),", GetNameOfITypeBase(typeBase));

            return(sb.ToString());
        }
        /// <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 static PropertyInfo EFIndexerProperty([NotNull] this ITypeBase type)
        {
            var runtimeProperties = type is TypeBase typeBase
                ? typeBase.GetRuntimeProperties().Values // better perf if we've already computed them once
                : type.ClrType.GetRuntimeProperties();

            // find the indexer with single argument of type string which returns an object
            return(runtimeProperties.FirstOrDefault(p => p.IsEFIndexerProperty()));
        }
示例#6
0
 public SingleMouseXml(string name, string id, ITypeBase type, string[] videos, string mClass, int age)
 {
     Version = 1.0;
     Name    = name;
     Id      = id;
     Type    = type.Name;
     Videos  = videos;
     Class   = mClass;
     Age     = age;
 }
示例#7
0
 private static void SetSoftDeleteEntities(this ModelBuilder modelBuilder, ITypeBase entityType)
 {
     if (entityType.ClrType.GetCustomAttributes(typeof(SoftDeleteAttribute), true).Any())
     {
         modelBuilder
         .Entity(entityType.Name)
         .Property <bool>("IsActive")
         .HasDefaultValue(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 static PropertyInfo GetIndexerProperty([NotNull] this ITypeBase type)
        {
            var indexerProperty = type.FindIndexerProperty();

            if (indexerProperty == null)
            {
                throw new InvalidOperationException(CoreStrings.NoIndexer(type.DisplayName()));
            }

            return(indexerProperty);
        }
        /// <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 static PropertyInfo EFIndexerProperty([NotNull] this ITypeBase type)
        {
            var runtimeProperties = type is TypeBase typeBase
                ? typeBase.GetRuntimeProperties().Values // better perf if we've already computed them once
                : type.ClrType.GetRuntimeProperties();

            // find the indexer with single argument of type string which returns an object
            return((from p in runtimeProperties
                    where p.PropertyType == typeof(object)
                    let q = p.GetIndexParameters()
                            where q.Length == 1 && q[0].ParameterType == typeof(string)
                            select p).FirstOrDefault());
        }
示例#10
0
        public static string ShortName([NotNull] this ITypeBase type)
        {
            if (type.ClrType != null)
            {
                return(type.ClrType.ShortDisplayName());
            }

            var plusIndex = type.Name.LastIndexOf("+", StringComparison.Ordinal);
            var dotIndex  = type.Name.LastIndexOf(".", StringComparison.Ordinal);

            return(plusIndex == -1
                ? dotIndex == -1
                    ? type.Name
                    : type.Name.Substring(dotIndex + 1, type.Name.Length - dotIndex - 1)
                : type.Name.Substring(plusIndex + 1, type.Name.Length - plusIndex - 1));
        }
示例#11
0
 public static string GetOwnedName([NotNull] this ITypeBase type, [NotNull] string simpleName, [NotNull] string ownershipNavigation)
 => type.Name + "." + ownershipNavigation + "#" + simpleName;
示例#12
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 static TypeBase AsTypeBase([NotNull] this ITypeBase entityType, [NotNull][CallerMemberName] string methodName = "")
 => MetadataExtensions.AsConcreteMetadataType <ITypeBase, TypeBase>(entityType, methodName);
示例#13
0
 public static void ApplyShadowProperties(this ModelBuilder modelBuilder, ITypeBase entityType)
 {
     modelBuilder.SetAuditableEntities(entityType);
     modelBuilder.SetSoftDeleteEntities(entityType);
 }
 public static bool IsAbstract([NotNull] this ITypeBase type)
 => type.ClrType?.GetTypeInfo().IsAbstract ?? false;
 private static string DisplayNameDefault(this ITypeBase type)
 => type.ClrType != null
         ? type.ClrType.ShortDisplayName()
         : type.Name;
 public ServiceFactory(ITypeBase typeBase,
                       IServiceProvider serviceProvider)
 {
     _typeBase        = typeBase;
     _serviceProvider = serviceProvider;
 }
 /// <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 static string DisplayName([NotNull] this ITypeBase type)
 => type.ClrType != null
         ? type.ClrType.ShortDisplayName()
         : type.Name;
示例#18
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 static PropertyInfo FindIndexerPropertyInfo([NotNull] this ITypeBase type)
 => (type as TypeBase).FindIndexerPropertyInfo();
示例#19
0
 public static bool IsAbstract([NotNull] this ITypeBase type)
 => type.ClrType.IsAbstract;
示例#20
0
 public static string GetNameOfIEntityType(ITypeBase entityType)
 {
     return($"{GetNakedNameOfIEntityType(entityType)}EntityType");
 }
示例#21
0
 /// <summary>
 ///     <para>
 ///         Gets the <see cref="PropertyAccessMode" /> being used for navigations of this type.
 ///         Null indicates that the default property access mode is being used.
 ///     </para>
 ///     <para>
 ///         Note that individual navigations can override this access mode. The value returned here will
 ///         be used for any navigation for which no override has been specified.
 ///     </para>
 /// </summary>
 /// <param name="typeBase"> The type for which to get the access mode. </param>
 /// <returns> The access mode being used, or null if the default access mode is being used. </returns>
 public static PropertyAccessMode?GetNavigationAccessMode(
     [NotNull] this ITypeBase typeBase)
 => (PropertyAccessMode?)Check.NotNull(typeBase, nameof(typeBase))[CoreAnnotationNames.NavigationAccessModeAnnotation]
 ?? typeBase.GetPropertyAccessMode()
 ?? typeBase.Model.GetPropertyAccessMode();
示例#22
0
 public static string FullName([NotNull] this ITypeBase type) => type.Name;
示例#23
0
 public static string DisplayName([NotNull] this ITypeBase type)
 => type.FullName();
示例#24
0
 public static bool HasClrType([NotNull] this ITypeBase type)
 => type.ClrType != null;
示例#25
0
 public static string DisplayName([NotNull] this ITypeBase type)
 => type.FullName() + (type is IEntityType entityType && entityType.HasSharedClrType
示例#26
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 static IReadOnlyDictionary <string, PropertyInfo> GetRuntimeProperties([NotNull] this ITypeBase type)
 => (type as TypeBase).GetRuntimeProperties();
示例#27
0
 public static string GetNameOfITypeBase(ITypeBase entityType)
 {
     return($"{entityType.Name.Split(".").Last().Split("<").First()}TypeBase");
 }
示例#28
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 static IReadOnlyDictionary <string, FieldInfo> GetRuntimeFields([NotNull] this ITypeBase type)
 => (type as TypeBase).GetRuntimeFields();
示例#29
0
 public static string FullName(this ITypeBase type) => type.Name;
示例#30
0
 public static string GetNakedNameOfIEntityType(ITypeBase entityType)
 {
     return(entityType.Name.Split(".").Last().Split("<").First());
 }