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

Commit

Permalink
Added PropertyExposure
Browse files Browse the repository at this point in the history
  • Loading branch information
msawczyn committed Sep 10, 2020
1 parent a009a9c commit a882a23
Show file tree
Hide file tree
Showing 9 changed files with 369 additions and 127 deletions.
14 changes: 14 additions & 0 deletions src/Dsl/DslDefinition.dsl
Expand Up @@ -738,6 +738,11 @@
<DomainEnumerationMoniker Name="PropertyAccessMode" />
</Type>
</DomainProperty>
<DomainProperty Id="247afa44-837d-4472-94c7-74f319c10510" Description="How should this property be exposed in code?" Name="ExposeAs" DisplayName="Expose As" DefaultValue="Property" Category="Code Generation">
<Type>
<DomainEnumerationMoniker Name="PropertyExposure" />
</Type>
</DomainProperty>
</Properties>
</DomainClass>
<DomainClass Id="e2c13b26-0944-4b6c-89b5-bb95c500f515" Description="" Name="Comment" DisplayName="Comment" Namespace="Sawczyn.EFDesigner.EFModel">
Expand Down Expand Up @@ -1664,6 +1669,12 @@
<EnumerationLiteral Description="Enforces that all accesses to the property must go through the property getters and setters, even when new objects are being constructed. An exception will be thrown if this mode is set and it is not possible to read from or write to the property, for example because it is read-only." Name="Property" Value="2" />
</Literals>
</DomainEnumeration>
<DomainEnumeration Name="PropertyExposure" Namespace="Sawczyn.EFDesigner.EFModel" Description="How the code generator will present this property to Entity Framework (EFCore5+ only)">
<Literals>
<EnumerationLiteral Description="Generated code will create and use this attribute as a .NET property," Name="Property" Value="" />
<EnumerationLiteral Description="Generated code will create and use this attribute as a .NET field" Name="Field" Value="" />
</Literals>
</DomainEnumeration>
</Types>
<Shapes>
<CompartmentShape Id="8055f08f-3d3a-435f-8b47-7afcd0e051bd" Description="" Name="ClassShape" DisplayName="Class Shape" Namespace="Sawczyn.EFDesigner.EFModel" GeneratesDoubleDerived="true" FixedTooltipText="Class Shape" TextColor="White" ExposesTextColor="true" FillColor="0, 122, 204" InitialHeight="0.3" OutlineThickness="0.01" FillGradientMode="None" ExposesOutlineColorAsProperty="true" ExposesFillColorAsProperty="true" ExposesOutlineDashStyleAsProperty="true" ExposesOutlineThicknessAsProperty="true" Geometry="Rectangle">
Expand Down Expand Up @@ -2294,6 +2305,9 @@
<XmlPropertyData XmlName="propertyAccessMode">
<DomainPropertyMoniker Name="ModelAttribute/PropertyAccessMode" />
</XmlPropertyData>
<XmlPropertyData XmlName="exposeAs">
<DomainPropertyMoniker Name="ModelAttribute/ExposeAs" />
</XmlPropertyData>
</ElementData>
</XmlClassData>
<XmlClassData TypeName="Comment" MonikerAttributeName="" SerializeId="true" MonikerElementName="commentMoniker" ElementName="comment" MonikerTypeName="CommentMoniker">
Expand Down
238 changes: 119 additions & 119 deletions src/Dsl/DslDefinition.dsl.diagram

Large diffs are not rendered by default.

89 changes: 89 additions & 0 deletions src/Dsl/GeneratedCode/DomainClasses.cs
Expand Up @@ -9490,6 +9490,95 @@ public override sealed void SetValue(ModelAttribute element, PropertyAccessMode
}
}

#endregion
#region ExposeAs domain property code

/// <summary>
/// ExposeAs domain property Id.
/// </summary>
public static readonly global::System.Guid ExposeAsDomainPropertyId = new global::System.Guid(0x247afa44, 0x837d, 0x4472, 0x94, 0xc7, 0x74, 0xf3, 0x19, 0xc1, 0x05, 0x10);

/// <summary>
/// Storage for ExposeAs
/// </summary>
private PropertyExposure exposeAsPropertyStorage = PropertyExposure.Property;

