internal List<CodeMemberMethod> createEventHooks()
{
string[] eventNames = new string[] { "OnUpdate", "OnInsert", "OnDelete", "OnSelect", "OnSelectAll" };
List<CodeMemberMethod> eventHooks = new List<CodeMemberMethod>();
foreach (string eventName in eventNames)
{
CodeMemberMethod eventHook = new CodeMemberMethod();
eventHook.Name = eventName;
eventHook.Attributes = MemberAttributes.ScopeMask;
eventHook.ReturnType = new CodeTypeReference("partial void");
}
return eventHooks;
}
is producing the following code:
partial void OnUpdate() {
}
partial void OnInsert() {
}
partial void OnDelete() {
}
partial void OnSelect() {
}
partial void OnSelectAll() {
}
How can I get CodeDom to drop the "{}
", which will resolve the compiler error I'm getting trying to compile? I thought of just using a CodeSnippetStatement
(which I would rather not do, since this defeats the purpose of using CodeDom in the first place), but I can't find a place in the CodeTypeDeclaration
class to add snippets.
So: I need to either
OK, here's what I did:
internal List<CodeMemberField> createEventHooks()
{
string[] eventNames = new string[] { "OnUpdate()", "OnInsert()", "OnDelete()", "OnSelect()", "OnSelectAll()" };
List<CodeMemberField> eventHooks = new List<CodeMemberField>();
foreach (string eventName in eventNames)
{
CodeMemberField eventHook = new CodeMemberField(); //do it as a FIELD instead of a METHOD
eventHook.Name = eventName;
eventHook.Attributes = MemberAttributes.ScopeMask;
eventHook.Type = new CodeTypeReference("partial void");
eventHooks.Add(eventHook);
}
return eventHooks;
}
Basically, I changed my methods to fields and included the ()
s in the "field" names. Still a hack but beats search/replacing the generated code (barely).
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With