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.
I have imports namespace System.Data.SqlClient.I just create object of SqlConnection,But error is there- 'SqlConnection' is ambiguous in the namespace 'System.Data.SqlClient'.
I am creating class libraries in my project so that I can update code without having to update the whole app.I created a class library project and added some code to it. I also added a reference to System.Data.SqlClient and also imported it into the class file.I am getting an error and I have never seen it before. Been looking online and not able to find an answer yet.
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.
This class is located in the namespace Acme.Infrastructure.Interface.A class with the same name EventArgs exists in the System namespace.In another project in my solution I have a class Acme.BusinessModules.MyModule.MyClass.When attempting to use the EventArgs class I have to fully qualify the class name or the compiler thinks I am using the System.EventArgs class.My understanding of namespace resolution was that the compiler would first look for the class in the current namespace, and then its parents. It seems that the compiler checks in System before it checks in sibling namespaces. Is it correct that System is checked before the sibling? Or is this behaviour caused by other issues (Imports order?)?
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?
Is there a simple way in vb.net to mask a public property or method from the internal namespace? It would be helpful as a refactoring tool to isolate internal dependencies and perhaps to enforce a non-recursion policy for external services.
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 am having a namespace extension implemented, which is visible in "MY Computer". I want to write automated test cases to browse through the same. I am able to open the explorer window till the namespace extension. as - Process.Start("explorer.exe", "shell:::{CLSID of my namespace }")
next I want to search for a particular folder name inside the window opened. For example if i give input as "temp", then my mouse should move to "temp" folder in the namespace explorer window. then I double click on the mouse's current position and enter that folder. next i give input as "doc1.doc", then my mouse should be able to locate & move to "doc1.doc" file. Also getDirectory or GetFile etc APIs won't work because I don't have a standard drive associated with my namespace & don't have a relative path either.
I want to know what are classes , objects , a namespace , subroutines,functions,methods,properties and differemce betweem byval and byref in your words.
I would use the System.Linq.Dynamic. I added the specified Dynamic.vb file, that starts like this:
[Code]...
to my (VB.NET)solution. Now Visual Studio does not recognize anymore in the project files the System.XXX references, proposing me to change them to Global.System.XXX
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.
This as I wrote in VB.NET. I know I'm wrong, but how do you do if the int to System.Windows.GridLength so that the height of the "rowerror" whether that be 30?