Created
January 17, 2015 19:58
-
-
Save scionwest/483fba984222c7662d17 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| public interface IMessage | |
| { | |
| T GetContent<T>() where T : class; | |
| } | |
| public abstract class MessageBase<TContentType> : IMessage where TContentType : class | |
| { | |
| TContentType Content { get; } | |
| public abstract TContentType GetContent<ContentType>(); | |
| // I want to replace this with the GetContent above | |
| public T GetContent<T>() where T : class | |
| { | |
| throw new NotImplementedException(); | |
| } | |
| } |
jakesays-old
commented
Jan 17, 2015
Author
Another potential solution.
public interface IMessage
{
object GetContent();
}
public interface ITypedMessage<TContentType> : IMessage where TContentType : class
{
TContentType Content { get; }
new TContentType GetContent();
}
public class WhisperMessage : ITypedMessage<string>
{
public string Content
{
get
{
throw new NotImplementedException();
}
}
public new string GetContent()
{
throw new NotImplementedException();
}
object IMessage.GetContent()
{
throw new NotImplementedException();
}
}
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment