public override object Next(StateEntry entry, IProperty property) { Check.NotNull(property, "property"); Contract.Assert(property.IsForeignKey()); var entityType = property.EntityType; var stateManager = entry.Configuration.StateManager; foreach (var foreignKey in entityType.ForeignKeys) { for (var propertyIndex = 0; propertyIndex < foreignKey.Properties.Count; propertyIndex++) { if (property == foreignKey.Properties[propertyIndex]) { foreach (var navigation in entityType.Navigations .Concat(foreignKey.ReferencedEntityType.Navigations) .Where(n => n.ForeignKey == foreignKey) .Distinct()) { var principal = TryFindPrincipal(stateManager, navigation, entry.Entity); if (principal != null) { var principalEntry = stateManager.GetOrCreateEntry(principal); return principalEntry[foreignKey.ReferencedProperties[propertyIndex]]; } } } } } return null; }
public static int GetIcon(IProperty property) { if (property.IsIndexer) return IndexerIndex + GetModifierOffset(property.Modifiers); else return PropertyIndex + GetModifierOffset(property.Modifiers); }
protected static XElement GetOrUpdateProperty(XElement rootElement, IProperty property) { var propElem = rootElement.GetOrCreateElement("property", x => x.GetAttributeValue("name") == property.Name); propElem.SetAttributeValue("name", property.Name); // todo: escape attribute values? var propertyValue = property.Value; if (propertyValue == null) { } else if (propertyValue is IXmlExportable) { var type = propertyValue.GetType(); var typeString = type.FullName + ", " + type.Assembly.GetName().Name; var exportable = (IXmlExportable)propertyValue; propElem.SetAttributeValue("type", typeString); exportable.Export(propElem); } else { var value = propertyValue != null ? propertyValue.ToString() : null; propElem.SetAttributeValue("value", value); } return propElem; }
public AddDependencyPage(Action<string> updateParameterType, ISolution solution) { _typeValidator = new CSharpTypeValidator(); _solution = solution; _continueEnabled = new Property<bool>("ContinueEnabled", true); var shellLocks = Shell.Instance.GetComponent<IShellLocks>(); _typeEditBox = new CompletionPickerEdit(shellLocks, Shell.Instance.Components.Tooltips()) { Width = 300, }; var lifetime = this.DefineWinFormsLifetime(); _typeEditBox.Settings.Value = TypeChooser.CreateSettings( lifetime, solution, LibrariesFlag.SolutionAndLibraries, CSharpLanguage.Instance, shellLocks); _typeEditBox.Text.Change.Advise_HasNew( lifetime, args => { updateParameterType(args.New); UpdateUI(); }); Controls.Add(_typeEditBox); }
IProperty WrapProperty(IProperty result) { if (result == null) return null; if (!(result is AlienOwnedProperty)) return new AlienOwnedProperty(this, _realMember, result); return result; }
public virtual RelationalTypeMapping GetTypeMapping(IProperty property) => GetTypeMapping( property.Relational().ColumnType, property.Relational().Column, property.ClrType.UnwrapNullableType(), property.IsKey() || property.IsForeignKey(), property.IsConcurrencyToken);
private void ForeignKeyPropertyChangedAction(InternalEntityEntry entry, IProperty property, object oldValue, object newValue) { foreach (var foreignKey in entry.EntityType.GetForeignKeys().Where(p => p.Properties.Contains(property)).Distinct()) { var navigations = _model.GetNavigations(foreignKey).ToList(); var oldPrincipalEntry = entry.StateManager.GetPrincipal(entry.RelationshipsSnapshot, foreignKey); if (oldPrincipalEntry != null) { Unfixup(navigations, oldPrincipalEntry, entry); } var principalEntry = entry.StateManager.GetPrincipal(entry, foreignKey); if (principalEntry != null) { if (foreignKey.IsUnique) { var oldDependents = entry.StateManager.GetDependents(principalEntry, foreignKey).Where(e => e != entry).ToList(); // TODO: Decide how to handle case where multiple values found (negative case) // Issue #739 if (oldDependents.Count > 0) { StealReference(foreignKey, oldDependents[0]); } } DoFixup(navigations, principalEntry, new[] { entry }); } } }
public virtual FieldInfo TryMatchFieldName( IProperty property, PropertyInfo propertyInfo, Dictionary<string, FieldInfo> dclaredFields) { Check.NotNull(property, nameof(property)); Check.NotNull(propertyInfo, nameof(propertyInfo)); Check.NotNull(dclaredFields, nameof(dclaredFields)); var propertyName = propertyInfo.Name; var propertyType = propertyInfo.PropertyType.GetTypeInfo(); var camelized = char.ToLowerInvariant(propertyName[0]) + propertyName.Substring(1); FieldInfo fieldInfo; return (dclaredFields.TryGetValue(camelized, out fieldInfo) && fieldInfo.FieldType.GetTypeInfo().IsAssignableFrom(propertyType)) || (dclaredFields.TryGetValue("_" + camelized, out fieldInfo) && fieldInfo.FieldType.GetTypeInfo().IsAssignableFrom(propertyType)) || (dclaredFields.TryGetValue("_" + propertyName, out fieldInfo) && fieldInfo.FieldType.GetTypeInfo().IsAssignableFrom(propertyType)) || (dclaredFields.TryGetValue("m_" + camelized, out fieldInfo) && fieldInfo.FieldType.GetTypeInfo().IsAssignableFrom(propertyType)) || (dclaredFields.TryGetValue("m_" + propertyName, out fieldInfo) && fieldInfo.FieldType.GetTypeInfo().IsAssignableFrom(propertyType)) ? fieldInfo : null; }
public override object Next(StateEntry entry, IProperty property) { Check.NotNull(entry, "entry"); Check.NotNull(property, "property"); return Convert.ChangeType(Interlocked.Increment(ref _current), property.PropertyType); }
/// <summary> /// Selects the appropriate value generator for a given property. /// </summary> /// <param name="property"> The property to get the value generator for. </param> /// <param name="entityType"> /// The entity type that the value generator will be used for. When called on inherited properties on derived entity types, /// this entity type may be different from the declared entity type on <paramref name="property" /> /// </param> /// <returns> The value generator to be used. </returns> public virtual ValueGenerator Select(IProperty property, IEntityType entityType) { Check.NotNull(property, nameof(property)); Check.NotNull(entityType, nameof(entityType)); return Cache.GetOrAdd(property, entityType, Create); }
public static IEnumerable<object> GetValues(IProperty property, bool isExploded = false) { if (isSimpleType(property.Type)) { object result = property.Value; return new object[] { result }; } else if (isListType(property.Type)) { var result = (IEnumerable)property.Value; return result.Cast<object>().ToArray(); } else { object instance = property.Value; var subProperties = PropertyLookup.CreatePropertyLookup(instance); List<object> values = new List<object>(); foreach (IProperty subProperty in subProperties.GetProperties()) { object value = subProperty.Value; if (isExploded) { var pair = new Tuple<string, object>(subProperty.Name, value); values.Add(pair); } else { values.Add(subProperty.Name); values.Add(value); } } return values.ToArray(); } }
public override string PropertyDefinition(IProperty property) { bool hasTick = property.PropertyType.IsRef && !property.PropertyType.IsGenericTypeArg; StringBuilder sb = new StringBuilder("public:").AppendLine(); sb.Append("property ").Append(TypeName(property.PropertyType)).Append(' '); if (hasTick) sb.Append('^'); sb.Append(property.DisplayName).AppendLine(" {"); if (property.HasGetter) { sb.Append(Tabulator).Append(TypeName(property.PropertyType)).Append(' '); if (hasTick) sb.Append('^'); sb.AppendLine("get();"); } if (property.HasSetter) { sb.Append(Tabulator); if (property.SetterAccess.HasValue && property.SetterAccess.Value == AccessModifier.Protected) sb.Append("protected: "); sb.Append("void set(") .Append(TypeName(property.PropertyType)) .Append(' '); if (hasTick) sb.Append('^'); sb.AppendLine("value);"); } sb.Append("}"); return sb.ToString(); }
public ParameterDescriptorImpl(IProperty property) { if (property == null) throw new ArgumentNullException("property"); this.property = property; SetEnumerable(); }
public override object Next(StateEntry entry, IProperty property) { Check.NotNull(entry, "entry"); Check.NotNull(property, "property"); return Guid.NewGuid(); }
public PropertyResult(IProperty source) { if (source == null) return; _alias = source.Alias; _value = source.Value; }
public override IValueGeneratorFactory Select(IProperty property) { Check.NotNull(property, "property"); switch (property.ValueGenerationOnAdd) { case ValueGenerationOnAdd.Client: if (property.PropertyType.IsInteger() && property.PropertyType != typeof(byte)) { return _tempFactory; } if (property.PropertyType == typeof(Guid)) { return _sequentialGuidFactory; } goto default; case ValueGenerationOnAdd.Server: if (property.PropertyType.IsInteger()) { return _sequenceFactory; } goto default; default: return base.Select(property); } }
public MemberNode(IProperty property) { InitMemberNode(property); sortOrder = 12; Text = AppendReturnType(GetAmbience().Convert(property), property.ReturnType); SelectedImageIndex = ImageIndex = ClassBrowserIconService.GetIcon(property).ImageIndex; }
public virtual void ForeignKeyPropertyChanged(StateEntry entry, IProperty property, object oldValue, object newValue) { Check.NotNull(entry, "entry"); Check.NotNull(property, "property"); PerformFixup(() => ForeignKeyPropertyChangedAction(entry, property, oldValue, newValue)); }
public static bool HasPublicModifier(IProperty property) { try { if (property.Getter == null) { return false; } var declaration = property.GetDeclarations().FirstOrDefault(); if (declaration == null) { return false; } var memberDeclaration = declaration as ICSharpTypeMemberDeclaration; if (memberDeclaration == null) { return false; } return memberDeclaration.ModifiersList.Modifiers.Any(m => m.GetTokenType() == CSharpTokenType.PUBLIC_KEYWORD); } catch (Exception exn) { Debug.WriteLine(exn); return false; } }
public virtual ValueGenerator GetOrAdd(IProperty property, Func<IProperty, ValueGenerator> factory) { Check.NotNull(property, nameof(property)); Check.NotNull(factory, nameof(factory)); return _cache.GetOrAdd(property, factory); }
public virtual async Task<object> NextAsync(StateEntry stateEntry, IProperty property, CancellationToken cancellationToken = default(CancellationToken)) { Check.NotNull(stateEntry, "stateEntry"); Check.NotNull(property, "property"); var newValue = GetNextValue(); // If the chosen value is outside of the current block then we need a new block. // It is possible that other threads will use all of the new block before this thread // gets a chance to use the new new value, so use a while here to do it all again. while (newValue.Current >= newValue.Max) { // Once inside the lock check to see if another thread already got a new block, in which // case just get a value out of the new block instead of requesting one. using (await _lock.LockAsync(cancellationToken)) { if (newValue.Max == _currentValue.Max) { var commandInfo = PrepareCommand(stateEntry.Configuration); var newCurrent = (long)await _executor.ExecuteScalarAsync(commandInfo.Item1.DbConnection, commandInfo.Item1.DbTransaction, commandInfo.Item2, cancellationToken).ConfigureAwait(false); newValue = new SequenceValue(newCurrent, newCurrent + _blockSize); _currentValue = newValue; } else { newValue = GetNextValue(); } } } return Convert.ChangeType(newValue.Current, property.PropertyType); }
private static IValueGeneratorPool CreatePool(IProperty property, IValueGeneratorFactory factory) { var poolSize = factory.GetPoolSize(property); return poolSize == 1 ? (IValueGeneratorPool)new SingleValueGeneratorPool(factory, property) : new ValueGeneratorPool(factory, property, poolSize); }
// Methods public ARPPage(IOptionsDialog optionsDialog) : base("ARP") { this.connectionString = new Property<string>("ConectionString"); this.databaseEnabled = new Property<bool>("Enabled"); var solution = optionsDialog.DataContext.GetData<ISolution>(DataConstants.SOLUTION); if (solution != null) { this.manager = DatabaseManager.GetInstance(solution); base.Bind(new PropertyBinding<string, string>(ManualProperty.Create<string>("ConectionString", this.manager.ConnectionString, delegate(string value) { this.manager.ConnectionString = value; }), this.connectionString, DataFlowDirection.FromSource)); base.Bind(new PropertyBinding<bool, bool>(ManualProperty.Create<bool>("Enabled", this.manager.Enabled, delegate(bool value) { this.manager.Enabled = value; }), this.databaseEnabled, DataFlowDirection.FromSource)); // TODO bind properties using (new LayoutSuspender(this)) { this.InitSettings(); return; } } base.Controls.Add(JetBrains.UI.Options.Helpers.Controls.CreateNoSolutionCueBanner()); }
private static SDProperty GetMinimalParsedProperty(IProperty property) { return new SDProperty(property.GetIdentifier()) { Name = property.Name, Accessibility = property.Accessibility.ToString().ToLower() }; }
private string GetColumnType(IProperty propertyInfo) { var type = propertyInfo.PropertyType; if (!_columnTypes.ContainsKey(type)) throw new Exception(string.Format("The key {0} was not found!", type.Name)); return _columnTypes[type]; }
/// <summary> /// Gets the existing value generator from the cache, or creates a new one if one is not present in /// the cache. /// </summary> /// <param name="property"> The property to get the value generator for. </param> /// <param name="entityType"> /// The entity type that the value generator will be used for. When called on inherited properties on derived entity types, /// this entity type may be different from the declared entity type on <paramref name="property" /> /// </param> /// <param name="factory"> Factory to create a new value generator if one is not present in the cache. </param> /// <returns> The existing or newly created value generator. </returns> public virtual ValueGenerator GetOrAdd( IProperty property, IEntityType entityType, Func<IProperty, IEntityType, ValueGenerator> factory) { Check.NotNull(property, nameof(property)); Check.NotNull(factory, nameof(factory)); return _cache.GetOrAdd(new CacheKey(property, entityType, factory), ck => ck.Factory(ck.Property, ck.EntityType)); }
/// <summary> /// Creates a new instance of a ColumnExpression. /// </summary> /// <param name="name"> The column name. </param> /// <param name="property"> The corresponding property. </param> /// <param name="tableExpression"> The target table expression. </param> public ColumnExpression( [NotNull] string name, [NotNull] IProperty property, [NotNull] TableExpressionBase tableExpression) : this(name, Check.NotNull(property, nameof(property)).ClrType, tableExpression) { _property = property; }
public override IEnumerable<IAnnotation> For(IProperty property) { if (property.ValueGenerated == ValueGenerated.OnAdd && property.ClrType.UnwrapNullableType().IsInteger()) { yield return new Annotation(SqliteAnnotationNames.Prefix + SqliteAnnotationNames.Autoincrement, true); } }
private string GetColumn(IProperty propertyInfo) { return propertyInfo.Name == "Id" ? string.Format("[{0}] [{1}] primary key", propertyInfo.Name, GetColumnType(propertyInfo)) : propertyInfo.Name.EndsWith("Id") ? string.Format("[{0}] [{1}] foreing key", propertyInfo.Name, GetColumnType(propertyInfo)) : string.Format("[{0}] [{1}]", propertyInfo.Name, GetColumnType(propertyInfo)); }
public override ValueGenerator Create(IProperty property) { Check.NotNull(property, nameof(property)); return property.ClrType.IsInteger() ? _inMemoryFactory.Create(property) : base.Create(property); }
/// <summary> /// Gets a value indicating whether or not the property can persist Unicode characters. /// </summary> /// <param name="property"> The property to get the Unicode setting for. </param> /// <returns> The Unicode setting, or <see langword="null"/> if none is defined. </returns> public static bool?IsUnicode([NotNull] this IProperty property) { Check.NotNull(property, nameof(property)); return((bool?)property[CoreAnnotationNames.Unicode]); }
/// <summary> /// Gets the factory that has been set to generate values for this property, if any. /// </summary> /// <param name="property"> The property to get the value generator factory for. </param> /// <returns> The factory, or <see langword="null"/> if no factory has been set. </returns> public static Func <IProperty, IEntityType, ValueGenerator> GetValueGeneratorFactory([NotNull] this IProperty property) => (Func <IProperty, IEntityType, ValueGenerator>) Check.NotNull(property, nameof(property))[CoreAnnotationNames.ValueGeneratorFactory];
/// <summary> /// <para> /// Gets a value indicating whether or not this property can be modified before the entity is /// saved to the database. /// </para> /// <para> /// If <see cref="PropertySaveBehavior.Throw" />, then an exception /// will be thrown if a value is assigned to this property when it is in /// the <see cref="EntityState.Added" /> state. /// </para> /// <para> /// If <see cref="PropertySaveBehavior.Ignore" />, then any value /// set will be ignored when it is in the <see cref="EntityState.Added" /> state. /// </para> /// </summary> /// <param name="property"> The property. </param> public static PropertySaveBehavior GetBeforeSaveBehavior([NotNull] this IProperty property) => (PropertySaveBehavior?)Check.NotNull(property, nameof(property))[CoreAnnotationNames.BeforeSaveBehavior] ?? (property.ValueGenerated == ValueGenerated.OnAddOrUpdate ? PropertySaveBehavior.Ignore : PropertySaveBehavior.Save);
protected override string GetColumnType(IProperty property) => property.MySql().ColumnType;
/// <summary> /// Gets the custom <see cref="ValueConverter" /> set for this property. /// </summary> /// <param name="property"> The property. </param> /// <returns> The converter, or <see langword="null"/> if none has been set. </returns> public static ValueConverter GetValueConverter([NotNull] this IProperty property) => (ValueConverter)Check.NotNull(property, nameof(property))[CoreAnnotationNames.ValueConverter];
/// <summary> /// Gets a value indicating whether this property is used as the primary key or alternate key /// (or part of a composite primary or alternate key). /// </summary> /// <param name="property"> The property to check. </param> /// <returns> <see langword="true"/> if the property is used as a key, otherwise <see langword="false"/>. </returns> public static bool IsKey([NotNull] this IProperty property) => Check.NotNull((Property)property, nameof(property)).Keys != null;
/// <summary> /// Gets the primary key that uses this property (including a composite primary key in which this property /// is included). /// </summary> /// <param name="property"> The property to get primary key for. </param> /// <returns> The primary that use this property, or <see langword="null"/> if it is not part of the primary key. </returns> public static IKey FindContainingPrimaryKey([NotNull] this IProperty property) => Check.NotNull((Property)property, nameof(property)).PrimaryKey;
/// <summary> /// Returns the <see cref="CoreTypeMapping" /> for the given property. /// </summary> /// <param name="property"> The property. </param> /// <returns> The type mapping, or <see langword="null"/> if none was found. </returns> public static CoreTypeMapping FindTypeMapping([NotNull] this IProperty property) => ((Property)property).TypeMapping;
/// <summary> /// Gets the maximum length of data that is allowed in this property. For example, if the property is a <see cref="string" /> ' /// then this is the maximum number of characters. /// </summary> /// <param name="property"> The property to get the maximum length of. </param> /// <returns> The maximum length, or <see langword="null"/> if none if defined. </returns> public static int?GetMaxLength([NotNull] this IProperty property) { Check.NotNull(property, nameof(property)); return((int?)property[CoreAnnotationNames.MaxLength]); }
private static object SnapshotValue(IProperty property, ValueComparer comparer, IUpdateEntry entry) => SnapshotValue(comparer, entry.GetCurrentValue(property));
private static ValueComparer GetStructuralComparer(IProperty p) => p.GetStructuralValueComparer() ?? p.FindTypeMapping()?.StructuralComparer;
/// <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 FileContextIntegerValueGenerator <TProperty> GetIntegerValueGenerator <TProperty>(IProperty property) { if (_integerGenerators == null) { _integerGenerators = new Dictionary <int, IFileContextIntegerValueGenerator>(); } // WARNING: The in-memory provider is using EF internal code here. This should not be copied by other providers. See #15096 var propertyIndex = Microsoft.EntityFrameworkCore.Metadata.Internal.PropertyBaseExtensions.GetIndex(property); if (!_integerGenerators.TryGetValue(propertyIndex, out var generator)) { generator = new FileContextIntegerValueGenerator <TProperty>(propertyIndex); _integerGenerators[propertyIndex] = generator; foreach (var row in _rows.Values) { generator.Bump(row); } } return((FileContextIntegerValueGenerator <TProperty>)generator); }
public RelationalPropertyAnnotations([NotNull] IProperty property, [CanBeNull] string providerPrefix) : this(new RelationalAnnotations(property, providerPrefix)) { }
public override bool HasChildNodes(ITreeBuilder builder, object dataObject) { IProperty property = (IProperty)dataObject; return(property.HasGet || property.HasSet); }
/// <summary> /// Gets the scale of data that is allowed in this property. /// For example, if the property is a <see cref="decimal" /> /// then this is the maximum number of decimal places. /// </summary> /// <param name="property"> The property to get the scale of. </param> /// <returns> The scale, or <see langword="null"/> if none is defined. </returns> public static int?GetScale([NotNull] this IProperty property) { Check.NotNull(property, nameof(property)); return((int?)property[CoreAnnotationNames.Scale]); }
private static ValueConverter FindValueConverter(IProperty property) => property.FindMapping()?.Converter ?? property.GetValueConverter();
/// <summary> /// Gets the precision of data that is allowed in this property. /// For example, if the property is a <see cref="decimal" /> /// then this is the maximum number of digits. /// </summary> /// <param name="property"> The property to get the precision of. </param> /// <returns> The precision, or <see langword="null"/> if none is defined. </returns> public static int?GetPrecision([NotNull] this IProperty property) { Check.NotNull(property, nameof(property)); return((int?)property[CoreAnnotationNames.Precision]); }
protected override string GetColumnType(IProperty property) => property.TestProvider().ColumnType;
public void KeyPropertyChanged( InternalEntityEntry entry, IProperty property, IReadOnlyList <IKey> containingPrincipalKeys, IReadOnlyList <IForeignKey> containingForeignKeys, object oldValue, object newValue) { }
/// <summary> /// Generates code for the annotations on an <see cref="IProperty" />. /// </summary> /// <param name="property"> The property. </param> /// <param name="stringBuilder"> The builder code is added to. </param> protected virtual void GeneratePropertyAnnotations([NotNull] IProperty property, [NotNull] IndentedStringBuilder stringBuilder) { Check.NotNull(property, nameof(property)); Check.NotNull(stringBuilder, nameof(stringBuilder)); var annotations = property.GetAnnotations().ToList(); var valueConverter = FindValueConverter(property); if (valueConverter != null) { var hints = valueConverter.MappingHints; if (hints != null) { var storeType = Code.Reference(valueConverter.ProviderClrType); stringBuilder .AppendLine() .Append(".") .Append(nameof(PropertyBuilder.HasConversion)) .Append("(new ") .Append(nameof(ValueConverter)) .Append("<") .Append(storeType) .Append(", ") .Append(storeType) .Append(">(v => default(") .Append(storeType) .Append("), v => default(") .Append(storeType); var nonNulls = new List <string>(); if (hints.Size != null) { nonNulls.Add("size: " + Code.Literal(hints.Size.Value)); } if (hints.Precision != null) { nonNulls.Add("precision: " + Code.Literal(hints.Precision.Value)); } if (hints.Scale != null) { nonNulls.Add("scale: " + Code.Literal(hints.Scale.Value)); } if (hints.IsUnicode != null) { nonNulls.Add("unicode: " + Code.Literal(hints.IsUnicode.Value)); } if (hints is RelationalConverterMappingHints relationalHints && relationalHints.IsFixedLength != null) { nonNulls.Add("fixedLength: " + Code.Literal(relationalHints.IsFixedLength.Value)); } stringBuilder .Append("), new ConverterMappingHints(") .Append(string.Join(", ", nonNulls)) .Append(")))"); } } GenerateFluentApiForAnnotation(ref annotations, RelationalAnnotationNames.ColumnName, nameof(RelationalPropertyBuilderExtensions.HasColumnName), stringBuilder); GenerateFluentApiForAnnotation(ref annotations, RelationalAnnotationNames.ColumnType, nameof(RelationalPropertyBuilderExtensions.HasColumnType), stringBuilder); GenerateFluentApiForAnnotation(ref annotations, RelationalAnnotationNames.DefaultValueSql, nameof(RelationalPropertyBuilderExtensions.HasDefaultValueSql), stringBuilder); GenerateFluentApiForAnnotation(ref annotations, RelationalAnnotationNames.ComputedColumnSql, nameof(RelationalPropertyBuilderExtensions.HasComputedColumnSql), stringBuilder); GenerateFluentApiForAnnotation(ref annotations, RelationalAnnotationNames.IsFixedLength, nameof(RelationalPropertyBuilderExtensions.IsFixedLength), stringBuilder); GenerateFluentApiForAnnotation(ref annotations, CoreAnnotationNames.MaxLength, nameof(PropertyBuilder.HasMaxLength), stringBuilder); GenerateFluentApiForAnnotation(ref annotations, CoreAnnotationNames.Unicode, nameof(PropertyBuilder.IsUnicode), stringBuilder); GenerateFluentApiForAnnotation( ref annotations, RelationalAnnotationNames.DefaultValue, a => valueConverter == null ? a?.Value : valueConverter.ConvertToProvider(a?.Value), nameof(RelationalPropertyBuilderExtensions.HasDefaultValue), stringBuilder); IgnoreAnnotations( annotations, CoreAnnotationNames.ValueGeneratorFactory, CoreAnnotationNames.PropertyAccessMode, CoreAnnotationNames.ChangeTrackingStrategy, CoreAnnotationNames.BeforeSaveBehavior, CoreAnnotationNames.AfterSaveBehavior, CoreAnnotationNames.TypeMapping, CoreAnnotationNames.ValueComparer, CoreAnnotationNames.KeyValueComparer, CoreAnnotationNames.StructuralValueComparer, CoreAnnotationNames.ValueConverter, CoreAnnotationNames.ProviderClrType); GenerateAnnotations(annotations, stringBuilder); }
/// <summary> /// <para> /// Creates a human-readable representation of the given metadata. /// </para> /// <para> /// Warning: Do not rely on the format of the returned string. /// It is designed for debugging only and may change arbitrarily between releases. /// </para> /// </summary> /// <param name="property"> The metadata item. </param> /// <param name="options"> Options for generating the string. </param> /// <param name="indent"> The number of indent spaces to use before each new line. </param> /// <returns> A human-readable representation. </returns> public static string ToDebugString( [NotNull] this IProperty property, MetadataDebugStringOptions options, int indent = 0) { var builder = new StringBuilder(); var indentString = new string(' ', indent); builder.Append(indentString); var singleLine = (options & MetadataDebugStringOptions.SingleLine) != 0; if (singleLine) { builder.Append($"Property: {property.DeclaringEntityType.DisplayName()}."); } builder.Append(property.Name).Append(" ("); var field = property.GetFieldName(); if (field == null) { builder.Append("no field, "); } else if (!field.EndsWith(">k__BackingField", StringComparison.Ordinal)) { builder.Append(field).Append(", "); } builder.Append(property.ClrType.ShortDisplayName()).Append(")"); if (property.IsShadowProperty()) { builder.Append(" Shadow"); } if (!property.IsNullable) { builder.Append(" Required"); } if (property.IsPrimaryKey()) { builder.Append(" PK"); } if (property.IsForeignKey()) { builder.Append(" FK"); } if (property.IsKey() && !property.IsPrimaryKey()) { builder.Append(" AlternateKey"); } if (property.IsIndex()) { builder.Append(" Index"); } if (property.IsConcurrencyToken) { builder.Append(" Concurrency"); } if (property.GetBeforeSaveBehavior() != PropertySaveBehavior.Save) { builder.Append(" BeforeSave:").Append(property.GetBeforeSaveBehavior()); } if (property.GetAfterSaveBehavior() != PropertySaveBehavior.Save) { builder.Append(" AfterSave:").Append(property.GetAfterSaveBehavior()); } if (property.ValueGenerated != ValueGenerated.Never) { builder.Append(" ValueGenerated.").Append(property.ValueGenerated); } if (property.GetMaxLength() != null) { builder.Append(" MaxLength(").Append(property.GetMaxLength()).Append(")"); } if (property.IsUnicode() == false) { builder.Append(" Ansi"); } if (property.GetPropertyAccessMode() != PropertyAccessMode.PreferField) { builder.Append(" PropertyAccessMode.").Append(property.GetPropertyAccessMode()); } if ((options & MetadataDebugStringOptions.IncludePropertyIndexes) != 0) { var indexes = property.GetPropertyIndexes(); if (indexes != null) { builder.Append(" ").Append(indexes.Index); builder.Append(" ").Append(indexes.OriginalValueIndex); builder.Append(" ").Append(indexes.RelationshipIndex); builder.Append(" ").Append(indexes.ShadowIndex); builder.Append(" ").Append(indexes.StoreGenerationIndex); } } if (!singleLine && (options & MetadataDebugStringOptions.IncludeAnnotations) != 0) { builder.Append(property.AnnotationsToDebugString(indent + 2)); } return(builder.ToString()); }
/// <summary> /// Selects the appropriate value generator for a given property. /// </summary> /// <param name="property">The property to get the value generator for.</param> /// <param name="entityType"> /// The entity type that the value generator will be used for. When called on inherited properties on derived entity types, /// this entity type may be different from the declared entity type on <paramref name="property" /> /// </param> /// <returns>The value generator to be used.</returns> public virtual ValueGenerator Select(IProperty property, IEntityType entityType) => Cache.GetOrAdd(property, entityType, (p, t) => CreateFromFactory(p, t) ?? Create(p, t));
/// <summary> /// Creates an <see cref="IEqualityComparer{T}" /> for values of the given property type. /// </summary> /// <param name="property"> The property. </param> /// <typeparam name="TProperty"> The property type. </typeparam> /// <returns> A new equality comparer. </returns> public static IEqualityComparer <TProperty> CreateKeyEqualityComparer <TProperty>([NotNull] this IProperty property) { var comparer = property.GetKeyValueComparer(); return(comparer is IEqualityComparer <TProperty> nullableComparer ? nullableComparer : new NullableComparer <TProperty>(comparer)); }
public static ValueComparer GetStructuralValueComparer([NotNull] this IProperty property) => property.GetKeyValueComparer();
/// <summary> /// Gets all primary or alternate keys that use this property (including composite keys in which this property /// is included). /// </summary> /// <param name="property"> The property to get primary and alternate keys for. </param> /// <returns> The primary and alternate keys that use this property. </returns> public static IEnumerable <IKey> GetContainingKeys([NotNull] this IProperty property) => Check.NotNull((Property)property, nameof(property)).GetContainingKeys();
/// <summary> /// Gets the type that the property value will be converted to before being sent to the database provider. /// </summary> /// <param name="property"> The property. </param> /// <returns> The provider type, or <see langword="null"/> if none has been set. </returns> public static Type GetProviderClrType([NotNull] this IProperty property) => (Type)Check.NotNull(property, nameof(property))[CoreAnnotationNames.ProviderClrType];
public override string GetNodeName(ITreeNavigator thisNode, object dataObject) { IProperty property = (IProperty)dataObject; return(property.Name); }
public virtual PropertyConfiguration FindPropertyConfiguration([NotNull] IProperty property) { Check.NotNull(property, nameof(property)); return(PropertyConfigurations.FirstOrDefault(pc => pc.Property == property)); }
public override CodeGeneratorMemberResult Visit(IProperty property, CodeGenerationOptions options) { var regions = new List <CodeGeneratorBodyRegion> (); var result = new StringBuilder(); AppendModifiers(result, options, property); AppendReturnType(result, options.ImplementingType, property.ReturnType); result.Append(" "); if (property.IsIndexer) { result.Append("this["); AppendParameterList(result, options.ImplementingType, property.Parameters); result.Append("]"); } else { if (options.ExplicitDeclaration) { result.Append(ambience.GetString(new DomReturnType(property.DeclaringType), OutputFlags.IncludeGenerics)); result.Append("."); } result.Append(property.Name); } generator.AppendBraceStart(result, generator.policy.PropertyBraceStyle); if (property.HasGet) { int bodyStartOffset, bodyEndOffset; generator.AppendIndent(result); result.Append("get"); generator.AppendBraceStart(result, generator.policy.PropertyGetBraceStyle); if (IsMonoTouchModelMember(property)) { AppendMonoTouchTodo(result, out bodyStartOffset, out bodyEndOffset); } else if (property.IsAbstract || property.DeclaringType.ClassType == ClassType.Interface) { AppendNotImplementedException(result, options, out bodyStartOffset, out bodyEndOffset); } else { generator.AppendIndent(result); bodyStartOffset = result.Length; result.Append("return base."); result.Append(property.Name); result.Append(";"); bodyEndOffset = result.Length; result.AppendLine(); } generator.AppendBraceEnd(result, generator.policy.PropertyGetBraceStyle); result.AppendLine(); regions.Add(new CodeGeneratorBodyRegion(bodyStartOffset, bodyEndOffset)); } if (property.HasSet) { int bodyStartOffset, bodyEndOffset; generator.AppendIndent(result); result.Append("set"); generator.AppendBraceStart(result, generator.policy.PropertyGetBraceStyle); if (IsMonoTouchModelMember(property)) { AppendMonoTouchTodo(result, out bodyStartOffset, out bodyEndOffset); } else if (property.IsAbstract || property.DeclaringType.ClassType == ClassType.Interface) { AppendNotImplementedException(result, options, out bodyStartOffset, out bodyEndOffset); } else { generator.AppendIndent(result); bodyStartOffset = result.Length; result.Append("base."); result.Append(property.Name); result.Append(" = value;"); bodyEndOffset = result.Length; result.AppendLine(); } generator.AppendBraceEnd(result, generator.policy.PropertyGetBraceStyle); result.AppendLine(); regions.Add(new CodeGeneratorBodyRegion(bodyStartOffset, bodyEndOffset)); } generator.AppendBraceEnd(result, generator.policy.PropertyBraceStyle); return(new CodeGeneratorMemberResult(result.ToString(), regions)); }
/// <summary> /// Gets a value indicating whether this property is used as the primary key (or part of a composite primary key). /// </summary> /// <param name="property"> The property to check. </param> /// <returns> <see langword="true"/> if the property is used as the primary key, otherwise <see langword="false"/>. </returns> public static bool IsPrimaryKey([NotNull] this IProperty property) => FindContainingPrimaryKey(property) != null;