The Artima Developer Community
Sponsored Link

.NET Buzz Forum
L'uso di una marker interface generica con constructor constraint

0 replies on 1 page.

Welcome Guest
  Sign In

Go back to the topic listing  Back to Topic List Click to reply to this topic  Reply to this Topic Click to search messages in this forum  Search Forum Click for a threaded view of the topic  Threaded View   
Previous Topic   Next Topic
Flat View: This topic has 0 replies on 1 page
Adrian Florea

Posts: 206
Nickname: adrian11
Registered: Jul, 2004

Adrian Florea is a .NET developer from Italy
L'uso di una marker interface generica con constructor constraint Posted: Oct 14, 2005 9:33 AM
Reply to this message Reply

This post originated from an RSS feed registered with .NET Buzz by Adrian Florea.
Original Post: L'uso di una marker interface generica con constructor constraint
Feed Title: Web Log di Adrian Florea
Feed URL: /error.aspx?aspxerrorpath=/adrian/Rss.aspx
Feed Description: "You know you've achieved perfection in design, not when you have nothing more to add, but when you have nothing more to take away." Antoine de Saint-Exupery
Latest .NET Buzz Posts
Latest .NET Buzz Posts by Adrian Florea
Latest Posts From Web Log di Adrian Florea

Advertisement

Mi è venuta in mente questa idea e mi interesserebbe un feedback da parte vostra a riguardo.

Per obbligare una classe ad avere un costruttore default (public e senza parametri), mi sono costruito una marker interface generica con constructor constraint:

public interface IDefaultConstructor where T : new() {}

e quindi basta che la classe Foo implementi IDefaultConstructor per essere sicuri in fase di compilazione che essa abbia un costruttore default:

class Foo : IDefaultConstructor<Foo>
{
      public Foo() // garantito!
      {
            // ...
      }
 
      // altri costruttori...
      public Foo(int i)
      {
            //...
      }
 
      // il resto dei membri
}

Read: L'uso di una marker interface generica con constructor constraint

Topic: ASQF Arbeitskreis-Treffen am 12.10.2005 Previous Topic   Next Topic Topic: Hampton Roads code camp call for speakers

Sponsored Links



Google
  Web Artima.com   

Copyright © 1996-2019 Artima, Inc. All Rights Reserved. - Privacy Policy - Terms of Use