C# - Overloaded .NET Extension Method In Class Library?

Jul 20, 2010

It seems that my library of extension methods that was written in VB.NET has problems.I have 2 overloaded extension methods Crop().When i reference the lib from a VB.NET project i see them. If reference it from a C# project i can't see them.

View 3 Replies


ADVERTISEMENT

Debug And Deploy Class Library That Is Really A VSX Extension?

Oct 21, 2010

The Class Library is an Microsoft Studio extension that generates a file from saving running a custom tool on a template file, following the module from this example I found from Microsoft: [URL]

I can not figure out how I'm gonna debug, build, or deploy this object so I can test it in Microsoft Studio 2010. If you can help me get my class library debugging inside the VSX instance let me know. I will also need to compile and have a delivery method for this extension.

View 1 Replies

Xml - C# Class Library Method Summaries Not Showing In Intellisense Of .net Project?

Dec 19, 2010

(VS 2008)I'm using a C# library for my VB.NET project. And the method summary/notes or what they are called do not show in intellisense. Is this supposed to be like that? Or is there something I must do to fix it? And if not, will VS 2010 be able to do this?

EDIT: Still unresolved. Now building library dll + xml file, but how to import the xml file in my vb project?
See image: [URL]...

View 2 Replies

VS 2010 Create An Overloaded Method In A Module

Feb 14, 2012

I'm trying to create an overloaded method in a module, but if I type Public Overloads Function GetData(ByVal sql As String) As String it tells me "Inappropriate use of 'Overloads' keyword in a module". Are overloaded methods not allowed in modules?

View 3 Replies

Asp.net - .Net Iniatialising A Class Using System.Reflection And System.Type To Create A Session Based Singlton Extension Method

Jun 11, 2009

I have had several occasions recently to access a specific class several times over a relatively small time frame.So I've been storing the value of the class in Session and trying to access it on page load, if it's not available creating a new instance and storing that in session.

So instead of constantly replicating the same code for different classes on different pages I'm trying to create an extension method to do this for me.

[Code]...

I'm stuck on what to do when I make my new instance of my class (it would have to have a New() sub)

I'm not sure where to go from here... or even if this is the best way to do it.

View 2 Replies

Use An Extension Method Instead Of Just Creating Non-extension Sub Or Function?

Dec 3, 2009

Why would I use an extension method instead of just creating non-extension sub or function?

For ex, I could have an extension function called IsNullOrEmptyOrAllSpaces on String, which does a check as its name implies. Or I can write a stand alone function that does the same thing. Other than having the extension show up in Intellisense, is there any advantage? Is a call to the extension quicker/more efficient than a call to a regular function?

View 8 Replies

Class That Contains Overloaded Methods?

Jul 16, 2011

In this project I am making a grade calculator; I am modifying an existing code I have to have the following characteristics: I need to modify the DetermineGrade method so that it accepts the maximum number of points that can be earned on both tests (currently, the max number of points is 200: 100 points per test). For an A grade, the student must earn at least 90% of the total number of points. For a B, the student must earn at least 80%. For a C, at least 70%. For a D, at least 60%. If they earn less than 60% of the total points, then grade is F. Here is the exisint code I have for the DetermineGrade method specifically:

Public Sub DetermineGrade()
Dim intTotal As Integer
intTotal = _intScore1 + _intScore2

[code]......

View 5 Replies

Overloaded Constructor In Abstract Class

Nov 19, 2010

I have an abstract class in vb.net with two subclasses. In the abstract class I have a constuctor that looks like this:[code]I would like to create a second constructor that doesn't take any arguments and just initializes the args to default values.[code]When I attempt to create a new subclass using the second constructor the compiler complains that I'm missing two args to the constructor.Is there a reason I can't overload the constructor in the abstract class?

View 2 Replies

VB Extension Property Instead Of Extension Method

Mar 16, 2012

I saw this post and I want to know if this is possible in VB. So like extension method, do extension properties exists in VB.Net? Here I've read they do, but cannot find any examples.

View 3 Replies

Constrain A Generic Method / Extension Method To Numeric TYPEs Only?

Sep 16, 2010

Write an overload for every numeric type or if possible constrain a generic extension method to just numeric types.

View 2 Replies

Determine Whether A Method Is Declared Normally Or As An Extension Method?

Jul 16, 2010

Extension methods are useful for types that you don't own and can't/don't want to derive from and extend (e.g. reference types and interfaces). Obviously, interfaces should be kept as short and to-the-point as possible, so extension methods for interfaces are particularly useful (e.g. LINQ).For classes, especially classes that you own, they're still useful - but I'm wondering how you determine what should be an extension method or what should be a method in the class itself.Personally, every time I think about it, I keep going round in circles with the following thoughts:If it's useful enough, it should be in the class.It's not part of the core responsibility of the class, it should be an extension method - but if it's useful enough, surely it should be the responsibility of the class...

