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()); }
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)..];
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())); }
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; }
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()); }
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)); }
public static string GetOwnedName([NotNull] this ITypeBase type, [NotNull] string simpleName, [NotNull] string ownershipNavigation) => type.Name + "." + ownershipNavigation + "#" + simpleName;
/// <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);
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;
/// <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();
public static bool IsAbstract([NotNull] this ITypeBase type) => type.ClrType.IsAbstract;
public static string GetNameOfIEntityType(ITypeBase entityType) { return($"{GetNakedNameOfIEntityType(entityType)}EntityType"); }
/// <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();
public static string FullName([NotNull] this ITypeBase type) => type.Name;
public static string DisplayName([NotNull] this ITypeBase type) => type.FullName();
public static bool HasClrType([NotNull] this ITypeBase type) => type.ClrType != null;
public static string DisplayName([NotNull] this ITypeBase type) => type.FullName() + (type is IEntityType entityType && entityType.HasSharedClrType
/// <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();
public static string GetNameOfITypeBase(ITypeBase entityType) { return($"{entityType.Name.Split(".").Last().Split("<").First()}TypeBase"); }
/// <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();
public static string FullName(this ITypeBase type) => type.Name;
public static string GetNakedNameOfIEntityType(ITypeBase entityType) { return(entityType.Name.Split(".").Last().Split("<").First()); }