/// <summary>
/// Gets or sets the value of ExposeAs domain property.
/// How should this property be exposed in code?
/// </summary>
[DslDesign::DisplayNameResource("Sawczyn.EFDesigner.EFModel.ModelAttribute/ExposeAs.DisplayName", typeof(global::Sawczyn.EFDesigner.EFModel.EFModelDomainModel), "Sawczyn.EFDesigner.EFModel.GeneratedCode.DomainModelResx")]
[DslDesign::CategoryResource("Sawczyn.EFDesigner.EFModel.ModelAttribute/ExposeAs.Category", typeof(global::Sawczyn.EFDesigner.EFModel.EFModelDomainModel), "Sawczyn.EFDesigner.EFModel.GeneratedCode.DomainModelResx")]
[DslDesign::DescriptionResource("Sawczyn.EFDesigner.EFModel.ModelAttribute/ExposeAs.Description", typeof(global::Sawczyn.EFDesigner.EFModel.EFModelDomainModel), "Sawczyn.EFDesigner.EFModel.GeneratedCode.DomainModelResx")]
[global::System.ComponentModel.DefaultValue(PropertyExposure.Property)]
[DslModeling::DomainObjectId("247afa44-837d-4472-94c7-74f319c10510")]
public PropertyExposure ExposeAs
{
[global::System.Diagnostics.DebuggerStepThrough]
get
{
return exposeAsPropertyStorage;
}
[global::System.Diagnostics.DebuggerStepThrough]
set
{
ExposeAsPropertyHandler.Instance.SetValue(this, value);
}
}
/// <summary>
/// Value handler for the ModelAttribute.ExposeAs domain property.
/// </summary>
internal sealed partial class ExposeAsPropertyHandler : DslModeling::DomainPropertyValueHandler<ModelAttribute, PropertyExposure>
{
private ExposeAsPropertyHandler() { }

/// <summary>
/// Gets the singleton instance of the ModelAttribute.ExposeAs domain property value handler.
/// </summary>
public static readonly ExposeAsPropertyHandler Instance = new ExposeAsPropertyHandler();

/// <summary>
/// Gets the Id of the ModelAttribute.ExposeAs domain property.
/// </summary>
public sealed override global::System.Guid DomainPropertyId
{
[global::System.Diagnostics.DebuggerStepThrough]
get
{
return ExposeAsDomainPropertyId;
}
}

/// <summary>
/// Gets a strongly-typed value of the property on specified element.
/// </summary>
/// <param name="element">Element which owns the property.</param>
/// <returns>Property value.</returns>
public override sealed PropertyExposure GetValue(ModelAttribute element)
{
if (element == null) throw new global::System.ArgumentNullException("element");
return element.exposeAsPropertyStorage;
}

/// <summary>
/// Sets property value on an element.
/// </summary>
/// <param name="element">Element which owns the property.</param>
/// <param name="newValue">New property value.</param>
public override sealed void SetValue(ModelAttribute element, PropertyExposure newValue)
{
if (element == null) throw new global::System.ArgumentNullException("element");

PropertyExposure oldValue = GetValue(element);
if (newValue != oldValue)
{
ValueChanging(element, oldValue, newValue);
element.exposeAsPropertyStorage = newValue;
ValueChanged(element, oldValue, newValue);
}
}
}

#endregion
#region ModelClass opposite domain role accessor
/// <summary>
Expand Down
25 changes: 25 additions & 0 deletions src/Dsl/GeneratedCode/DomainModel.cs
Expand Up @@ -215,6 +215,7 @@ protected sealed override DomainMemberInfo[] GetGeneratedDomainProperties()
new DomainMemberInfo(typeof(ModelAttribute), "DatabaseCollation", ModelAttribute.DatabaseCollationDomainPropertyId, typeof(ModelAttribute.DatabaseCollationPropertyHandler)),
new DomainMemberInfo(typeof(ModelAttribute), "IsDatabaseCollationTracking", ModelAttribute.IsDatabaseCollationTrackingDomainPropertyId, typeof(ModelAttribute.IsDatabaseCollationTrackingPropertyHandler)),
new DomainMemberInfo(typeof(ModelAttribute), "PropertyAccessMode", ModelAttribute.PropertyAccessModeDomainPropertyId, typeof(ModelAttribute.PropertyAccessModePropertyHandler)),
new DomainMemberInfo(typeof(ModelAttribute), "ExposeAs", ModelAttribute.ExposeAsDomainPropertyId, typeof(ModelAttribute.ExposeAsPropertyHandler)),
new DomainMemberInfo(typeof(Comment), "Text", Comment.TextDomainPropertyId, typeof(Comment.TextPropertyHandler)),
new DomainMemberInfo(typeof(Comment), "ShortText", Comment.ShortTextDomainPropertyId, typeof(Comment.ShortTextPropertyHandler)),
new DomainMemberInfo(typeof(ModelEnum), "ValueType", ModelEnum.ValueTypeDomainPropertyId, typeof(ModelEnum.ValueTypePropertyHandler)),
Expand Down Expand Up @@ -1584,3 +1585,27 @@ public enum PropertyAccessMode
Property = 2,
}
}
namespace Sawczyn.EFDesigner.EFModel
{
/// <summary>
/// DomainEnumeration: PropertyExposure
/// How the code generator will present this property to Entity Framework (EFCore5+
/// only)
/// </summary>
[global::System.CLSCompliant(true)]
public enum PropertyExposure
{
/// <summary>
/// Property
/// Generated code will create and use this attribute as a .NET property,
/// </summary>
[DslDesign::DescriptionResource("Sawczyn.EFDesigner.EFModel.PropertyExposure/Property.Description", typeof(global::Sawczyn.EFDesigner.EFModel.EFModelDomainModel), "Sawczyn.EFDesigner.EFModel.GeneratedCode.DomainModelResx")]
Property,
/// <summary>
/// Field
/// Generated code will create and use this attribute as a .NET field
/// </summary>
[DslDesign::DescriptionResource("Sawczyn.EFDesigner.EFModel.PropertyExposure/Field.Description", typeof(global::Sawczyn.EFDesigner.EFModel.EFModelDomainModel), "Sawczyn.EFDesigner.EFModel.GeneratedCode.DomainModelResx")]
Field,
}
}
28 changes: 28 additions & 0 deletions src/Dsl/GeneratedCode/DomainModelResx.resx
Expand Up @@ -1293,6 +1293,18 @@
<value>Code Generation</value>
<comment>Category for DomainProperty &apos;PropertyAccessMode&apos; on DomainClass &apos;ModelAttribute&apos;</comment>
</data>
<data name="Sawczyn.EFDesigner.EFModel.ModelAttribute/ExposeAs.Description" xml:space="preserve">
<value>How should this property be exposed in code?</value>
<comment>Description for DomainProperty &apos;ExposeAs&apos; on DomainClass &apos;ModelAttribute&apos;</comment>
</data>
<data name="Sawczyn.EFDesigner.EFModel.ModelAttribute/ExposeAs.DisplayName" xml:space="preserve">
<value>Expose As</value>
<comment>DisplayName for DomainProperty &apos;ExposeAs&apos; on DomainClass &apos;ModelAttribute&apos;</comment>
</data>
<data name="Sawczyn.EFDesigner.EFModel.ModelAttribute/ExposeAs.Category" xml:space="preserve">
<value>Code Generation</value>
<comment>Category for DomainProperty &apos;ExposeAs&apos; on DomainClass &apos;ModelAttribute&apos;</comment>
</data>
<data name="Sawczyn.EFDesigner.EFModel.Comment.Description" xml:space="preserve">
<value></value>
<comment>Description for DomainClass &apos;Comment&apos;</comment>
Expand Down Expand Up @@ -3245,6 +3257,22 @@
<value>Enforces that all accesses to the property must go through the property getters and setters, even when new objects are being constructed. An exception will be thrown if this mode is set and it is not possible to read from or write to the property, for example because it is read-only.</value>
<comment>Description for EnumerationLiteral &apos;Property&apos; on DomainEnumeration &apos;PropertyAccessMode&apos;</comment>
</data>
<data name="Sawczyn.EFDesigner.EFModel.PropertyExposure/Property.DisplayName" xml:space="preserve">
<value>Property</value>
<comment>Display name for EnumerationLiteral &apos;Property&apos; on DomainEnumeration &apos;PropertyExposure&apos;</comment>
</data>
<data name="Sawczyn.EFDesigner.EFModel.PropertyExposure/Property.Description" xml:space="preserve">
<value>Generated code will create and use this attribute as a .NET property,</value>
<comment>Description for EnumerationLiteral &apos;Property&apos; on DomainEnumeration &apos;PropertyExposure&apos;</comment>
</data>
<data name="Sawczyn.EFDesigner.EFModel.PropertyExposure/Field.DisplayName" xml:space="preserve">
<value>Field</value>
<comment>Display name for EnumerationLiteral &apos;Field&apos; on DomainEnumeration &apos;PropertyExposure&apos;</comment>
</data>
<data name="Sawczyn.EFDesigner.EFModel.PropertyExposure/Field.Description" xml:space="preserve">
<value>Generated code will create and use this attribute as a .NET field</value>
<comment>Description for EnumerationLiteral &apos;Field&apos; on DomainEnumeration &apos;PropertyExposure&apos;</comment>
</data>
<data name="Sawczyn.EFDesigner.EFModel.ClassShape.Description" xml:space="preserve">
<value></value>
<comment>Description for DomainClass &apos;ClassShape&apos;</comment>
Expand Down
25 changes: 25 additions & 0 deletions src/Dsl/GeneratedCode/EFModelSchema.xsd
Expand Up @@ -784,6 +784,12 @@
<xsd:documentation>Defines how EF reads and write this property or its backing field. See https://docs.microsoft.com/en-us/dotnet/api/microsoft.entityframeworkcore.propertyaccessmode</xsd:documentation>
</xsd:annotation>
</xsd:attribute>
<!-- Property: ExposeAs -->
<xsd:attribute name="exposeAs" type="PropertyExposure" >
<xsd:annotation>
<xsd:documentation>How should this property be exposed in code?</xsd:documentation>
</xsd:annotation>
</xsd:attribute>
</xsd:extension>
</xsd:complexContent>
</xsd:complexType>
Expand Down Expand Up @@ -2336,5 +2342,24 @@
</xsd:restriction>
</xsd:simpleType>

