Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6964573
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T15:56:31+00:00 2026-05-27T15:56:31+00:00

I am making one library which I hope so is going to be used

  • 0

I am making one library which I hope so is going to be used at many places.

In my interface I have a method which triggers events. I have cached myself that forget to subscribe to the events and get error after program has compiled. I would love to try to push users to subscribe to the events so that they get compiler errors before a program starts if there is no subscription to the events.

Is that possible at all? Or is HELP and XML comments just enough to mention a user to subscribe to an event.

My interface looks like:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Robot.SkolaCa.BusinessObjects;

namespace Robot.SkolaCa.FiskalPrinter
{
    public delegate void OnRacunSuccessEvent(object sender, OnRacunSuccessArgs eargs);
    public delegate void OnRacunErrorEvent(object sender, OnRacunErrorArgs eargs);
    public class OnRacunErrorArgs : EventArgs
    {
        public string ErrorMessage { get; set; }
    }
    public class OnRacunSuccessArgs : EventArgs
    {   
        public string SuccesMessage { get; set; }
    }

    public interface IFiskalPrinter
    {
        bool PresjekStanja();
        bool DnevniIzvjestaj();
        /// <summary>
        /// PLEASE SUBSCRIBE TO ALL EVENTS !!!!
        /// </summary>
        /// <param name="racun"></param>
        void Racun(Racun racun);
        bool StornpRacuna(Racun racun, int brojFiskalnogKojiSeStornira);
        void SetConfig(IPrinterConfig config);
        event OnRacunSuccessEvent OnRacunSuccess;
        event OnRacunErrorEvent OnRacunError;
    }
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-27T15:56:31+00:00Added an answer on May 27, 2026 at 3:56 pm

    Events by definition are facultative, i.e. if one wants, he/she subscribes, if not – then it’s his/her right. By declaring an event, you say ‘If someone is interested, I will notify him about some event’. Therefore, the whole idea of forcing subscriptions is wrong.

    But if you need to force consumers do something, you’d better declared a co-interface for your class consumers and make your methods receive interface implementations as arguments. For example:

    public interface IFiskalPrinterConsumer
    {
        void OnRacunSuccess(string successMessage);
        void OnRacunError(string errorMessage);
    }
    
    public interface IFiskalPrinter
    {
        bool PresjekStanja();
        bool DnevniIzvjestaj();
        void Racun(Racun racun, IFiskalPrinterConsumer consumer);
        bool StornpRacuna(Racun racun, int brojFiskalnogKojiSeStornira);
        void SetConfig(IPrinterConfig config);
    }
    

    This way you’ll be able to throw run-time errors if the caller passes null as consumer, and the caller won’t be able to not subscribe. This will make your contract more clear. You’re now saying ‘I’m not going to work if you won’t give me a listener object’.

    Then you might create, say, Code Analysis or FxCop rules to check that noone implements the interface with empty method implementations.

    And so on…

    But the joke is: if someone wants to break your rules, he will.

    UPDATE

    The co-interface solution might be even better, because with event you can have not only 0 subscribers, but also 1000 subscribers. How about writing XML comments saying ‘please, verify that you always have exactly one subscription’? You know, that’s quite difficult to verify.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am currently making a program in which one of its functions is to
I'm making a flash quiz which will have a series of questions. Each question
I have created one windows service which send an email notifications to users (list
I have a Class Library project which houses some shared code between other projects
I have a method which instantiates an object, some of the properties of this
I have a VisualStudio solution created in Vs2005 which is making use of Microsoft
I am writing a library of utility classes, many of which are singletons. I
I am making one application where i am reading mails from Lotus Notes. I
I ran into the situation where my class is making one asynchronous web call
Are these nested comments allowed in a XML file? <!-- Making only one observation

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.