{"id":17770610,"url":"https://github.com/strypper/eventhandleranddelegate","last_synced_at":"2025-03-15T14:31:01.370Z","repository":{"id":115180799,"uuid":"259003918","full_name":"Strypper/EventHandlerAndDelegate","owner":"Strypper","description":"This is a small demo to demonstrate how to use EventHandler and Delegate, for more detail see Mosh explain at https://youtu.be/jQgwEsJISy0","archived":false,"fork":false,"pushed_at":"2024-06-04T05:46:05.000Z","size":463,"stargazers_count":4,"open_issues_count":0,"forks_count":1,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-02-27T03:11:51.413Z","etag":null,"topics":["console","csharp","delegate","event-handler"],"latest_commit_sha":null,"homepage":null,"language":"C#","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/Strypper.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2020-04-26T10:38:21.000Z","updated_at":"2024-06-04T05:46:08.000Z","dependencies_parsed_at":null,"dependency_job_id":"91c3a41e-bbef-4292-a2a6-1d8efff228e8","html_url":"https://github.com/Strypper/EventHandlerAndDelegate","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Strypper%2FEventHandlerAndDelegate","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Strypper%2FEventHandlerAndDelegate/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Strypper%2FEventHandlerAndDelegate/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Strypper%2FEventHandlerAndDelegate/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Strypper","download_url":"https://codeload.github.com/Strypper/EventHandlerAndDelegate/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":243742763,"owners_count":20340698,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["console","csharp","delegate","event-handler"],"created_at":"2024-10-26T21:24:07.541Z","updated_at":"2025-03-15T14:31:01.364Z","avatar_url":"https://github.com/Strypper.png","language":"C#","readme":"# Event Handler and Delegate in C#\nFor what ? \n* Loosely couple architecture\n* Easy to test\n\n# What is in the code ?\n\tThere are 2 type of Event Handler, the one with no parameter and the one with code inside it\n# No Parameter\n\n* Create a delegate\n* Create an Event Handler based on that delegate\n* Raise the Event\n![](Demo/NoParameter.png)\n# With Parameter\n\n* Create a delegate but with a class which inheritances a custom EventArgs as second parameter\n* Create an EventHanlder base on the above Delegate\n* Require the trigger method with the parameter we need\n* Raise the Event\n![](Demo/WithParameter.png)\n# Better Way\nIn the new C# version we don't need to do this \n```cs\n         \tpublic delegate void VideoEncodedHandler(object source, VideoEventArgs args);\n        \tpublic event VideoEncodedHandler videoEncoded;\n```\nInstead just to this\n```cs\n\tpublic event EventHandler\u003cVideoEventArgs\u003e videoEncodedWithParameter;\n```\n#Execute the example\n```cs\n        static void Main(string[] args)\n        {\n            //Event with no Parameter\n\n            Video v = new Video(\"Family Guy\");\n            var VE = new VideoEncoder();\n            var SE = new SendEmail();\n            var SS = new SendSMS();\n            VE.videoEncoded += SE.OnVideoEncoded;\n            VE.videoEncoded += SS.OnVideoEncoded;\n            VE.EncodeVideo(v);\n\n\n            //Event with Parameter\n            Video v1 = new Video(\"Fuck you Peter\");\n            var VEP = new VideoEncoderWithParameter();\n            var SEP = new SendEmailWithParameter();\n            var SSP = new SendSMSWithParameter();\n            VEP.videoEncodedWithParameter += SEP.OnVideoEncoded;\n            VEP.videoEncodedWithParameter += SSP.OnVideoEncoded;\n            VEP.EncodeVideo(v1);\n        }\n```\n  \n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fstrypper%2Feventhandleranddelegate","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fstrypper%2Feventhandleranddelegate","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fstrypper%2Feventhandleranddelegate/lists"}