interface

IsAssignableFrom or AS?

穿精又带淫゛_ 提交于 2019-12-22 07:53:40
问题 I have next code: private T CreateInstance<T>(object obj) // where T : ISomeInterface, class { ... if (!typeof(T).IsAssignableFrom(obj.GetType())) { throw ..; } return (T)obj; } Can it be replaced with this: T result = obj as T; if (result == null) { throw ..; } return result; If not - why? 回答1: Another variant: private T CreateInstance<T>(object obj) where T : ISomeInterface // as OP mentioned above { ... T result = obj as T; if (result == null) { throw ..; } else return result; } 回答2: What

Error that I must implement a function in a class even though function is defined [duplicate]

≡放荡痞女 提交于 2019-12-22 07:25:14
问题 This question already has answers here : Class 'QueryParameterComparer' must implement Function Compare. (2 answers) Closed 4 years ago . I get the error: Class 'QueryParameterComparer' must implement 'Function Compare(x As QueryParameter, y As QueryParameter) As Integer' for interface 'System.Collections.Generic.IComparer(Of QueryParameter)'. On this class definition: Protected Class QueryParameterComparer Implements IComparer(Of QueryParameter) Public Function Compare(x As QueryParameter, y

Interfaces and Headers

人盡茶涼 提交于 2019-12-22 07:13:30
问题 Today I ran across the concept of a C# Interface, I have one hopefully simple question to see if I understand them... Are they fairly similar to a C++ header file? I mean, from what I'm getting, you define the backbone of a class without actually defining what it does, that's kind of similar to a header, correct? I read the entire MSDN definition and it doesn't really make it 100% clear to me. I believe I have the idea (wrote and attached a very elementary program to see if I understood) but

Best way to use a C++ Interface

余生长醉 提交于 2019-12-22 06:09:09
问题 I have an interface class similar to: class IInterface { public: virtual ~IInterface() {} virtual methodA() = 0; virtual methodB() = 0; }; I then implement the interface: class AImplementation : public IInterface { // etc... implementation here } When I use the interface in an application is it better to create an instance of the concrete class AImplementation. Eg. int main() { AImplementation* ai = new AIImplementation(); } Or is it better to put a factory "create" member function in the

How to inject dependencies into classes that implement an interface?

混江龙づ霸主 提交于 2019-12-22 05:51:53
问题 I know interfaces cannot define constructors. What is the best practice to force all classes implementing an interface, to receive their dependencies in a uniform contract. I know ints possible to inject dependencies into objects via properties, but passing them via constructors makes more sense to me. How to DI then ? 回答1: I know you said you want to have a stable contract. But an advantage to not supplying a stable interface is that your dependencies could then vary wildly with different

Difference between DataSource and DataSet

拈花ヽ惹草 提交于 2019-12-22 05:28:23
问题 I am currently working on project whose main task is to read data stored in SQL database and to display them in user-friendly form. Programming language used is C++. I am working in Borland C++ Builder 6 environment. But I think question posed in title is independent from programming language or libraries. When reading data from db i am quite frequently meeting with these terms in class names without knowing exactly what they represent. I understand that they behave as interface to data

Android why Fragments should not directly communicate with each other?

孤者浪人 提交于 2019-12-22 05:25:23
问题 I have an Activity A hosting two main Fragment F1 and F2 . Both F1 and F2 have nested Fragment , each with its own Listener interface for exchanging data. From what I understood from the answer to this question, the activity A : needs to know every single interface declared by the fragments hosted by F1 and F2 needs to route the events generated by the fragments in F1 and F2 to the correct main fragment, F1 or F2 . If I understood correctly, there is no modularity in this approach: the

Extending typescript interface

此生再无相见时 提交于 2019-12-22 05:23:25
问题 When extending the Express.Request interface in TypeScript I ran into this problem that I want to use an external library definition, but I can't import the external library as it results in error -> Error:(4, 28) TS1147: Import declarations in an internal module cannot reference an external module. Edit: It is a .d.ts file /// <reference path="../typings/express/express.d.ts" /> declare module Express { import bunyan = require('bunyan'); <-- results in error export interface Request { _id:

Android proguard Javascript Interface problem

旧时模样 提交于 2019-12-22 05:19:27
问题 My project after obfuscation with proguard fail with javascriptinterface Here is the link with some suggestions for proguard configuration but it dosn't work in my case http://groups.google.com/group/android-developers/browse_thread/thread/f889e846fbf7ec3f?pli=1 So the calls from Javascript loose binding to the associated Java methods My proguard configuration regarding that -keep public class com.trans_code.android.JavascriptCallback -keep public class * implements com.trans_code.android

Indexer as part of the interface in C#

大憨熊 提交于 2019-12-22 05:06:30
问题 In C#, what's the syntax for declaring an indexer as part of an interface? Is it still this[ ] ? Something feels odd about using the this keyword in an interface. 回答1: public interface IYourList<T> { T this[int index] { get; set; } } 回答2: It is - it's pretty odd syntax at other times if you ask me! But it works. You have to declare the get; and/or set; parts of it with no definition, just a semi-colon, exactly like ordinary properties in an interface. 回答3: I know what you mean but, yes, this