Skip to content
This repository has been archived by the owner on Jan 16, 2024. It is now read-only.

Commit

Permalink
Testing assoc backing fields
Browse files Browse the repository at this point in the history
  • Loading branch information
msawczyn committed Sep 8, 2020
1 parent f9b66df commit 9f54128
Show file tree
Hide file tree
Showing 45 changed files with 1,219 additions and 1,120 deletions.
82 changes: 36 additions & 46 deletions src/Dsl/CustomCode/Partials/ModelClass.cs
Expand Up @@ -319,58 +319,48 @@ public IEnumerable<NavigationProperty> LocalNavigationProperties(params Associat
List<NavigationProperty> sourceProperties = Association.GetLinksToTargets(this)
.Except(ignore)
.Select(x => new NavigationProperty
{
Cardinality = x.TargetMultiplicity
,
ClassType = x.Target
,
AssociationObject = x
,
PropertyName = x.TargetPropertyName
,
Summary = x.TargetSummary
,
Description = x.TargetDescription
,
CustomAttributes = x.TargetCustomAttributes
,
DisplayText = x.TargetDisplayText
,
IsAutoProperty = true
,
ImplementNotify = x.TargetImplementNotify
,
FKPropertyName = x.TargetRole == EndpointRole.Principal ? x.FKPropertyName : null
})
{
Cardinality = x.TargetMultiplicity
, ClassType = x.Target
, AssociationObject = x
, PropertyName = x.TargetPropertyName
, Summary = x.TargetSummary
, Description = x.TargetDescription
, CustomAttributes = x.TargetCustomAttributes
, DisplayText = x.TargetDisplayText
, IsAutoProperty = x.TargetAutoProperty
, BackingFieldName = x.TargetAutoProperty
? null
: x.TargetBackingFieldName
, ImplementNotify = x.TargetImplementNotify
, FKPropertyName = x.TargetRole == EndpointRole.Principal
? x.FKPropertyName
: null
})
.ToList();

List<NavigationProperty> targetProperties = Association.GetLinksToSources(this)
.Except(ignore)
.OfType<BidirectionalAssociation>()
.Select(x => new NavigationProperty
{
Cardinality = x.SourceMultiplicity
,
ClassType = x.Source
,
AssociationObject = x
,
PropertyName = x.SourcePropertyName
,
Summary = x.SourceSummary
,
Description = x.SourceDescription
,
CustomAttributes = x.SourceCustomAttributes
,
DisplayText = x.SourceDisplayText
,
IsAutoProperty = true
,
ImplementNotify = x.SourceImplementNotify
,
FKPropertyName = x.SourceRole == EndpointRole.Principal ? x.FKPropertyName : null
})
{
Cardinality = x.SourceMultiplicity
, ClassType = x.Source
, AssociationObject = x
, PropertyName = x.SourcePropertyName
, Summary = x.SourceSummary
, Description = x.SourceDescription
, CustomAttributes = x.SourceCustomAttributes
, DisplayText = x.SourceDisplayText
, IsAutoProperty = x.SourceAutoProperty
, BackingFieldName = x.SourceAutoProperty
? null
: x.SourceBackingFieldName
, ImplementNotify = x.SourceImplementNotify
, FKPropertyName = x.SourceRole == EndpointRole.Principal
? x.FKPropertyName
: null
})
.ToList();

targetProperties.AddRange(Association.GetLinksToSources(this)
Expand Down
102 changes: 93 additions & 9 deletions src/Dsl/CustomCode/Type Converters/PropertyAccessModeTypeConverter.cs
@@ -1,21 +1,71 @@
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Globalization;

using Microsoft.VisualStudio.Modeling;

using Sawczyn.EFDesigner.EFModel.Extensions;

namespace Sawczyn.EFDesigner.EFModel
{
public class PropertyAccessModeTypeConverter : EnumConverter
public class PropertyAccessModeTypeConverter : TypeConverterBase
{
/// <summary>Initializes a new instance of the <see cref="T:System.ComponentModel.EnumConverter" /> class for the given type.</summary>
/// <param name="type">A <see cref="T:System.Type" /> that represents the type of enumeration to associate with this enumeration converter. </param>
public PropertyAccessModeTypeConverter() : base(typeof(PropertyAccessMode)) { }
/// <summary>
/// Returns whether this converter can convert an object of the given type to the type of this converter, using
/// the specified context.
/// </summary>
/// <returns>true if this converter can perform the conversion; otherwise, false.</returns>
/// <param name="context">An <see cref="T:System.ComponentModel.ITypeDescriptorContext" /> that provides a format context. </param>
/// <param name="sourceType">A <see cref="T:System.Type" /> that represents the type you want to convert from. </param>
public override bool CanConvertFrom(ITypeDescriptorContext context, Type sourceType)
{
return sourceType == typeof(string);
}

/// <summary>Returns whether this converter can convert the object to the specified type, using the specified context.</summary>
/// <returns>true if this converter can perform the conversion; otherwise, false.</returns>
/// <param name="context">An <see cref="T:System.ComponentModel.ITypeDescriptorContext" /> that provides a format context. </param>
/// <param name="destinationType">A <see cref="T:System.Type" /> that represents the type you want to convert to. </param>
public override bool CanConvertTo(ITypeDescriptorContext context, Type destinationType)
{
return destinationType == typeof(PropertyAccessMode);
}

/// <summary>Converts the given object to the type of this converter, using the specified context and culture information.</summary>
/// <returns>An <see cref="T:System.Object" /> that represents the converted value.</returns>
/// <param name="context">An <see cref="T:System.ComponentModel.ITypeDescriptorContext" /> that provides a format context. </param>
/// <param name="culture">The <see cref="T:System.Globalization.CultureInfo" /> to use as the current culture. </param>
/// <param name="value">The <see cref="T:System.Object" /> to convert. </param>
/// <exception cref="T:System.NotSupportedException">The conversion cannot be performed. </exception>
public override object ConvertFrom(ITypeDescriptorContext context, CultureInfo culture, object value)
{
if (value is string s)
{
switch (s)
{
case "Field":
return PropertyAccessMode.Field;

case "FieldDuringConstruction":
return PropertyAccessMode.FieldDuringConstruction;

case "PreferField":
return PropertyAccessMode.PreferField;

case "PreferFieldDuringConstruction":
return PropertyAccessMode.PreferFieldDuringConstruction;

case "PreferProperty":
return PropertyAccessMode.PreferProperty;

case "Property":
return PropertyAccessMode.Property;
}
}

return base.ConvertFrom(context, culture, value);
}

/// <summary>
/// Returns a collection of standard values for the data type this type converter is designed for when provided
Expand All @@ -42,7 +92,8 @@ public override StandardValuesCollection GetStandardValues(ITypeDescriptorContex
? objects[0] as IHasStore
: context.Instance as IHasStore;

Store store = currentElement?.Store;
Store store = GetStore(currentElement);

if (store != null)
{
ModelRoot modelRoot = store.ModelRoot();
Expand All @@ -52,13 +103,16 @@ public override StandardValuesCollection GetStandardValues(ITypeDescriptorContex
return new StandardValuesCollection(values);

if (modelRoot.GetEntityFrameworkPackageVersionNum() < 3)
{
values.AddRange(new[]
{
"Field"
, "FieldDuringConstruction"
, "Property"
});
}
else
{
values.AddRange(new[]
{
"Field"
Expand All @@ -68,10 +122,40 @@ public override StandardValuesCollection GetStandardValues(ITypeDescriptorContex
, "PreferProperty"
, "Property"
});
}
}

return new StandardValuesCollection(values);
}

/// <summary>
/// Returns whether the collection of standard values returned from
/// <see cref="M:System.ComponentModel.TypeConverter.GetStandardValues" /> is an exclusive list of possible values,
/// using the specified context.
/// </summary>
/// <returns>
/// true if the <see cref="T:System.ComponentModel.TypeConverter.StandardValuesCollection" /> returned from
/// <see cref="M:System.ComponentModel.TypeConverter.GetStandardValues" /> is an exhaustive list of possible values;
/// false if other values are possible.
/// </returns>
/// <param name="context">An <see cref="T:System.ComponentModel.ITypeDescriptorContext" /> that provides a format context. </param>
public override bool GetStandardValuesExclusive(ITypeDescriptorContext context)
{
return true;
}

/// <summary>
/// Returns whether this object supports a standard set of values that can be picked from a list, using the
/// specified context.
/// </summary>
/// <returns>
/// true if <see cref="M:System.ComponentModel.TypeConverter.GetStandardValues" /> should be called to find a
/// common set of values the object supports; otherwise, false.
/// </returns>
/// <param name="context">An <see cref="T:System.ComponentModel.ITypeDescriptorContext" /> that provides a format context. </param>
public override bool GetStandardValuesSupported(ITypeDescriptorContext context)
{
return true;
}
}
}
}

0 comments on commit 9f54128

Please sign in to comment.