kreta/Tools/CodeGeneration/Templates/Common/CSharpUtil.tdl
2024-03-13 00:33:46 +01:00

176 lines
No EOL
7.1 KiB
Text
Raw Permalink Blame History

This file contains invisible Unicode characters

This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

//***************************************************************************//
// Nevet konvertál C# osztály névre. //
//***************************************************************************//
proc ConvertNameToCSharpClassName(name)
return [name];
end proc
//***************************************************************************//
// C# kommentet gyárt egy sztringből. //
//***************************************************************************//
template ConvertDescriptionToCSharpSummary(description)
[if ([description] == "")]
[else]
/// [replace([description], "", "\n /// ")]
[end if]
end template
//***************************************************************************//
// Visszaadja egy művelet visszatérési értékét a C# nyelv szintaktikájának //
// megfelelően //
//***************************************************************************//
proc GetCSharpReturnTypeOfOperation(MOperation)
if ([MOperation.returnType] == "")
return "void";
else
return GetCSharpType([MOperation.returnType]);
end if
end proc
//***************************************************************************//
// Visszaadja egy művelet paraméterlistáját a C# nyelv szintaktikájának és //
// a saját jelölésbeli konvencióinknak megfelelően //
//***************************************************************************//
proc GetCSharpOperationParameters(MOperation)
local ops;
[ops] = "";
loop (MOperation -> OpPara; setDelim(""); setDelim(", "))
[ops] = [ops] delim() GetCSharpType([OpPara.type]) " " ToLower([OpPara.name]);
end loop
return [ops];
end proc
proc GetCSharpTypeOfAttribute(MAttribute)
return GetCSharpType([MAttribute.type]);
end proc
//***************************************************************************//
// Visszadja a megadott típushoz tartozó C# tipust //
//***************************************************************************//
proc GetCSharpType(type)
switch(ToLower([type]))
case "string": return "string";
case "integer": return "int";
case "datetime": return "DateTime";
case "boolean": return "bool";
case "dictionaryitem": return "int /* DictionaryItem */"; //XXX
case "binary": return "Byte[]";
case "float": return "double";
case "char": return "string";
case "longstring": return "string";
case "id": return "int";
case "guid": return "Guid";
end switch
//return "object /* ERROR Ismeretlen tipus: " [type] " */";
return [type];
end proc
//***************************************************************************//
// Visszaadja a megadott típus alapértelmezett (kezdeti) értékét a C# nyelv //
// szintaktikájának megfelelően //
//***************************************************************************//
proc GetCSharpDefaultValueOfType(type)
switch(ToLower([type]))
case "string": return "\"\"";
case "integer": return "-1";
case "datetime": return "DateTime.Now /* XXX DateTime */";//XXX
case "boolean": return "false";
case "dictionaryitem": return "-1 /* DictionaryItem */"; //XXX
case "binary": return "null";
case "float": return "0";
case "char": return "\"\"";
case "longstring": return "\"\"";
case "id": return "-1";
case "guid": return "default(Guid)";
end switch
return "null /* ERROR Ismeretlen tipus: " [type] " */";
end proc
//***************************************************************************//
// Visszaadja hogy DictionaryItem tipusu-e az adott attributum //
// //
//***************************************************************************//
proc IsDictionaryItem(MAttribute)
if (ToLower([MAttribute.type]) == "dictionaryitem")
return _True();
else
return _False();
end if
end proc
//***************************************************************************//
// Visszaadja az adott DictionaryItem konkrét osztályának a nevét //
// //
//***************************************************************************//
proc GetDictionaryItemClass(MAttribute)
return [MAttribute.defaultValue];
end proc
//***************************************************************************//
// Visszaadja a megadott attribútum alapértelmezett (kezdeti) értékét a C# //
// nyelv szintaktikájának megfelelően //
//***************************************************************************//
proc GetCSharpDefaultValueOfAttribute(MAttribute)
if (IsAttributeRequired([MAttribute]) == _True())
else
return "null";
end if
if ([MAttribute.type] == "DictionaryItem")
return GetCSharpDefaultValueOfType("ID");
end if
if ([MAttribute.type] == "Char")
//info = [MAttribute.defaultValue]; // teszt
end if
local result;
[result] = [MAttribute.defaultValue];
if ([result] == "")
[result] = GetCSharpDefaultValueOfType([MAttribute.type]);
else
switch (ToLower([MAttribute.type]))
case "string": return "\"" [result] "\"";
case "boolean": return ToLower([result]);
case "longstring": return "\"" [result] "\"";
case "char": //return "'" [result] "'";
return "\"" [result] "\"";
end switch
if (ToLower([MAttribute.type]) == "guid")
if ([result] == "NEWID")
return "Guid.NewGuid()";
else
return "Guid.Parse(\"" [result] "\")";
end if
end if
end if
return [result];
end proc
//***************************************************************************//
// Visszadja a megadott típushoz tartozó C# nullabletipust //
//***************************************************************************//
proc GetCSharpNullableType(type)
switch(ToLower([type]))
case "string": return "string";
case "integer": return "int?";
case "datetime": return "DateTime?";
case "boolean": return "bool?";
case "dictionaryitem": return "int? /* DictionaryItem */"; //XXX
case "binary": return "Byte[]";
case "float": return "double?";
case "char": return "string";
case "longstring": return "string";
case "id": return "int?";
case "guid": return "Guid?";
end switch
//return "object /* ERROR Ismeretlen tipus: " [type] " */";
return [type];
end proc