interface

More about Virtual / new…plus interfaces!

☆樱花仙子☆ 提交于 2019-12-18 13:36:33
问题 Yesterday I posted a question about the new/virtual/override keywords, and i learned a lot from your answers. But still i remain with some doubts. In between all the "boxes", i lost touch with what's really happening to the type's method tables. For instance: interface I1 { void Draw(); } interface I2 { void Draw(); } class A : I1, I2 { public void Minstance() { Console.WriteLine("A::MInstance"); } public virtual void Draw() { Console.WriteLine("A::Draw"); } void I2.Draw() { Console.WriteLine

.NET Tools: Extract Interface and Implement Wrapper Class

◇◆丶佛笑我妖孽 提交于 2019-12-18 13:35:17
问题 Is there a tool that can generate extract and generate interfaces for existing classes? I know Visual Studio will extract an Interface for an existing class. However, I would also like to generate a wrapper class that implements that functionality. I believe this would help tremendously for unit testing. Example Existing Class: public class ThirdPartyClass { public void Method1(){} public void Method2(){} } This can be generated by Visual Studio (Extract Interface): public interface

Adding an interface to a partial class

一曲冷凌霜 提交于 2019-12-18 13:02:24
问题 I have a class that is generated by a third party tool: public partial class CloudDataContext : DbContext { // ...SNIPPED... public DbSet<User> Users { get; set; } } I create a partial class and then assign an interface so that I can inject this class later: public partial class CloudDataContext : IDataContext { } The IDataContext has the single property Users . This won't compile, the compiler complains that the interface isn't implemented. If I move the interface to the generated class, it

Can I pass an interface based object to an MVC 4 WebApi POST?

こ雲淡風輕ζ 提交于 2019-12-18 12:55:08
问题 I want to have an API as such: public class RelayController : ApiController { // POST api/values public void Post([FromBody]IDataRelayPackage package) { MessageQueue queue = new MessageQueue(".\\private$\\DataRelay"); queue.Send(package); queue.Close(); } } I'm getting a null value for 'package' so I'm wondering what might be going wrong. My only thoughts are that the default JSON serializer can't handle this, but I'm unclear how to fix it. 回答1: You can do this fairly easily with a custom

Is there any way in C# to enforce operator overloading in derived classes?

你离开我真会死。 提交于 2019-12-18 12:50:10
问题 I need to define an Interface which has to enforce certain operator overloading to the types which implements it. There doesn't seem an obvious way to do it since operator overloading has to be done using static methods in class. Is there any way to achieve the same effect (using abstract classes or anything else)? 回答1: Bit of a hack, but... You could provide operator overloads in your base class that then call some published abstract methods in one of the classes to do the job there. public

Delphi, MDI vs Tabs for multi-document interface

自闭症网瘾萝莉.ら 提交于 2019-12-18 12:34:16
问题 I'm developing a multi-document application. Currently it uses MDI which is quite convenient for me (as a developer) as well as for users I believe. However there is one "against" - I haven't found a solution to quickly load many child windows (each time the window is created and maximized to fill the parent's area, there is an 'animation' of resizing which takes a lot of time) so far, thus I'm considering switching back to tabbed interface (which requires some more work, I need to "embed" a

Example of inner classes used as an alternative to interfaces

血红的双手。 提交于 2019-12-18 12:32:47
问题 What I was told, which sparked my curiosity on this topic: Java gui classes can implement hundreds of Listeners and Callbacks and many books teach you to implement all these interfaces in your gui class. Alternatively, these aspects can be implemented in inner classes, so methods called by that listeners do not get mixed up. I'd like to know how to do this in ActionScript, which doesn't have inner classes, but has private classes. But, I don't think I fully realize what inner classes are

When using Data Annotations with MVC, Pro and Cons of using an interface vs. a MetadataType

心已入冬 提交于 2019-12-18 12:32:24
问题 If you read this article on Validation with the Data Annotation Validators, it shows that you can use the MetadataType attribute to add validation attributes to properties on partial classes. You use this when working with ORMs like LINQ to SQL, Entity Framework, or Subsonic. Then you can use the "automagic" client and server side validation. It plays very nicely with MVC. However, a colleague of mine used an interface to accomplish exactly the same result. it looks almost exactly the same,

Example of inner classes used as an alternative to interfaces

▼魔方 西西 提交于 2019-12-18 12:32:05
问题 What I was told, which sparked my curiosity on this topic: Java gui classes can implement hundreds of Listeners and Callbacks and many books teach you to implement all these interfaces in your gui class. Alternatively, these aspects can be implemented in inner classes, so methods called by that listeners do not get mixed up. I'd like to know how to do this in ActionScript, which doesn't have inner classes, but has private classes. But, I don't think I fully realize what inner classes are

Is there ever a reason to hide inherited members in an interface?

早过忘川 提交于 2019-12-18 12:28:51
问题 I understand that a class which inherits from another class may hide a property by using the new keyword. This, however, is hiding a specific implementation of the property, so I can see how it could be used. Is there any practical reason to hide members in interfaces which implement other interfaces? For example consider the example below. IChildInterface implements IParentInterface , and hides PropertyA . interface IParentInterface { string Name { get; set; } int PropertyA { get; set; } int