Doesn't C# Extension Methods Allow Passing Parameters By Reference?

Aug 11, 2009

Is it really impossible to create an extension method in C# where the instance is passed as a reference?

Heres a sample VB.NET console app:
Imports System.Runtime.CompilerServices
Module Module1

[code].....

View 3 Replies


ADVERTISEMENT

Passing Parameters By Reference Into Public Shared Methods

Oct 21, 2009

I have a List(Of AddlInfo) with AddlInfo being an object. I'm trying to pass addlInfoList by reference into a function of another class:

[Code]...

This works if I'm not passing the reference into another class, but when I try to do this, I get the following error: Overload resolution failed because no accessible 'Sort' can be called with these arguments:

[Code]...

View 1 Replies

.net - Extension Methods From C# Dll Doesn't Work As Extensions?

Sep 17, 2010

I made a library in C# and I've been told by people that one of mine methods don't work in VB.NET as extension [UR]

this is the method:

public static PropertyDescriptorCollection GetProps(this object o)
{
return GetProps(o.GetType());
}

View 1 Replies

.net - Extension Methods In T4?

Mar 28, 2012

I'm trying to use PGK.Extensions in a T4 template in VS2008 for VB.NET and I get:

RemoveAllSpecialCharacters is not a member of string..

My T4 headers:

<#@ template language="VB" hostspecific="false" debug="true" inherits="Microsoft.VisualStudio.TextTemplating.VSHost.ModelingTextTransformation" #>
<#@ output extension="vb" #>
<#@ assembly name="PGK.Extensions.dll" #> // the dll is found
<#@ import namespace="StringExtensions" #> //Try with and without namespace

[Code]...

View 1 Replies

Why Use Extension Methods

Jan 7, 2010

I would like to know your opinion on extension methods. Sure, it is a nice feature and makes you feel powerful. It's great to see your own method pop up when typing in a object. But it doesn't really add something new... You can get the job done with normal methods as well. I think extension methods do not belong in object oriented programming. It makes your code easier to read but harder to understand for someone else.

View 2 Replies

.net - Extension Methods Error ?

Mar 7, 2011

CODE:

View 2 Replies

Asp.net Mvc - Combining Extension Methods?

Sep 5, 2009

I'm trying to write 2 extension methods to handle Enum types.One to use the description attribute to give some better explanation to the enum options and a second method to list the enum options and their description to use in a selectlist or some kind of collection.You can read my code up to now here:

<Extension()> _
Public Function ToDescriptionString(ByVal en As System.Enum) As String
Dim type As Type = en.GetType
Dim entries() As String = en.ToString().Split(","c)

[code]....

So my problem is both extension methods don't work that well together. The methods that converts the enum options to an ienumerable can't use the extension method to get the description.

View 1 Replies

Extension Methods For Object

Nov 9, 2011

I wonder why it's impossible to create and extension method for Object? I use Excel PIA. The property Cells of Worksheet returns Object (if using with indexes). For example, Worksheet.Cells(1, 1) returns Object type. I know it's a Range object, and I want to cast it to Range. It would be convenient to write following:[code]

View 5 Replies

How Do Extension Methods Really Work

Jan 25, 2010

I know what extension methods are, how to create and use them, but I wanted to know more about how they actually work. How do they "attach" themselves to the type of object that you are extending? Or is there even an attachment being made. I know want to know more about the inner workings, etc.. I looked around and read several different blog posts about extensions and not one of them discusses how they actually work.

View 6 Replies

.net - Extension Methods In Referenced Assemblies?

Sep 16, 2010

If I try to call my extension method which is defined like this:

Module LinqExtensions
<System.Runtime.CompilerServices.Extension()> _
Public Function ToSortableBindingList(Of TSource)(ByVal source As IEnumerable(Of TSource))

[code].....

View 1 Replies

.net - Syntax And String Extension Methods

Aug 30, 2011

Code in VB.NET

[Code]...

works very well. So seems some consistency miss of the string constant behavior.

2) Have a look on the COMMENTS (in the attached picture). The words "custom", "string" and "error" are highlighted, however they are in the comments, so should be green, not blue.

Why this? What workaround? EDIT: Declared as "bug" in Microsoft Connect (even if is not more that a syntactic "miss")... EDIT 2: As remarked Hans Passant, standard string methods, like "cucu".Trim() does not work either.

View 2 Replies

.net - Using Extension Methods From Within An Object's Constructor?

