Extracting an interface from .NEt System classes - visual-studio

When using Visual Studio it is easy to extract an interface from a class that I have written myself. I right click on the class and select 'Refactor' then select 'Extract Interface'.
Let's assume for a second that I wanted to create a ConfigurationManager wrapper and write some tests around it. A quick way to do that would be to extract an interface from ConfigurationManager by right clicking it, then 'Go To Definition' and then from inside the class select 'Refactor' then select 'Extract Interface'. Then I would simply create my wrapper class, inherit from my newly created interface, and then implement it and I have a great starting point for my wrapper class.
However, extracting an interface from any .NET system classes is not possible, probably because it's just meta data about the classes and not the classes themselves (or I am doing it wrong).
Is there an easy way to do what I am trying to accomplish? I want to ensure I am not wasting time typing what I don't need to be typing.
Thanks

The problem is not so much to extract the interface - you could also do this 'by hand'
But you have no way to tell the CLR that the System-defined Configuration manager implements this interface since this (meta-)information is stored in the framework assembly which you cannot modify.
EDIT:
To ease the 'extraction by hand' you can click with the right button on the type and select "Go to Definition". Visual Studio creates a class definition (without implementation) from the metadata. You can then use copy and paste into a new file. Anyway you'll still have to do some modifications by hand
Replace the class keyword by interface
remove all non-public methods/properties
remove the public and override access modifiers (they are invalid in an interface definition)
This can be done easily using search&replace. You'll even get the documentation strings with this approach.

Related

Xcode, see where a method is used

I have a method in some class and i would like to see exactly where it is being used. Compared to Java and Eclipse you can simply tell it to show all the references and even a call hierarchy of a method. Is there anything similar in Xcode?
I know that Objective-C does not follow the same ways of identifying method signature as Java does (i.e. there is no method to a class, just a bunch of selectors mapped to an id at runtime), so i'm having a hard time trying to figure out how Xcode could even accomplish this.
Look here:
There is no equivalent menu or context menu.
In addition to callers you can access callees, superclasses, etc.
If you don't use Ctrl-1 for Spaces you can access that menu with it.
Note that you need to use the Standard or Assistant Editor:
Callers and callees are not shown if the Version Editor is selected:
Your best bet is likely string searching, but realize that you can use patterns (click the little magnifying glass in the search bar in the file browser pane).
You've hinted at one of the reasons it's so hard to do otherwise. Objective-C's runtime allows many different ways of finding and executing code.

Embed OLE Object in Wordpad

IS there any way to embed an OLE object in the Wordpad application using some kind of scripting, say vb script.
Using native application we can do it through Insert->Object and then select any object that needs to be embedded. I need to do it through vbscript like we can do it in Excel/Word/Powerpoint.
Please let me know.
Thanks.
Wordpad does expose an interface that can be instantiated using the ProgID "Wordpad.Document.1" as seen below. However, it doesn't appear to have a type library associated with it (there's nothing to see in an object browser) and there is no documentation of any publicly accessible methods or properties. It would seem to me that this was never intended to be used as a scriptable interface despite the fact that the following code will execute without error.
Set objWordpadDocument = CreateObject("Wordpad.Document.1")

visual studio app settings USAGE

I am not sure how to use Application Setting with custom user types.
For example, in a time tracking system, I would like to have an application setting (with application scope) that says how many hours a day an employee must account for. There is a custom user type, TimeQuantity, with some factory methods and a constructor with a signature of TimeQuantity(double, TimeSliceUnit), where the unit is just an enum.
I can get the settings designer to recognize the TimeQuantity type, but am at a loss as how to provide the setting value (8d hours, here).
Must I create some sort of settings provider? Build the object outside of the designer? Roll my own settings infrastructure?
Cheers,
Berryl
I was just battling the same issue. As far as I can tell, visual studio doesn't allow you to browse to a type in your current project; you can only browse to types in a referenced assembly. However, you can type the fully qualified name of the type you want to use in the settings 'Select a Type' dialog box like shown below. Note that this won't work until your project has been built with the type you want to reference already included. (Same is true with referenced assemblies.) Hope that helps!

How does visual studio associate mfc dialog classes with dialog resources?

I was wondering how Visual Studio associates MFC CDialog derived classes with their corresponding dialog resources. I'm not interested in how the connection is made at run time (as asked here), but rather at design time.
When I add a message handler to a dialog, how does it know which class to add the handler to.
Also, is it possible to have several CDialog derived classes associated with the same dialog resource and vice versa?
I have searched the project directory for the IDD_SOMEDIALOG string but have only found it in SomeDialog.h, resource.h and Project.rc in the expected places so I guess it somehow deduces the connection from those files, most likely the enum in SomeDialog.h:
// in class CSomeDialog:
enum { IDD = IDD_SOMEDIALOG };
I'm asking this mostly out of curiosity.
It depends on what version of dev studio.
In VS6 it was all kept in the CLW (Class Wizard File).
In newer versions of dev studio it doesn't use the CLW anymore and I don't know specifically how it knows, but i suspect its a live parsing instead of using a cached CLW.
As for having multiple derived dialogs using the same resource, it can be done manually. You can duplicate the created class files and rename them and remove the enum from header and edit the use of the IDD enum in the source file to be the actual dialog resource id (IDD_SOMEDIALOG).
AFAIK Dev Studio will only 'happily' handle one class to a dialog at a time. In my experience trying to re-use a dialog resource like this just ends up in a bit of battle with MFC & Dev Studio since they were not intended to do this.
To add to Ruddy's answer:
I noticed that some of my dialog classes in which I replaced the enum { IDD } with static const int IDD was not any longer associated with its dialog resource. Reverting to the enum re-associated them. So it seems that visual studio parses the source code to determine the relationships.
As for resource sharing, it would be ambiguous as to which class should receive the event handler code. Class sharing seems to be be impossible since it relies on the IDD which can not be assigned to a IDD_SOMETHING and IDD_SOMETHING_ELSE simultaneously.

where is my ActiveX DLL project template in VS 2005?

In VB6, ActiveX DLL is listed as a project template but in VS 2005+ there is no such thing. Where is my good old ActiveX DLL template? Many thanks in advance.
A couple of concepts; .NET Assemblies are the functional equivalent to ActiveX DLLs in the .NET langauges. .NET Classes and method can be decorated with attribute that have various meaning in different context. A .NET Assembly can be turned into a ActiveX/COM DLL (or OCX) by using various attributes to assign the correct GUIDs.
A basic overview of setting a .NET assembly use COM is here.
Note that do google searches you should include VB6 .NET and COM (not ActiveX). COM generates more hits as it is the underlying technology behind the ActiveX term.
The MSDN article I linked shows a basic COM setup for a .NET Class. The attribute here is the ComClass Attribute.
<ComClass(ComClass1.ClassId, ComClass1.InterfaceId, ComClass1.EventsId)> _
Public Class ComClass1
#Region "COM GUIDs"
' These GUIDs provide the COM identity for this class
' and its COM interfaces. If you change them, existing
' clients will no longer be able to access the class.
Public Const ClassId As String = "6DB79AF2-F661-44AC-8458-62B06BFDD9E4"
Public Const InterfaceId As String = "EDED909C-9271-4670-BA32-109AE917B1D7"
Public Const EventsId As String = "17C731B8-CE61-4B5F-B114-10F3E46153AC"
#End Region
' A creatable COM class must have a Public Sub New()
' without parameters. Otherwise, the class will not be
' registered in the COM registry and cannot be created
' through CreateObject.
Public Sub New()
MyBase.New()
End Sub
End Class
There are other Attributes as well that are especially useful if you trying to subsitute a .NET assembly for an existing COM DLL or OCX. Finally .NET has a lot of different wizards that help you with the tedious details.
Try this: http://msmvps.com/blogs/pauldomag/archive/2006/08/16/107758.aspx
It outlines how to create an activex control and use it in a web page. As far as I know there's really no 'ActiveX' project template since .NET does it differently. However you can make your .Net controls visible to the COM world, which the article above illustrates.
It's not quite clear from you question, but if you want to be able to consume in VB6 (or some other com environment) something created in VS2005, you want to look at the Interop Forms Toolkit. This greatly simplifies interop between VB6 and VS2005. Now if you actually want to distribute those applications, installing what you created becomes a lot more fun (Hints: Don't use the GAC, install the .Net dll in the same directory as your application executable, and learn to use RegAsm.)
If you give a little description what you want to use the ActiveX.dll for (project library or User Control) and what environment you want to use it, more advice can be given.
I don’t know if this is what you are trying to do or not. But if you right click on the Toolbox in Visual Studio, in the popup menu select Choose Item…
When you get the “Choose Toolbox Item” dialog box come up, select the “COM Components” tab and check the COM Component(s) you want to add to the toolbox. I have done this to added the “Windows Media Player” to the toolbox and used it in a C# Winform.
From this dialog you can access any COM, OCX or ActiveX control loaded on you system.

Resources