Как я могу объединить вложения обработчиков событий универсального типа?

Я думаю, что сервер не готов, потому что вы написали: require{'express'} вместо require('express').

const express = require('express'); // Here
var favicon = require('serve-favicon')
const app = express();
const path = require('path');

app.use(express.static(__dirname + '/dist'));
// app.use(favicon(__dirname + '/dist/favicon.ico'));
app.use(favicon(__dirname + '/dist/favicon.ico'));
// app.use(favicon(path.join(__dirname,'dist','favicon.ico')));


app.listen(process.env.PORT || 8080);

//path location strategy
app.get('/*',function(req,res) {
    res.sendFile(path.join(__dirname + '/dist/index.html'));
})

console.log('console listeing!');
0
задан user4134476 19 January 2019 в 15:22
поделиться

1 ответ

Одним из способов решения этой проблемы является создание класса животных:

public interface IAnimal
{
    int LegCount { get; }
}

public abstract class Animal: IAnimal
{
     public virtual int LegCount {get{return 4;}}   

     public event EventHandler<AnimalRequiredEventArgs<Animal>> AnimalRequired;

     protected virtual void OnAnimalRequired(AnimalRequiredEventArgs e)
        {
            // Make a temporary copy of the event to avoid possibility of
            // a race condition if the last subscriber unsubscribes
            // immediately after the null check and before the event is raised.
            EventHandler<AnimalRequiredEventArgs<Animal>> handler = AnimalRequired;
            if (handler != null)
            {
                handler(this, e);
            }
        }
}

public class Dog : Animal
{
    public override int LegCount { get { return 4; } }
}

public class Octopus : IAnimal
{
    public override int LegCount { get { return 8; } }
}

Затем вы можете переопределить OnAnimalRequired в каждом производном классе, если хотите.

Для клиентов будет одно событие, представленное абстрактным базовым классом.

Надеюсь, это поможет.

0
ответ дан Manoj Choudhari 19 January 2019 в 15:22
поделиться
Другие вопросы по тегам:

Похожие вопросы: