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:
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
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.
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.
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]
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.
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))
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.
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
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?
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
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?
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
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.
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.
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...
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]
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.
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"
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]
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..
[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?