View 3 Replies

VB2010 Class Library: Create A Static Library Instead Of DLL?

Jun 21, 2011

I have a Visual Basic Class Library project. It generates a DLL. Is there a method to generate a static .LIB to which I can do a static link?Alternatively, can I do a static link against a DLL?

View 6 Replies

Strongly-typed Generic Method Invokes Its Argument's Base Class Method Instead Of A Shadowed Method In T?

Oct 19, 2010

Consider a MyForm class that contains a shadowed implementation of Show(). It also contains a CreateForm() method, which accepts an instance of the form and calls the shadowed sub:

[Code]....

View 3 Replies

How To Add Extension Method

Apr 10, 2010

I know how to add extension method Like (Date.Now.MyExtensionFunction()),But I can NOT find how to add such methods and functions in class (not in module) with vb.net

View 3 Replies

Asp.net - Error With Extension Method In .NET?

Mar 26, 2012

I am trying to write extension methods in VB.NET

Imports System.Runtime.CompilerServices
Module ExtensionMethods
<Extension()> _

[code]....

But I am getting this error.Class 'System.Web.UI.WebControls.ListItem' cannot be indexed because it has no default property

What could be wrong?I am calling the code like this.

ddlSalesmanager.Items.FindByText(survey, StringComparison.CurrentCultureIgnoreCase)

P.S: I ported this wonderful code from C# to VB

View 1 Replies

Calling A VB Extension Method?

Feb 23, 2012

I converted some code from c# for a VB.net project I have an object declared as this :

<Serializable()> _
Public Class oUserApplication
Public ApplicationID As Integer = 0
Public ApplicationRoleID As Integer = 0

[code]....

View 3 Replies

Extension Method In View Using ASP.NET MVC?

May 18, 2009

I ran into a strange issue over the weekend while I was working on an asp.net mvc project in vb.net. I created an extension method to convert an integer to the corresponding month it is associated with. I tested the extension method in a console application so I know it is working.

In my asp.net mvc project I have a view and want to call the extension method but I get an error that the extension method is not recognized. I imported the namespace it was contained in and still couldn't shake the error.

Extension Method:

Imports System.Runtime.CompilerServices
Module SiteExtensions
<Extension()> _

[Code].....

View 3 Replies

Implement An Extension Method?

Nov 10, 2010

I want to implement an extension method in VB.NET that will clone an object of type T.Say, I want

Dim cust1 as New Customer() //...
Dim cust2 as New Customer() //...
cust2 = cust1.Clone()

[code]....

View 2 Replies

MyBase Cannot To Be Used In A Extension Method?

Jun 7, 2012

I created a module to add some Extension Methods to a Class. This Class inherits from another parent Class. In the code of my Extension Methods, I would like to refer to the base Class using MyBase. This doesn't seems to be allowed (Error message : "'MyBase' is not valid within a Module.")

[Code]...

View 1 Replies

.net - Extension Method And Type Constraints?

Sep 13, 2010

I am starting to play with extension methods and i came across with this problem:In the next scenario i get a: "extension method has a type constraint that can never be satisfied"

Public Interface IKeyedObject(Of TKey As IEquatable(Of TKey))
ReadOnly Property InstanceKey() As TKey
End Interface

[Code]...

View 1 Replies

.net - Extension Method For Anonymous Function?

Jul 13, 2011

I'm trying to create an extension method that returns an IEqualityComparer based on a lambda function. Heres the extension method:

<Extension()>
Public Function Comparer(Of T)(Func As Func(Of T, T, Boolean)) As IEqualityComparer(Of T)
Return New GenericComparer(Of T)(Func)
End Function

[Code]...

View 1 Replies

.net - Is An Extension Method The Only Way To Add A Function To An Enum

Oct 27, 2010

I have a Direction Enum:

Public Enum Direction
Left
Right
Top
Bottom
End Enum

And Sometimes I need to get the inverse, so it seems nice to write:

SomeDirection.Inverse()

But I can't put a method on an enum! However, I can add an Extension Method (VS2008+) to it.

In VB, Extension Methods must be inside Modules. I really don't like modules that much, and I'm trying to write a (moderately) simple class that I can share in a single file to be plugged into other projects.

Modules can only reside in the file/namespace level so I have one in the bottom of the file now:

Public Class MyClass
'...'
End Class

[Code]....

It works, and "if it ain't broke, don't fix it", but I'd love to know if I'm doing it wrong and there's a better way with less boilerplate. Maybe in .NET 4?

