.net - Use Mono.Cecil To Determine If A Type Implements An Interface?

Jun 23, 2012

I had a look through the documentation on the Wiki, but it seems a bit thin. How do I determine if a type implements a given interface using Cecil? For my particular implementation it is important that I do not actually load the type into the AppDomain.m Here's the code that I have so far:

Dim outputModule As ModuleDefinition = ModuleDefinition.ReadModule(outputFile)
For Each assemblyType As TypeDefinition In outputModule.Types

'How to determine if assemblyType implements a specific interface?

View 1 Replies


ADVERTISEMENT

Can Mono.Cecil Rewrite Debugging Symbols As .NET

Oct 27, 2011

After rewriting a VB.NET assembly with Mono.Cecil the 'Call Stack' debugging window in Visual Studio 2010 shows the language as C# and not VB.NET. Is it possible configure Mono.Cecil to rewrite an assembly so the debugger recognises the rewritten assembly as VB.NET?The following Mono.Cecil simply reads and saves an assembly without modification. However, the debugger reads the new assembly as C# instead of VB.NET.

Dim readerParameters = New ReaderParameters() With {.ReadSymbols = True}
Dim writerParameters = New WriterParameters() With {.WriteSymbols = True}

[code]....

It is desirable for the rewritten assembly to be VB.NET so the debugging windows 'Local' and 'Immediate Window' are the VB.NET versions rather than the C# versions.

View 1 Replies

C# - How To See If A Type Implements An Interface

Oct 25, 2010

I need to know if a Type implements an interface. [Code] because the Interface IRule itself is assignable of IRule what raises a MissingMethodExcpetion if i try to create an instance:

ruleObj = CType(Activator.CreateInstance(typeAsm, True), Rule.IRule)

UPDATE2: IsAssignableFrom in combination with IsAbstract might be the best way to check if a given type implements an interface and is not the interface itself (what throws a MissingMethodException if you try to create an instance).

If GetType(Rule.IRule).IsAssignableFrom(typeAsm) AndAlso Not typeAsm.IsAbstract Then

View 5 Replies

Tell If A Class Implements An Interface?

Dec 4, 2009

I've got a web user control (.ascx) which implements a couple of interfaces I wrote; namely IXMLBoundControl and ISectionOverridingControl.I've written a mini-CMS type application that dynamically loads controls onto the page based on information in a database. When I click a button on a web page (.aspx), I want to look at all the controls on that page, and determine if there is a control which implements the ISectionOverridingControl.

I've got my loop and I'm looping through the controls; that's fine. However I'm not sure what the best way is to determine whether or not the control implements the interface. What I'm doing at the moment (and works) is to try to cast each control into the ISectionOverridingControl and catching InvalidCastException: If I don't get the catch; I consider it's worked. If the exception is thrown then it doesn't implement the interface.

It's working, however, I consider this inefficient (relying on exceptions): surely there's a better way in VB.NET (I've seen an example in C# but it didn't convert to VB) to tell whether an instance of a class implements an interface or not?

View 3 Replies

Test If An Object Implements An Interface?

Sep 1, 2009

I have an object parameter and I need to check if the object implements a specified interface in vb.net. How to test this?

View 2 Replies

Drag Drop If Object Implements Interface

Sep 2, 2010

I have an interface, for the sake of argument called MyInterface.I Have a Control Class, lets name it "Parent" that implements MyInterface.I have another Control Class that inherits Parent, called "Child".I have a final Control Class lets call it "Container", that accepts dragging the parent onto it.[code]I want to modify this not to only accept Parent, but to accept ANYthing that implements MyInterface. I can't figure out how the heck to get it to work. Even more confusing, if I drag the child onto Container, with the code as it is above(checking to see if a Parent was dropped), GetDataPresent always returns false. I would figure it would work, since Child inherited parent.[code]But it bombs and GetDataPresent returns false whether I dragged a Parent or a Child. I'm being an idiot somewhere..

View 1 Replies

How To Test If Object Implements Defined Interface

Jun 5, 2011

I use the IsAssignableFrom-method to check if the datasource of a bindingsource-object implements an interface i defined. The check happens inside the property-setter like this:

Private WithEvents _BindingSource As BindingSource
''' <summary>
''' BindingSource containing datasource in which search is executed.
''' </summary>
''' <remarks>Datasource must implement ISearchAndFindable.</remarks>
<Description("The BindingSource to search within."), Category("Data")> _
Public Property BindingSource() As BindingSource
[Code] .....

View 4 Replies

Require That A Class Is A Windows.Forms.Control And Implements An Interface?

Nov 29, 2011

I'm not sure that I'm doing the right thing here..I'm writing a user control that's supposed to be (fairly) generic. It's a bit like a modified email client specifically tailored to some of the internal things we do.

The view is composed of two main pieces, a message list and a viewer. I need this viewer to be interchangeable, so if someone wants a different style of view they can simply handle an event and change a property. My original idea was to just have an INoteViewer, but since I'm adding it to my form I also need to guarantee that this object is a Windows.Forms.Control of some sort.