<!-- Enum PropertyExposure -->
<xsd:simpleType name="PropertyExposure">
<xsd:annotation>
<xsd:documentation>How the code generator will present this property to Entity Framework (EFCore5+ only)</xsd:documentation>
</xsd:annotation>
<xsd:restriction base="xsd:string">
<xsd:enumeration value="Property">
<xsd:annotation>
<xsd:documentation>Generated code will create and use this attribute as a .NET property,</xsd:documentation>
</xsd:annotation>
</xsd:enumeration>
<xsd:enumeration value="Field">
<xsd:annotation>
<xsd:documentation>Generated code will create and use this attribute as a .NET field</xsd:documentation>
</xsd:annotation>
</xsd:enumeration>
</xsd:restriction>
</xsd:simpleType>

</xsd:schema>

25 changes: 25 additions & 0 deletions src/Dsl/GeneratedCode/LanguageNameSchema.xsd
Expand Up @@ -784,6 +784,12 @@
<xsd:documentation>Defines how EF reads and write this property or its backing field. See https://docs.microsoft.com/en-us/dotnet/api/microsoft.entityframeworkcore.propertyaccessmode</xsd:documentation>
</xsd:annotation>
</xsd:attribute>
<!-- Property: ExposeAs -->
<xsd:attribute name="exposeAs" type="PropertyExposure" >
<xsd:annotation>
<xsd:documentation>How should this property be exposed in code?</xsd:documentation>
</xsd:annotation>
</xsd:attribute>
</xsd:extension>
</xsd:complexContent>
</xsd:complexType>
Expand Down Expand Up @@ -2336,5 +2342,24 @@
</xsd:restriction>
</xsd:simpleType>

<!-- Enum PropertyExposure -->
<xsd:simpleType name="PropertyExposure">
<xsd:annotation>
<xsd:documentation>How the code generator will present this property to Entity Framework (EFCore5+ only)</xsd:documentation>
</xsd:annotation>
<xsd:restriction base="xsd:string">
<xsd:enumeration value="Property">
<xsd:annotation>
<xsd:documentation>Generated code will create and use this attribute as a .NET property,</xsd:documentation>
</xsd:annotation>
</xsd:enumeration>
<xsd:enumeration value="Field">
<xsd:annotation>
<xsd:documentation>Generated code will create and use this attribute as a .NET field</xsd:documentation>
</xsd:annotation>
</xsd:enumeration>
</xsd:restriction>
</xsd:simpleType>

</xsd:schema>

30 changes: 30 additions & 0 deletions src/Dsl/GeneratedCode/Serializer.cs
Expand Up @@ -4501,6 +4501,23 @@ protected override void ReadPropertiesFromAttributes(DslModeling::SerializationC
}
}
}
// ExposeAs
if (!serializationContext.Result.Failed)
{
string attribExposeAs = EFModelSerializationHelper.Instance.ReadAttribute(serializationContext, element, reader, "exposeAs");
if (attribExposeAs != null)
{
PropertyExposure valueOfExposeAs;
if (DslModeling::SerializationUtilities.TryGetValue<PropertyExposure>(serializationContext, attribExposeAs, out valueOfExposeAs))
{
instanceOfModelAttribute.ExposeAs = valueOfExposeAs;
}
else
{ // Invalid property value, ignored.
EFModelSerializationBehaviorSerializationMessages.IgnoredPropertyValue(serializationContext, reader, "exposeAs", typeof(PropertyExposure), attribExposeAs);
}
}
}
}

/// <summary>
Expand Down Expand Up @@ -5335,6 +5352,19 @@ protected override void WritePropertiesAsAttributes(DslModeling::SerializationCo
}
}
}
// ExposeAs
if (!serializationContext.Result.Failed)
{
PropertyExposure propValue = instanceOfModelAttribute.ExposeAs;
string serializedPropValue = DslModeling::SerializationUtilities.GetString<PropertyExposure>(serializationContext, propValue);
if (!serializationContext.Result.Failed)
{
if (serializationContext.WriteOptionalPropertiesWithDefaultValue || string.CompareOrdinal(serializedPropValue, "Property") != 0)
{ // No need to write the value out if it's the same as default value.
EFModelSerializationHelper.Instance.WriteAttributeString(serializationContext, element, writer, "exposeAs", serializedPropValue);
}
}
}
}

/// <summary>
Expand Down

0 comments on commit a882a23

Please sign in to comment.