Finally, I know I could write a structure that behaves like an enum, but that seems even more backwards.

View 2 Replies

.net :: Using Reflection To Invoke An Extension Method?

Nov 16, 2011

I've created a MyFunc extension (in Module Extensions) for all the base types as well as generic arrays, ICollection(Of T) and Dictionary(Of String,T):

Function MyFunc(Of T)(a() As T) As String
Function MyFunc(Of T)(collection As ICollection(Of T)) As String
Function MyFunc(Of T)(dict As Dictionary(Of String,T)) As String

[code].....

View 1 Replies

Access MyBase From An Extension Method?

Jan 1, 2010

how do we access MyBase from an extension method?

i'm trying to extend a Sub called PassDown that would call the form's Base's OnPaint method

<Runtime.CompilerServices.Extension()> Public Sub PassDown(ByVal form_instance As Windows.Forms.Form, ByVal e As EventArgs)
MyBase.OnPaint(e)

but of course, mybase couldn't be accessed this way so is there an alternative?

View 5 Replies

Asp.net - Access Web.config In Extension Method?

May 31, 2012

Can I access values in application settings of web.config in extension method?I have the below code but it is not working:

<Extension()> _
Public Function DocCountExt(ByVal value As Collection) As Integer
Dim maxOffSet As Integer = Integer.Parse(ConfigurationManager.AppSettings(APP_SETTINGS_OFFSET))
return maxOffSet
End Function

The above code does not work.

View 3 Replies

Convert Extension Method Module To DLL?

Aug 7, 2011

i want to extend the integer class to a method that increments current integer value by 2. I create a console application and a second module which contains the extension method.

Imports System.Runtime.CompilerServices
Module StringExtensions
<Extension()>

[code]....

and everything works fine. The extension method module can be imported to any other project (Project-->add existing item --> select the vb file that contains the extension method module) and works fine too. But the code is accessible to other users. Is there a method to convert the extension method module to a dll and adding it to other projects as a reference. I tried to do it with creating a class project and pasting the code of the extension method module and compile the dll and then added it as reference to another project and imported the class with the keyword imports, but it didn't work.

View 5 Replies

Extension Method Doesn't Work

Jul 5, 2010

I wanna create extension method for IEnumerable(Of FileSystemInfo). However, compiler says "'Sort' is not a member of'System.Collections. Generic. IEnumerable(Of System.IO.FileSystemInfo)". What is strange is that IntelliSense shows this method. Where's error? [code]

View 1 Replies

Extension Method For Pages That Uses GetLocalResourceObject?

Feb 11, 2011

In our .aspx pages, we've got lots of this code:<%= CType(GetLocalResourceObject("key"), String)) %>I'd like to add an extension method that I can use in our .aspx views that allows me to do this:<%= GetLocalResourceString("key") %>The code isn't working, though:Imports System.Runtime.CompilerServices

View 1 Replies

How To Create Extension To Shared Method

Jul 24, 2011

I like to create an extension method to Image.FromStream Public Shared Function FromStream(ByVal stream As System.IO.Stream) As System.Drawing.Image

With possibility to cancel processing like Public Shared Function FromStream(ByVal stream As System.IO.Stream, ByVal CloseTask As ManualResetEvent) As System.Drawing.Image

View 1 Replies

IEnumerable<XElement>.Value() Extension Method Available In .Net But Not C#?

Jun 5, 2012

In VB.Net you can easily get the text value of the first child element of an XElement like so:Dim sChildValue = xeParent.<MyChild>.Value()Of course that syntax is not supported in C#, but it produces the same IEnumerable(Of XElement) result as the Elements() method. So we can rewrite the above like so:

Dim sChildValue = xeParent.Elements("MyChild").Value()This Value() extension method is handy because often you are working with small XML documents and you just want the first node that matches. (One thing that annoys me about this method is that it seems to return Nothing/null if the IEnumerable list is empty due to the specified element not being found. To work around this I have created my own ValueOrBlank() method that returns an empty string in that situation instead.)

My problem is that I can't do the same thing in C#:var sChildValue = xeParent.Elements("MyChild").Value(); // won't compile, can't find Value() method

I checked my references/imports and they match the VB.Net project where the same call works. Fortunately I am able to use my custom ValueOrBlank() extension method to accomplish the same thing. But I'm curious as to what's missing in my C# project. I tried right-clicking on the Value() method call in Visual Studio and clicking "Go To Definition" to see if the Object Browser could tell me where the extension method is kept, but it just shows the System.String class. Does that mean this is one of those sneaky VB.Net-only features that the compiler itself supports, like the XML Axis < MyChild > syntax?

View 2 Replies







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