[Mono-dev] Constructor implementation obligation via interface?

2006-05-24 Thread Ympostor

I have a question about C# 2.0:

If I want the compiler to show an error if a class A does not implement 
the function void B(), I can make an interface that contains this method 
and make class A inherit from that interface.


But, how can I do it if I want the compiler to show an error if class A 
doesn't have an empty constructor. Can this be controlled statically?


Thanks in advance.

--

___
Mono-devel-list mailing list
Mono-devel-list@lists.ximian.com
http://lists.ximian.com/mailman/listinfo/mono-devel-list


Re: [Mono-dev] Constructor implementation obligation via interface?

2006-05-24 Thread Martin Hinks

You can't force a constructor via an interface...

Write an abstract class with the constructor definition that you want,
specify that the interface inherits the abstract class and then make
your class implement the interface.

Think that's right, might be a better way...

On 5/24/06, Ympostor [EMAIL PROTECTED] wrote:

I have a question about C# 2.0:

If I want the compiler to show an error if a class A does not implement
the function void B(), I can make an interface that contains this method
and make class A inherit from that interface.

But, how can I do it if I want the compiler to show an error if class A
doesn't have an empty constructor. Can this be controlled statically?

Thanks in advance.

--

___
Mono-devel-list mailing list
Mono-devel-list@lists.ximian.com
http://lists.ximian.com/mailman/listinfo/mono-devel-list




--
Martin Hinks
http://www.m-s-d.net
___
Mono-devel-list mailing list
Mono-devel-list@lists.ximian.com
http://lists.ximian.com/mailman/listinfo/mono-devel-list


Re: [Mono-dev] Constructor implementation obligation via interface?

2006-05-24 Thread Kamil Skalski

There is a slight problem. In C# empty constructors are added
automatically, so you can't define a class without empty constructor.
What you can do is to define a class with private empty constructor,
which will prevent user from instanciating it directly. I guess there
is not way to forbid this.

2006/5/24, Ympostor [EMAIL PROTECTED]:

I have a question about C# 2.0:

If I want the compiler to show an error if a class A does not implement
the function void B(), I can make an interface that contains this method
and make class A inherit from that interface.

But, how can I do it if I want the compiler to show an error if class A
doesn't have an empty constructor. Can this be controlled statically?

Thanks in advance.

--

___
Mono-devel-list mailing list
Mono-devel-list@lists.ximian.com
http://lists.ximian.com/mailman/listinfo/mono-devel-list




--
Kamil Skalski
http://nazgul.omega.pl
___
Mono-devel-list mailing list
Mono-devel-list@lists.ximian.com
http://lists.ximian.com/mailman/listinfo/mono-devel-list


Re: [Mono-dev] Constructor implementation obligation via interface?

2006-05-24 Thread Martin Hinks

so you can't define a class without empty constructor.

Well, in an abstract class you could tag the empty constructor
mustoverride so that all derivative classes must explicitly override
the emtpy constructor...

Martin

On 5/24/06, Kamil Skalski [EMAIL PROTECTED] wrote:

There is a slight problem. In C# empty constructors are added
automatically, so you can't define a class without empty constructor.
What you can do is to define a class with private empty constructor,
which will prevent user from instanciating it directly. I guess there
is not way to forbid this.

2006/5/24, Ympostor [EMAIL PROTECTED]:
 I have a question about C# 2.0:

 If I want the compiler to show an error if a class A does not implement
 the function void B(), I can make an interface that contains this method
 and make class A inherit from that interface.

 But, how can I do it if I want the compiler to show an error if class A
 doesn't have an empty constructor. Can this be controlled statically?

 Thanks in advance.

 --

 ___
 Mono-devel-list mailing list
 Mono-devel-list@lists.ximian.com
 http://lists.ximian.com/mailman/listinfo/mono-devel-list



--
Kamil Skalski
http://nazgul.omega.pl
___
Mono-devel-list mailing list
Mono-devel-list@lists.ximian.com
http://lists.ximian.com/mailman/listinfo/mono-devel-list




--
Martin Hinks
http://www.m-s-d.net
___
Mono-devel-list mailing list
Mono-devel-list@lists.ximian.com
http://lists.ximian.com/mailman/listinfo/mono-devel-list