Feb 8, 2010

Consider the following:

Public Module Extensions
<Extension()> _
Public Sub Initialize(ByRef Target as SomeClass, ByVal SomeParam as Something )

[code].....

Why is Case 1 failing to initialize the object as expected?

View 1 Replies

How To Know If Class Has Been Extended With Extension Methods

May 30, 2012

In VB.NET or C#, is there a way to determine if a class has been extended with extension methods?

View 3 Replies

Way To Add An Overload To A Method That Already Has One Or More Extension Methods?

Jan 8, 2010

Is there anyway to add an overload "extension method" to a method that already has one or more extension methods?For example theString.Contains method has two extension methods totalling 3 separate versions.Is there anyway to add an extra extension method also called "Contains" ?By the way I have tried it but the IDE does not seem to recognise additional EXTENSION methods where a method already hasone or more extension methods.Is there anyway around this restriction?In other words I would like to be able to change the Extension method below from"Contain" to "Contains" but it seems it is not recognised.

Option Strict On
Public Class Form1
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles

[code].....

View 4 Replies

.net - Extension Methods In VB 2008 Assembly Cannot Be Used In A C# Project?

Jun 1, 2011

I wrote some string extension methods in a VB assembly and am unit testing them from a C# project. However, C# acts like it cannot see the the extension methods, when other VB projects reference the VB assembly they have no problem. Both the VB assemebly and the C# test project are targeting .Net 3.5. Is there a way around this?

[Code]...

View 1 Replies

Extension Select Methods For Entity Framework?

Dec 14, 2011

I have many similar calls to database and they work fine

Using ta As New QT_SSTEntities
Return ta.Product.
Select(Function(c) New RadComboBoxData() With {.Text = c.FieldName1, .Value = c.FieldName1}).

[Code].....

View 1 Replies

.net - Check That Extension Methods On An Array Got A Specific Size?

May 30, 2012

I'm using extension methods based on an array and I would like to know if there is an easy way to check that array got a specify size instead of me doing a copy paste of

if array.count != 1000
throw new exception "size of the array does not match"
in about ~50 extensions

this a small sample of extensions that I use, I got WAY more

<Extension()>
Public Function IsWhite(ByVal board() As bitPiece, ByVal pos As Integer) As Boolean
Return (board(pos) And bitPiece.White) = bitPiece.White
End Function

[code]....

View 3 Replies

LINQ To XML Result Object Not Showing Extension Methods

Jan 9, 2012

I have the code as below:
Dim xdTest As XDocument = XDocument.Load(GetXMLPath())
Dim objResult = From xe In xdTest.Elements("Some Element") _
Where xe.Element("strName").Value = strInput _
Select xe.Element("intValue").Value
objResult.
I cannot access any extension methods for objResult, like .ToList() or .First(). The file imports System.Linq and the project is targeted to .NET 3.5. How do I get the extension methods back?

View 1 Replies

MVC2 Extension Methods Throwing Errors In Views?

Nov 21, 2011

I have a project written in MVC2 and VB.NET. I use a lot of htmlhelper extension methods,and I have them all in a public module. They work just fine, and I can compile and run my project. I reference the namespace they are in with this:<%@ Import Namespace="MyProject.WebUI.Extensions" %>So, again, they work great, my project runs and compiles without a hitch.The problem is that each one of these extension methods is shown as an error:

Error 33 'TabbedMenu' is not a member of 'System.Web.Mvc.HtmlHelper(Of Object)'. C:ProjectsMyProjectMyProject.WebUIViewsSharedSite.Master 23 21 MyProject.WebUI

[code]....

View 2 Replies

Silverlight - Useful Extension Methods In System.data.* Namespace?

Nov 21, 2011

I have a number of very useful extension methods that I'd like to use in my Silverlight project.I've pasted the Module here [URL]The problem I'm having is that visual studio complains that the dlls my module have been written against have not been built against the Silverlight runtime.Is there an easy way to get these extension methods working in Silverlight?I'm thinking my main hurdle is getting IObjectSet and ObjectContext to run against the Silverlight run-time - perhaps there's another way to expose these methods that I'm not aware of.

View 1 Replies

Implement An Interface In .Net When Two Methods Have The Same Name But Different Parameters?

Mar 3, 2010