Should I continue along these lines and maybe raise an ArgumentException if I can't cast it to INoteViewer, or should I go a different direction and create a class that inherits from Windows.Forms.Control?

View 2 Replies

C# - Detecting If Type Implements ICollection<T>?

Sep 24, 2009

I am trying to check if a type implements the generic Icollection interface, since this is a base interface for any of my generic collections.the below code doesnt work

GetType(ICollection(Of)).IsAssignableFrom(
objValue.GetType().GetGenericTypeDefinition())

whats a good way of detecting if a type implements a generic interface?

View 2 Replies

.NET Class Inherits A Base Class And Implements An Interface (works In C#)?

Apr 9, 2010

I am trying to create a class in VB.NET which inherits a base abstract class and also implements an interface. The interface declares a string property called Description. The base class contains a string property called Description. The main class inherits the base class and implements the interface. The existence of the Description property in the base class fulfills the interface requirements. This works fine in C# but causes issues in VB.NET.

[Code]...

View 5 Replies

Unable To Cast COM Object Of Type 'System.__ComObject' To Interface Type 'MSTSCLib.IMsTscNonScriptable?

Jun 1, 2012

I am building a software which will be used to create a remote desktop connection. However I'm getting this error:

Unable to cast COM object of type 'System.__ComObject' to interface type 'MSTSCLib.IMsTscNonScriptable'. This operation failed because the QueryInterface call on the COM component for the interface with IID '{C1E6743A-41C1-4A74-832A-0DD06C1C7A0E}' failed
due to the following error: Δεν υποστηρίζεται τέτοια διασύνδεση (Exception from HRESULT: 0x80004002 E_NOINTERFACE)).

[Code]...

View 1 Replies

Using An Interface Defined In A Generic Type From Within The Defining Type

Feb 14, 2012

In trying to add a bit of usage variety to a generic class I'm working on, I ran into this issue with trying to cast an object into an interface instance where the interface is defined inside the generic class.

[Code]...

View 1 Replies

Error : Unable To Cast The COM Object Of Type 'System._ComObject' To Interface Type 'Microsoft.Office.Interop.Word.CustomProperties'

May 10, 2009

I have been trying to use vb2008 to automatically update CustomDocumentProperties fields that I have set up within a pro-forma document. I can load the Word application and word document without problems.I want to update the CustomDocumentProperties fields with data read from a dB. To do this I am assuming that I need to iterate through the CustomDocumentProperties fields within the word document and when one is "found" that matches the data I wish to merge then assign the dB value to the field.The problem is that I am getting an exception error when I try to reference the document customdocumentproperties

"Error : Unable to cast the COM object of type 'System._ComObject' to interface type 'Microsoft.Office.Interop.Word.CustomProperties'. ...... "

my code looks like;

Dim WordApp As Word._Application
Dim odoc As Word._Document
Dim BContinue As Boolean = True

[code].....

View 2 Replies

C# - Cecil - Getting The Defined Attributes Properties?

Aug 7, 2009

I am using Cecil to try to read my attributes properties:

