kreta/Tools/CodeGeneration/Templates/Server/DataAccess/Entity/Property.tdl
2024-03-13 00:33:46 +01:00

165 lines
5.7 KiB
Text

//***************************************************************************//
// Legenerálja egy entitás attribútumaiból a mezőket és a tulajdonságokat //
// Rendbe van téve //
//***************************************************************************//
template GenerateSimpleFields(MClass as ENTITY)
#region Egyszerű mezők
[loop (ENTITY -> MAttribute as ATTRIBUTE)]
#region [ATTRIBUTE.name]
[GenerateAttributeProperty([ENTITY], [ATTRIBUTE])]
#endregion
[end loop]
#endregion
end template
//***************************************************************************//
// Rendbe van téve //
//***************************************************************************//
template GenerateAttributeProperty(MClass as ENTITY, MAttribute as ATTRIBUTE)
[if (IsAttributeRequired([ATTRIBUTE]) == _True())]
protected internal [GetCSharpType([ATTRIBUTE.type])] m_[ATTRIBUTE.name];
[else]
protected internal [GetCSharpNullableType([ATTRIBUTE.type])] m_[ATTRIBUTE.name];
[end if]
/// <summary>
[if ([ATTRIBUTE.description] != "")]
[ConvertDescriptionToCSharpSummary([ATTRIBUTE.description])]
[else]
/// Nincs definiálva megjegyzés.
[end if]
/// </summary>
\[EntityProperty("[ATTRIBUTE.name]", EntityPropertyBaseType.ValueType, typeof([GetCSharpType([ATTRIBUTE.type])]), EntityCopyMethod.ShallowCopy)\]
[if (IsDictionaryItem([ATTRIBUTE]) == _True())]
\[EntityDictionaryItemProperty("[ATTRIBUTE.name]", "[GetDictionaryItemClass([ATTRIBUTE])]", typeof(SDA.[ProjectName].Entities.[GetDictionaryItemClass([ATTRIBUTE])]))\]
[end if]
[if (IsAttributeRequired([ATTRIBUTE]) == _True())]
public virtual [GetCSharpType([ATTRIBUTE.type])] [ATTRIBUTE.name]
[else]
public virtual [GetCSharpNullableType([ATTRIBUTE.type])] [ATTRIBUTE.name]
[end if]
{
get
{
[if ((ToLower([ATTRIBUTE.type]) == "string" || ToLower([ATTRIBUTE.type]) == "longstring") && IsTrimmed([ATTRIBUTE]) == _True())]
return m_[ATTRIBUTE.name] == null ? m_[ATTRIBUTE.name] : m_[ATTRIBUTE.name].Trim();
[else]
return m_[ATTRIBUTE.name];
[end if]
}
[if (IsComputedAttribute([ATTRIBUTE]) == _False())]
set
{
[if (IsReadonlyAttribute([ATTRIBUTE]) == _True())]
// readonly attribútum
[GenerateReadonlyAttributeSetter([ENTITY], [ATTRIBUTE])]
[else]
[GenerateAttributeSetter([ENTITY], [ATTRIBUTE])]
[end if]
}
[end if]
}
[if (IsMultiLanguage([ATTRIBUTE]) == _True())]
[if (GetLanguageIndex([ATTRIBUTE]) == "0")]
/// <summary>
/// A(z) [ATTRIBUTE.name] értéke a jelenlegi nyelven. Csak megjelenítéshez használni!
/// </summary>
public [GetCSharpType([ATTRIBUTE.type])] Get[ATTRIBUTE.name]()
{
return Get[ATTRIBUTE.name](EntityUtil.CurrentLanguageIndex);
}
private [GetCSharpType([ATTRIBUTE.type])] Get[ATTRIBUTE.name](int languageIndex)
{
switch (languageIndex)
{
case 1:
{
return (string.IsNullOrEmpty([ATTRIBUTE.name]_1) ? [ATTRIBUTE.name] : [ATTRIBUTE.name]_1);
}
case 2:
{
return (string.IsNullOrEmpty([ATTRIBUTE.name]_2) ? [ATTRIBUTE.name] : [ATTRIBUTE.name]_2);
}
case 3:
{
return (string.IsNullOrEmpty([ATTRIBUTE.name]_3) ? [ATTRIBUTE.name] : [ATTRIBUTE.name]_3);
}
case 4:
{
return (string.IsNullOrEmpty([ATTRIBUTE.name]_4) ? [ATTRIBUTE.name] : [ATTRIBUTE.name]_4);
}
default:
{
return [ATTRIBUTE.name];
}
}
}
[end if]
[end if]
end template
//***************************************************************************//
// Rendbe van téve //
//***************************************************************************//
template GenerateReadonlyAttributeSetter(MClass as ENTITY, MAttribute as ATTRIBUTE)
CheckModifyable();
if (m_[ATTRIBUTE.name] == null || this.ID <= 0)
{
[if (IsDefaultonlyAttribute([ATTRIBUTE]) == _True())]
m_[ATTRIBUTE.name] = [GetCSharpDefaultValueOfAttribute([ATTRIBUTE])];
[else]
[if ((ToLower([ATTRIBUTE.type]) == "string" || ToLower([ATTRIBUTE.type]) == "longstring") && IsTrimmed([ATTRIBUTE]) == _True())]
m_[ATTRIBUTE.name] = value == null ? value : value.Trim();
[else]
m_[ATTRIBUTE.name] = value;
[end if]
[end if]
FieldModified("[ATTRIBUTE.name]", value);
}
else
{
throw new ReadOnlyEntityAttributeException("[ENTITY.name]", "[ATTRIBUTE.name]");
}
end template
//***************************************************************************//
// Rendbe van téve //
//***************************************************************************//
template GenerateAttributeSetter(MClass as ENTITY, MAttribute as ATTRIBUTE)
CheckModifyable();
[if (IsDefaultonlyAttribute([ATTRIBUTE]) == _True())]
m_[ATTRIBUTE.name] = [GetCSharpDefaultValueOfAttribute([ATTRIBUTE])];
FieldModified("[ATTRIBUTE.name]", value);
[else]
[if (ToLower([ATTRIBUTE.type]) == "string" || ToLower([ATTRIBUTE.type]) == "binary" || ToLower([ATTRIBUTE.type]) == "longstring")]
[if ((ToLower([ATTRIBUTE.type]) == "string" || ToLower([ATTRIBUTE.type]) == "longstring") && IsTrimmed([ATTRIBUTE]) == _True())]
value = (value == null) ? value : value.Trim();
[end if]
if (m_[ATTRIBUTE.name] == value) return;
m_[ATTRIBUTE.name] = value;
FieldModified("[ATTRIBUTE.name]", value);
[else]
if (m_[ATTRIBUTE.name] == value) return;
m_[ATTRIBUTE.name] = value;
FieldModified("[ATTRIBUTE.name]", value);
[end if]
[end if]
end template