Click here to Skip to main content
15,905,915 members
Home / Discussions / C#
   

C#

 
GeneralRe: Forms opening other forms Pin
Member 112336118-Sep-18 0:06
Member 112336118-Sep-18 0:06 
GeneralRe: Forms opening other forms Pin
OriginalGriff8-Sep-18 0:07
mveOriginalGriff8-Sep-18 0:07 
GeneralRe: Forms opening other forms Pin
Matias Lopez11-Sep-18 8:50
Matias Lopez11-Sep-18 8:50 
QuestionC# project - SMS Alert Pin
Member 124675946-Sep-18 21:51
Member 124675946-Sep-18 21:51 
AnswerRe: C# project - SMS Alert Pin
OriginalGriff6-Sep-18 22:05
mveOriginalGriff6-Sep-18 22:05 
AnswerRe: C# project - SMS Alert Pin
DerekT-P13-Sep-18 1:01
professionalDerekT-P13-Sep-18 1:01 
QuestionCrypto in C#/4.0 using PKCS#10 and SHA256 Pin
ninodago6-Sep-18 5:28
ninodago6-Sep-18 5:28 
QuestionProblems with Rx EventMessager [Solved] Pin
Kenneth Haugland5-Sep-18 4:10
mvaKenneth Haugland5-Sep-18 4:10 
Im trying to publish a message that should communicate between classes:
public sealed class EventMessager : IEventMessager
{
    private readonly Dictionary<Type, object> subscriberLookup = new Dictionary<Type, object>();

    public IObservable<T> Observe<T>()
    {
        if (!subscriberLookup.TryGetValue(typeof(T), out object subject))
        {
            subject = new Subject<T>();
            subscriberLookup.Add(typeof(T), subject);
        }
        return ((ISubject<T>)subject).AsObservable();
    }

    public void Publish<T>(T @event)
    {
        if (subscriberLookup.TryGetValue(@event.GetType(), out object subject))
        {
            ((Subject<T>)subject).OnNext(@event);
        }
    }
}


This works well, except for the time I wanted to use Reflection in order to initate a new Message class like so:
eventMessager.Publish(Activator.CreateInstance(w[0]));


It complains that it cannot cast the subject of class type that w is as an Subject Object.
It will work as expected if I just say new MyClass instead of the activator.
I really cant find any solutions online either, so does anyone know what is going on here?

modified 6-Sep-18 2:05am.

AnswerRe: Problems with Rx EventMessager Pin
Pete O'Hanlon5-Sep-18 4:49
mvePete O'Hanlon5-Sep-18 4:49 
AnswerRe: Problems with Rx EventMessager Pin
Richard Deeming5-Sep-18 4:54
mveRichard Deeming5-Sep-18 4:54 
GeneralRe: Problems with Rx EventMessager Pin
Kenneth Haugland5-Sep-18 9:49
mvaKenneth Haugland5-Sep-18 9:49 
GeneralRe: Problems with Rx EventMessager Pin
Kenneth Haugland5-Sep-18 9:56
mvaKenneth Haugland5-Sep-18 9:56 
QuestionUnable to Access Method in Referenced .dll (C#/VS2017) Pin
Member 139418904-Sep-18 22:55
Member 139418904-Sep-18 22:55 
AnswerRe: Unable to Access Method in Referenced .dll (C#/VS2017) Pin
Richard MacCutchan4-Sep-18 23:10
mveRichard MacCutchan4-Sep-18 23:10 
GeneralRe: Unable to Access Method in Referenced .dll (C#/VS2017) Pin
Member 139418904-Sep-18 23:19
Member 139418904-Sep-18 23:19 
AnswerRe: Unable to Access Method in Referenced .dll (C#/VS2017) Pin
Member 139418905-Sep-18 0:24
Member 139418905-Sep-18 0:24 
QuestionConstructor Injection Pin
jones298474-Sep-18 7:33
jones298474-Sep-18 7:33 
AnswerRe: Constructor Injection Pin
Mc_Topaz4-Sep-18 10:15
Mc_Topaz4-Sep-18 10:15 
QuestionAforge Video-Picture quality Pin
User 136751144-Sep-18 1:08
User 136751144-Sep-18 1:08 
QuestionC# convert image format to dpx Pin
Member 135795963-Sep-18 23:28
Member 135795963-Sep-18 23:28 
AnswerRe: C# convert image format to dpx Pin
OriginalGriff4-Sep-18 1:10
mveOriginalGriff4-Sep-18 1:10 
SuggestionRe: C# convert image format to dpx Pin
Richard Deeming4-Sep-18 1:48
mveRichard Deeming4-Sep-18 1:48 
Question"Hiding" functions from StackTrace Pin
Bernhard Hiller3-Sep-18 2:37
Bernhard Hiller3-Sep-18 2:37 
AnswerRe: "Hiding" functions from StackTrace Pin
OriginalGriff3-Sep-18 4:12
mveOriginalGriff3-Sep-18 4:12 
AnswerRe: "Hiding" functions from StackTrace Pin
Gerry Schmitz4-Sep-18 4:53
mveGerry Schmitz4-Sep-18 4:53 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.