[AttributeUsage(AttributeTargets.Method, AllowMultiple = false, Inherited = false)]
public sealed class TraceMethodAttribute : Attribute {
public TraceMethodAttribute() {
MethodStart = true;

[code]....

This is, I'd like this last block of code to check whenever the attribute applied to Main, for example, has MethodMessages set to true or false. From what I've seen, it seems like both attributes.Fields.Count and attributes.Properties.Count is set to 0. Why is it?

View 1 Replies

Cast A List Of Object To List Of Interface That Object Implements?

May 19, 2009

I am working in VB.net and have a Class, Foo, that implements an interface, IBar.I have a List of Foo's, but I need to pass a list of IBar's into a function, but I keep getting casting errors, even when I use DirectCast.My code is [code]MainWorks works, but it would be really annoying and inefficient to have to do that everywhere I want to call this function.

View 4 Replies

Determine If A Control Is A Given Type?

Nov 5, 2011

Public Shared Function IsType(ctrl As Control, ByVal thisType As ??????) As Boolean Return (TypeOf ctrl Is thisType) I need a function that I can call, for example, to determine if a control is type RichTextbox.dim z as Boolean= IsType(txtBox1, RichTextBox) I ned to determine if a control is a given type (i.e., not always RichTextBox). I don't know what Type to make thisType. Can this be done?Actually I simpified the problem but if the above is answered I can write the function

View 4 Replies

Determine If File Type Is A Bmp?

Apr 28, 2012

I want to scan a directory and see what files are NOT bmp image files. As the file extension can lie I need to interrogate the file itself. I found some code here [url]...?ID=112 that does exactly this however it was written for VB5 and is 13 years out of date! I tried compiling it however VB 2010 baulked and I don't have the expertise to make it work.

View 1 Replies

How To Determine File Type

Jul 31, 2009

How can I programatically determine if a file with a certain extension (XLS, for example) is really an Excel file and not a VBS file, for example, that has the XLS extension?

View 1 Replies

How To Determine The Type Of A Control

Dec 12, 2009

I need to determine the type of a WinForms control in a collection.

[Code]...

View 1 Replies

Determine Cell Type Of A Column?

May 17, 2010

how do you determine cell type of a column?

View 7 Replies

Determine OS Type For Wow6432Node Registry?

Oct 14, 2010

I need to check a value within the registry. The application (Cisco VPN) is a 32bit app so uses Wow6432Node when installed on 64bit operating systems.What would be the best method of selecting which string to use? Checking the OS for x64, attempting to read one and then the other if the first fails? Or is there a better method?

Dim keyName64 As String = "HKEY_LOCAL_MACHINESoftwareWow6432NodeCisco SystemsVPN Client"
Dim keyName32 As String = "HKEY_LOCAL_MACHINESoftwareCisco SystemsVPN Client"

Using .net 4.0 framework?:

Dim registryKey As RegistryKey
If Environment.Is64BitOperatingSystem = True Then
registryKey = registryKey.OpenBaseKey(Microsoft.Win32.RegistryHive.LocalMachine, RegistryView.Registry64)
Else
registryKey = RegistryKey.OpenBaseKey(Microsoft.Win32.RegistryHive.LocalMachine, RegistryView.Registry32)
End If

View 1 Replies

Determine The Actual Type Of A ToolStripItem In C#?

Jul 31, 2011

I am converting a VB.Net application to C#. Everything else is going great. Except this bit. I have a function which builds menus,sub menus and seperators from a database. It can build a MenuStrip or a ContextMenuStrip which can then be assigned to a form.

This means that menus can be extensive and conpmex but managed outside the application, which I also use as part of my security access model. All menus are controlled from the database externally, it also means I can develop visual tools (Treeviews etc) to manage user menus. The application uses menus extensively which is by design.

Programmatically I want to assign an eventhandler to every item that isnt a dropdown or a seperator

In VB I would do this, (works perfectly)

[Code]...

"System.Windows.Forms.ToolStripItem' does not contain a definition for 'DropDownItems' and no extension method 'DropDownItems' accepting a first argument of type 'System.Windows.Forms.ToolStripItem' could be found (are you missing a using directive or an assembly reference?)"

View 3 Replies

Determine The Type Of A Passed Object?

May 19, 2009

I am still developing this function, but here is what I am intending it to do. This function will accept an Object, then try to determine its type. There are a specific set of types I am looking for: Integer, Boolean, Date, String. What I have so far is pretty privative, but it seems to be working so far:

Private Function DataType(ByVal entry As Object) As ValueType
Try
If IsNumeric(entry) Then

[Code].....

View 3 Replies

Determine Type Of Object In A Collection?

Oct 28, 2009

I can't figure out how to determine the type of an object in a collection. I want to do a For Each ... Next loop over the items in the DropDownItems collection of a ToolStripMenuItem. For those items that are ToolStripMenuItems themselves I want to take some kind of action. (The collection can contain other types of items, such as ToolStripSeparators). So I need to say something like: If Typeof(item) = ToolStripMenuItem Then .

View 1 Replies

How To Determine If Value Is Instance Of Generic Type

Mar 27, 2010

I have a class C(Of T). I want to determine if some given value has type C, regardless of what T is. For example, I might want to determine if a value is a strongly-typed list, regardless what type of items the list stores. I just need to know how to do it in VB.net. In Java the syntax is like this:
var result = obj instance of Gen2<?>;

View 3 Replies

.net - Determine If A Generic Parameter Is A Nullable Type?

Mar 3, 2011

I have the following VB.NET function, for example:

Public Function MyFunction (Of TData) (ByVal InParam As Integer) As TData
End Sub

How do I, in a function, determine if TData is a NULLable Type?

View 3 Replies

Determine A Dataset Column Data Type?

Mar 17, 2010

I have a dataset and want to know the data type of a specific column. The GetType returns datacolumn not string or integer etc.iggy!

View 2 Replies

Determine Error Type In Try Catch Statement

Sep 24, 2009

I'm interested in having a generic 'Try Catch' clause, with some case statements or if/than statements within the Catch part so that I can handle different error types differently. some way to get ex.Errorcode or ex.ErrorType that differentiates the different errors to a unique value.

How can this be done?

Try

'some code taht will throw an error'

Catch ex AS Exception
If ex.ErrorCode = 20 then
' Do something'

[Code].....

View 6 Replies

Determine If A Generic Param Is A Nullable Type?

Dec 14, 2006

I have the following VB.NET function, for example:Public Function MyFunction (Of TData) (ByVal InParam As Integer) As TDataEnd Sub

View 5 Replies

Determine The Type Of Control In The Controls Collection

Oct 9, 2009

I have a small piece of code that iterates through the controls collection on a panel (below) Everything works fine until I want to focus on a control that doesn't support the selectall method i.e. a datetimepicker. Is there any way of determining the type of control and not call the selectall method when the type is datetimepicker. All my other controls support it so that's the only one I need to exclude.

[code]...

View 2 Replies







Copyrights 2005-15 www.BigResource.com, All rights reserved