Is there a way to produce a partial method with CodeDom?
Ex. partial void MyMethod() { ... }
It looks like the MemberAttributes doesn't have "Partial" in it :(
CodeMemberMethod codeMemberMethod =
new CodeMemberMethod();
codeMemberMethod.Attributes = MemberAttributes.Public...but no MemberAttributes.Partial?
What's a partial method? If you're refferring to partial classes that just a compiler convenience to split the source of one class across several source files.
Svante
AxCrypt - Free Open Source File Encryption & Online Password Manager - http://www.axantum.com [Disclaimer: Code snippets usually uncompiled, beware typos.]
______
Don't forget to click "Mark as Answer" on the post(s) that helped you.
I wasn't aware of partial methods, thanks for that.
But it's still a compiler trick to combine source from several files to produce the final class if I understand it correctly. It's not a member attribute, as such. There's no representation in a CodeDom for a partial class or method I think.
The partial modifier works more like #pragma than a real modifier as far as I see it, i.e. it's a source code level compile time feature. I'm fairly sure the compiler must have access to all parts of the source code during the compile, and it's only after
this that it generates code in a CodeDom. Exactly how the compiler does this is beyond my actual knowledge, but a guess is that this occurs after the lexical parsing of the source code, but before generating code.
Perhaps someone else really knows, I don't usually answer when I don't know, but this was kind of interesting...
Svante
AxCrypt - Free Open Source File Encryption & Online Password Manager - http://www.axantum.com [Disclaimer: Code snippets usually uncompiled, beware typos.]
______
Don't forget to click "Mark as Answer" on the post(s) that helped you.
loring
0 Points
3 Posts
CodeDom and partial method
Sep 26, 2008 04:21 PM|LINK
Hi,
Is there a way to produce a partial method with CodeDom?
Ex. partial void MyMethod() { ... }
It looks like the MemberAttributes doesn't have "Partial" in it :( CodeMemberMethod codeMemberMethod = new CodeMemberMethod(); codeMemberMethod.Attributes = MemberAttributes.Public...but no MemberAttributes.Partial?Thanks
Svante
All-Star
18347 Points
2300 Posts
Re: CodeDom and partial method
Sep 26, 2008 05:41 PM|LINK
What's a partial method? If you're refferring to partial classes that just a compiler convenience to split the source of one class across several source files.
AxCrypt - Free Open Source File Encryption & Online Password Manager - http://www.axantum.com
[Disclaimer: Code snippets usually uncompiled, beware typos.]
______
Don't forget to click "Mark as Answer" on the post(s) that helped you.
loring
0 Points
3 Posts
Re: CodeDom and partial method
Sep 26, 2008 05:50 PM|LINK
Hi,
Partial Classes and Methods
http://msdn.microsoft.com/en-us/library/wa80x488.aspx
My problem is that I'm generating some code to implement partial method.
I have this class (created "by hand"):
public partial class MyClass
{
partial void MyMethod();
partial void MyMethodB();
}
Then with CodeDom, I want to generate the implementation of those partial method. Something like:
public partial class MyClass
{
partial void MyMethod()
{
// Do Something
}
partial void MyMethodB()
{
// Do Something
}
}
That's why I need the "Partial" in System.CodeDom.MemberAttributes.
May be I'm all wrong...it's something else the MemberAttributes that I should use to do this?
Thank
Svante
All-Star
18347 Points
2300 Posts
Re: CodeDom and partial method
Sep 26, 2008 06:10 PM|LINK
I wasn't aware of partial methods, thanks for that.
But it's still a compiler trick to combine source from several files to produce the final class if I understand it correctly. It's not a member attribute, as such. There's no representation in a CodeDom for a partial class or method I think.
The partial modifier works more like #pragma than a real modifier as far as I see it, i.e. it's a source code level compile time feature. I'm fairly sure the compiler must have access to all parts of the source code during the compile, and it's only after this that it generates code in a CodeDom. Exactly how the compiler does this is beyond my actual knowledge, but a guess is that this occurs after the lexical parsing of the source code, but before generating code.
Perhaps someone else really knows, I don't usually answer when I don't know, but this was kind of interesting...
AxCrypt - Free Open Source File Encryption & Online Password Manager - http://www.axantum.com
[Disclaimer: Code snippets usually uncompiled, beware typos.]
______
Don't forget to click "Mark as Answer" on the post(s) that helped you.
loring
0 Points
3 Posts
Re: CodeDom and partial method
Sep 26, 2008 08:45 PM|LINK
CodeSnippetTypeMember literalMember =
new CodeSnippetTypeMember("public partial void MyMethod()");
Thanks