Generic interface constraints?

You can make that constraint shorter if you use C# 4 or above and declare both type parameters of INetworkSite as covariant, which will make your interfaces look like this.

Up vote 2 down vote favorite share g+ share fb share tw.

Since having something like this: internal sealed class Question : IQuestion Makes very little sense to me compared to internal sealed class Question : IQuestion Update @Jared Sure, this would be it. /// /// Represents a question on one of the Stack Exchange sites. /// api.stackexchange.com/docs/types/question /// /// The concrete type of .

/// /// The concrete type of . /// The concrete type of . /// The concrete type of .

/// The concrete type of . /// The concrete type of . /// The concrete type of .

Public interface IQuestion : IShallowPost where TShallowUser : IShallowUser where TComment : IComment where TSite : INetworkSite where TStyling : INetworkSiteStyling where TRelation : INetworkSiteRelation where TMigrationInfo : IMigrationInfo where TAnswer : IAnswer { /// /// The id of this question. /// JsonProperty("question_id") long? QuestionId { get; set; } /// /// The date this question was locked.

/// JsonConverter(typeof(UnixDateTimeConverter)) JsonProperty("locked_date") DateTime? LockedDate { get; set; } /// /// The date this question was marked as community wiki. /// JsonConverter(typeof(UnixDateTimeConverter)) JsonProperty("community_owned_date") DateTime?

CommunityOwnedDate { get; set; } /// /// The amount of answers posted in response to this question. /// JsonProperty("answer_count") long? AnswerCount { get; set; } /// /// The id of the accepted answer, if any.

/// JsonProperty("accepted_answer_id") long? AcceptedAnswerId { get; set; } /// /// Migration info telling where this question was migrated to. /// JsonProperty("migrated_to") TMigrationInfo MigratedTo { get; set; } /// /// Migration info telling where this question was migrated from.

/// JsonProperty("migrated_from") TMigrationInfo MigratedFrom { get; set; } /// /// Date when the active bounty on this question ends. /// JsonConverter(typeof(UnixDateTimeConverter)) JsonProperty("bounty_closes_date") DateTime? BountyClosesDate { get; set; } /// /// The amount of reputation spent on the bounty.

/// JsonProperty("bounty_amount ") long? BountyAmount { get; set; } /// /// The date this question was closed. /// JsonConverter(typeof(UnixDateTimeConverter)) JsonProperty("closed_date") DateTime?

ClosedDate { get; set; } /// /// The date this question was marked as protected. /// JsonConverter(typeof(UnixDateTimeConverter)) JsonProperty("protected_date") DateTime? ProtectedDate { get; set; } /// /// The title of this question.

/// JsonProperty("title") string Title { get; set; } /// /// A list of tags applied on this question. /// JsonProperty("tags") IList Tags { get; set; } /// /// The reason this post was closed. /// JsonProperty("closed_reason") string ClosedReason { get; set; } /// /// The amount of users who favorited this question.

/// JsonProperty("favorite_count") long? FavoriteCount { get; set; } /// /// The amount of views this question had. /// JsonProperty("view_count") long?

ViewCount { get; set; } /// /// A list of answers posted on this question. /// JsonProperty("answers") IList Answers { get; set; } /// /// A link to the question. /// JsonProperty("link") string Link { get; set; } /// /// A boolean indicating whether this question is answered or considered unanswered.

/// JsonProperty("is_answered") bool? IsAnswered { get; set; } } I need the concrete types instead of the interfaces because of Json deserialization, but I really hate having to pass around those huge generic type lists. It's fugly.

C# generics interface link|improve this question edited Jan 7 at 15:29 asked Jan 7 at 15:14Nico4,2241333 97% accept rate.

C# - its tagged. – Ritch Melton Jan 7 at 15:23 Can you give is some more details about IQuestion (more of it's interface)? – JaredPar Jan 7 at 15:26 @JaredPar updated with the actual interface's code.

@Cody, I'm sorry, I forgot to tag C#. – Nico Jan 7 at 15:31.

You can make that constraint shorter if you use C# 4 or above and declare both type parameters of INetworkSite as covariant, which will make your interfaces look like this: public interface IQuestion : IShallowPost where TSite : INetworkSite { // interface members } public interface INetworkSite // these constraints are not actually needed for the example to work, // but they seemed logical, so I left them in where TStyling : INetworkSiteStyling where TRelation : INetworkSiteRelation { // interface members } however, if INetworkSite requires any kind of input of the given types (method parameters, ref parameters, settable properties), this will not work, thus forcing you to leave the constraint as it is. It is, of course, possible to define only one type parameter as covariant, allowing only that one to be left out of the constraint.

1 you beat me to it ;-) – Adam Ralph Jan 7 at 15:56.

I cant really gove you an answer,but what I can give you is a way to a solution, that is you have to find the anglde that you relate to or peaks your interest. A good paper is one that people get drawn into because it reaches them ln some way.As for me WW11 to me, I think of the holocaust and the effect it had on the survivors, their families and those who stood by and did nothing until it was too late.

Related Questions