I am a C# programmer but I have to work with some VB.Net code and I came across a situation where I have two methods on an interface with the same name but different method parameters. When I attempt to implement this interface in a class, VB.Net requires explicitly declaring "Implements MethodName" after the method signature. Since both method names are identical, this is confusing the compiler. Is there a way to get around this sort of problem? I suspect this must be a common occurrence. Any thoughts?

N.B. This was more a case of the programmer not verifying that the interface in question had not changed from underneath him.

View 3 Replies

Passing Objects To Methods?

Jun 26, 2010

I always thought I understood how this works...but lately I have started really using interfaces and now things arent doing what I am expecting.

using entity framework, I have a service for each object that is responsible for interacting with the database and such....on my one service I am passing the collection of objects to my service as an icollection(of contactinfo) before I pass the object, the changetraker has the right states. however in my method, this is not the case and all states are set to unmodified.

Private Sub SaveExecute(ByVal param As Object)
Dim srv As Services.ContactInfoService = GetService(Of Services.IContactInfoService)()

[Code]....

As I said above the Me.contacInfoCollection has the right changetracking states. But Once its passed to the srv.savechanges it reverts to unmodified. I am sure its something silly I am missing...the whole EF thing can be confusing to me...

View 2 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

Accepting Multiple Parameters In MVC 4 Web API Controller And Mapping To Custom Methods?

Jun 25, 2012

I'm trying to implement a Web API project that exposes some models. However, the way the model is retrieved isn't very RESTful. 1.Instead of having just one ID, it has a combination of 4 different ones to populate the model data by running a stored proc on the server.Dim balance as New BalanceSheet(uid, mid, eid, fid)The snippet above will use uid, mid, eid, fid to retrieve the correct record from the database.

View 1 Replies

Passing Parameters?

Jan 17, 2010

I'm trying to learn VB and don't understand what is wrong with this code?

Private Sub ScoreRange(strStart as String, strStop As String)
Dim MyCell As Range
For Each MyCell In Range(strStart & ":" & strStop).Cells

[code]....

View 6 Replies

VS 2008 Object Reference Within <Extension()>?

Jul 30, 2009

I am toying around with extension methods here and have run into a snag adding an extension method to the textbox control.

<Extension()> _
Public Sub InvertMono(ByRef t As TextBox)
Select Case t.BackColor
Case Color.White

[code]....

View 4 Replies

No Data When Passing The Parameters In Pdf?

Oct 14, 2009

to solve my problem regarding dataset, crystal reports and exporting to pdf file? There are datas when i preview the crystal reports but when i export it to pdf viewer there's no data displayed. Here's my

DataOpen()
cmd.CommandText = "Select * From AllDTR Where BIOID = '" & myuser & "' AND Date > '08/31/2009' ORDER by Date"

[code].....

View 3 Replies

Passing Parameters From One Form To Another

Nov 8, 2009

I have a form with 2 dateTimePickers and a SHOW button which gets data from an sql server database and displays it in a DataGridView. this works ok. I also have an EDIT button which brings up another form with textbox and comboBox controls displaying this one record. I want to be able to click in the DataGridView to select a Name and then click on the EDIT button to bring up the selected record. I don't know how to pass the ID as a parameter to this second form. Apart from that the EDIT button works, in the sense that I hard coded the ID (32 or 35 etc.) and it brings up the appropriate record. But how do i pass the selected ID. [Code]

View 2 Replies

Passing Parameters To A Dataset?

Sep 21, 2009

I have a DataSet1.xsd This is connected to my access DB through OleDB. the DataSet Designer is stating that my column in my table is of type Double. Which is true when I verify it by opening Access and viewing that same column in my table.

I need to pass a parameter to my fill query so that on formload it populates the controls. I create the parameter in the dataset designer and give the paramter a name and specify the proper data type.

I edit the query to include the parameter.

on form load the generated code from the dataset designer inserts the fill command for the table adapter but doesn't include the parameter data, so I manually insert the data to be passed to the parameter.. This is where I get an error stating that datatype mismatched..

However the datatypes are correct.

View 2 Replies

Passing Parameters To BAT File

Dec 3, 2009

[code]This works fine and passes 8 parameters into the sysimp.bat file. The problem is if I try to pass in a value that has a space between the text then it will treat it as two parameters rater than one.So if P1 value is for example "Hello World" then when passed into the bat file it will assign "Hello" to P1 & "World" to P2. Is there a way to wrap the text in the parameters or should this be done in the .bat file?

View 9 Replies







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