Menu
Forums
All threads
Latest threads
New posts
Trending threads
New posts
Search forums
Trending
What's new
New posts
New profile posts
Latest activity
Members
Current visitors
New profile posts
Search profile posts
Upgrades
Log in
Register
What's new
Search
Search
Search titles only
By:
All threads
Latest threads
New posts
Trending threads
New posts
Search forums
Menu
Log in
Register
Navigation
Install the app
Install
More options
Contact us
Close Menu
Forums
Server Development
Habbo Retros
Habbo Development
Starlight [C#/.NET Core/Dapper]
JavaScript is disabled. For a better experience, please enable JavaScript in your browser before proceeding.
You are using an out of date browser. It may not display this or other websites correctly.
You should upgrade or use an
alternative browser
.
Reply to thread
Message
<blockquote data-quote="TheGeneral" data-source="post: 471660" data-attributes="member: 73182"><p>Going generic in your interface doesnt mean you are required to have a parameterless constructor. Just do something like this:</p><p></p><p>[ICODE]typeof(MessageType).GetConstructor(new[] { typeof(IClientMessage)}).Invoke(new[]{message})[/ICODE]</p><p></p><p>And wherever you register your messages you can check if that type has a constructor that accepts [ICODE]IClientMessage[/ICODE]</p><p></p><p>The point of a constructor is so that the object is fully constructed and initialized, ready to be used. Having an extra function to be an hardrequirement to be called on that specific object to initialize it, is bad practice and defies the purpose of having a constructor. A better approach would be to have a static parse function that fills out the parameters values through the constructor.</p></blockquote><p></p>
[QUOTE="TheGeneral, post: 471660, member: 73182"] Going generic in your interface doesnt mean you are required to have a parameterless constructor. Just do something like this: [ICODE]typeof(MessageType).GetConstructor(new[] { typeof(IClientMessage)}).Invoke(new[]{message})[/ICODE] And wherever you register your messages you can check if that type has a constructor that accepts [ICODE]IClientMessage[/ICODE] The point of a constructor is so that the object is fully constructed and initialized, ready to be used. Having an extra function to be an hardrequirement to be called on that specific object to initialize it, is bad practice and defies the purpose of having a constructor. A better approach would be to have a static parse function that fills out the parameters values through the constructor. [/QUOTE]
Insert quotes…
Verification
Post reply
Forums
Server Development
Habbo Retros
Habbo Development
Starlight [C#/.NET Core/Dapper]
Top