Skip to content
This repository was archived by the owner on Nov 23, 2022. It is now read-only.

Feature/sqllogging and reserved keyword renaming #2

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Templates/CSharpDataClasses.tt
Original file line number Diff line number Diff line change
Expand Up @@ -293,7 +293,7 @@ namespace <#=data.EntityNamespace#>
<# if (data.Serialization && ((column.MemberAttributes & MemberAttributes.AccessMask) == MemberAttributes.Public)) {
#> [DataMember(Order=<#=dataMemberIndex++#>)]
<# }
#> <#=code.Format(column.MemberAttributes)#><#=code.Format(column.Type)#> <#=column.Member#>
#> <#=code.Format(column.MemberAttributes)#><#=code.Format(column.Type)#> <#=column.CSharpMemberName#>
{
get { return <#=column.StorageValue#>; }
<# if (!column.IsReadOnly) { #>
Expand Down
30 changes: 29 additions & 1 deletion Templates/L2ST4.ttinclude
Original file line number Diff line number Diff line change
Expand Up @@ -215,7 +215,7 @@ class FunctionClass : Class
// DBML type Column > Properties on a class
class Column
{
private String member, typeName, storage;
private String member, csharpMemberName, vbMemberName, typeName, storage;

private AutoSync autoSync;
public AutoSync AutoSync {
Expand Down Expand Up @@ -260,6 +260,14 @@ class Column
get { return member + ((member == Class.Name) ? "1" : ""); }
set { member = value; }
}
public String CSharpMemberName {
get { return csharpMemberName + ((csharpMemberName == Class.Name) ? "1" : ""); }
set { csharpMemberName = value; }
}
public String VbMemberName {
get { return vbMemberName + ((vbMemberName == Class.Name) ? "1" : ""); }
set { vbMemberName = value; }
}
public MemberAttributes MemberAttributes { get; private set; }
public String Name { get; private set; }
public String Storage {
Expand All @@ -285,6 +293,8 @@ class Column
Class = class1;
Name = (String) xe.Attribute("Name") ?? "";
Member = (String) xe.Attribute("Member") ?? Name;
CSharpMemberName = Util.RenameCSharpKeywords(Member);
VbMemberName = Util.RenameVBKeywords(Member);
typeName = xe.Attribute("Type").Value;
CanBeNull = (Boolean?) xe.Attribute("CanBeNull") ?? false;
DbType = (String) xe.Attribute("DbType") ?? "";
Expand Down Expand Up @@ -891,6 +901,24 @@ public static class Util
default: return MemberAttributes.Final;
}
}

public static string RenameCSharpKeywords(string valueString)
{
string[] reserved = new[] { "abstract", "break", "char", "continue", "do", "event", "finally", "foreach", "in", "is", "new", "out", "protected", "return", "sizeof", "struct", "TRUE", "ulong", "using", "while", "as", "byte", "checked", "decimal", "double", "explicit", "fixed", "goto", "int", "lock", "null", "override", "public", "sbyte", "stackalloc", "switch", "try", "unchecked", "virtual", "base", "case", "class", "default", "else", "extern", "float", "if", "interface", "long", "object", "params", "readonly", "sealed", "static", "this", "typeof", "unsafe", "void", "bool", "catch", "const", "delegate", "enum", "FALSE", "for", "implicit", "internal", "namespace", "operator", "private", "ref", "short", "string", "throw", "uint", "ushort", "volatile" };
if (reserved.Contains(valueString))
return "@" + valueString;

return valueString;
}

public static string RenameVBKeywords(string valueString)
{
string[] reserved = new[] { "#Const", "#Else", "#ElseIf", "#End", "#If", "AddHandler", "AddressOf", "Alias", "And", "AndAlso", "As", "Boolean", "ByRef", "Byte", "ByVal", "Call", "Case", "Catch", "CBool", "CByte", "CChar", "CDate", "CDbl", "CDec", "Char", "CInt", "Class", "Class Statement", "CLng", "CObj", "Const", "Continue", "CSByte", "CShort", "CSng", "CStr", "CType", "CUInt", "CULng", "CUShort", "Date", "Decimal", "Declare", "Default", "Delegate", "Dim", "DirectCast", "Do", "Double", "Each", "Else", "ElseIf", "End <keyword>", "End Statement", "EndIf", "Enum", "Erase", "Error", "Event", "Exit", "Finally", "For (in For…Next)", "For Each…Next", "Friend", "Function", "Get", "GetType", "GetXMLNamespace", "Global", "GoSub", "GoTo", "Handles", "If", "If()", "Implements", "Implements Statement", "Imports (.NET Namespace and Type)", "Imports (XML Namespace)", "In", "In (Generic Modifier)", "Inherits", "Integer", "Interface", "Is", "IsNot", "Let", "Lib", "Like", "Long", "Loop", "Me", "Mod", "Module", "Module Statement", "MustInherit", "MustOverride", "MyBase", "MyClass", "NameOf", "Namespace", "Narrowing", "New Constraint", "New Operator", "Next", "Next (in Resume)", "Not", "Nothing", "NotInheritable", "NotOverridable", "Object", "Of", "On", "Operator", "Option", "Optional", "Or", "OrElse", "Out (Generic Modifier)", "Overloads", "Overridable", "Overrides", "ParamArray", "Partial", "Private", "Property", "Protected", "Public", "RaiseEvent", "ReadOnly", "ReDim", "REM", "RemoveHandler", "Resume", "Return", "SByte", "Select", "Set", "Shadows", "Shared", "Short", "Single", "Static", "Step", "Stop", "String", "Structure Constraint", "Structure Statement", "Sub", "SyncLock", "Then", "Throw", "To", "Try", "TryCast", "TypeOf…Is", "UInteger", "ULong", "UShort", "Using", "Variant", "Wend", "When", "While", "Widening", "With", "WithEvents", "WriteOnly", "Xor", "FALSE", "TRUE" };
if (reserved.Contains(valueString))
return "[" + valueString + "]";

return valueString;
}
}

class TypeStub : System.Reflection.TypeDelegator
Expand Down
17 changes: 11 additions & 6 deletions Templates/VBNetDataClasses.tt
Original file line number Diff line number Diff line change
Expand Up @@ -70,30 +70,35 @@ Namespace <#=data.ContextNamespace#>

#Region "Construction"
<#if (data.ConnectSettingsObject != null) {#>
Public Sub New()
Public Sub New(ByVal Optional logger as IO.TextWriter = Nothing)
MyBase.New(Global.<#=data.ConnectSettingsObject#>.Default.<#=data.ConnectSettingsProperty#>, mappingSource)
OnCreated
Log = logger
End Sub
<#}#>

Public Sub New(ByVal connection As String)
Public Sub New(ByVal connection As String, ByVal Optional logger as IO.TextWriter = Nothing)
MyBase.New(connection, mappingSource)
OnCreated
Log = logger
End Sub

Public Sub New(ByVal connection As System.Data.IDbConnection)
Public Sub New(ByVal connection As System.Data.IDbConnection, ByVal Optional logger as IO.TextWriter = Nothing)
MyBase.New(connection, mappingSource)
OnCreated
Log = logger
End Sub

Public Sub New(ByVal connection As String, ByVal mappingSource As MappingSource)
Public Sub New(ByVal connection As String, ByVal mappingSource As MappingSource, ByVal Optional logger as IO.TextWriter = Nothing)
MyBase.New(connection, mappingSource)
OnCreated
Log = logger
End Sub

Public Sub New(ByVal connection As System.Data.IDbConnection, ByVal mappingSource As MappingSource)
Public Sub New(ByVal connection As System.Data.IDbConnection, ByVal mappingSource As MappingSource, ByVal Optional logger as IO.TextWriter = Nothing)
MyBase.New(connection, mappingSource)
OnCreated
Log = logger
End Sub

#End Region
Expand Down Expand Up @@ -315,7 +320,7 @@ Namespace <#=data.EntityNamespace#>
<# if (data.Serialization && ((column.MemberAttributes & MemberAttributes.AccessMask) == MemberAttributes.Public)) {
#> <DataMember(Order:=<#=dataMemberIndex++#>)> _
<# }
#> <#=code.Format(column.MemberAttributes)#><# if (column.IsReadOnly) {#>ReadOnly <#}#>Property <#=column.Member#> As <#=code.Format(column.Type)#>
#> <#=code.Format(column.MemberAttributes)#><# if (column.IsReadOnly) {#>ReadOnly <#}#>Property <#=column.VbMemberName#> As <#=code.Format(column.Type)#>
Get
Return <#=column.StorageValue#>
End Get
Expand Down