.NET Tutorials, Forums, Interview Questions And Answers
Welcome :Guest
Sign In
Win Surprise Gifts!!!

Top 5 Contributors of the Month
Gaurav Pal
Post New Web Links

add an extra method to an existing class

Posted By:      Posted Date: September 24, 2010    Points: 0   Category :ASP.Net

Suppose that I want to implement another method for a class namely hasFiles for System.IO.Directory , How can I do that?

for example if I add <Extension()> _  tag before each function or Sub I can add a new function or method for each Control.

How should it be for a specific Class?

View Complete Post

More Related Resource Links

Extension Method ForEach for ArrayList class

Hi,I need to create an extension method(ForEach) for arraylist classI have created an extension method for Array class but cannot do that for arraylist.Please help me namespace MyExtension { public static class IEnumerableExtension { public static void ForEach<T>(this IEnumerable<T> list, Action<T> action) { if (action == null) throw new ArgumentNullException("action"); foreach (T item in list) { action(item); } } } } Any Help Shall be appreciatedThanks

Calling a method with a class object as parameter data type.

   [WebMethod]    public string GetInfo(Customer inCust)    {        // Code in here    } I have a web service that resides on a remote server. I want to call a public method of theweb service named  "GetInfo". The method is shown above. The web service method expects a class object oftype "Customer". What I did to create a Customer object was to define in my asp.net project my own class named "Customer" which is exactlythe same as the class that belongs to the web service project on the remote server. I then created an instance of Customerand tried to call the web service passing in an object of type customer : my.Service ws = new my.Service(); // Get web service connectionCustomer aCustomer = new Customer();aCustomer.Initialize();ws.GetInfo(aCustomer) // call web service passing in a Customer object The problem is that the compiler gives me the following error: Value of type '_Default.Customer' cannot be converted to 'ws.Class1'. Here Default is refering to my Default.aspx.cs code. Why is this? Do I need to Cast my "aCustomer" class object to a type ofws.Customer ? How do I do that?

[] brackets before a class or method Declaration

Hi Guys,Some times we have [] brackets before a class or method Declaration.  Can anyone guide me please in understanding those squre brackets.  what do we write in those and what they represent. like this [SerializableAttribute][ObsoleteAttribute]class Moon { }Thanks in advance.

Is it possible to add a class method to CLR base class like Date?

Hi All, I would like to add a class method like ParseYYYYMMDD to the Date base class. So that I can use the following code. Dim result As Date = Date.ParseYYYYMMDD(dateString) Any idea? Is it possible via extension? Thanks! Regards, AlexAlex Lau from HKSAR

how to get a class reference as a reference and not a string to send for a generic method

I got some property that i get using generic method, there for I dont have it's <T>and I want to send it to another generic method but , how the heck do I get it's <T> :P?please look at the code below to understandit gets an entity framework objects, scan all it's properties and if the property is another entity framework object it would send it back to him self , the issue is that i dont know the new object <T> to send it back to him self :(search for the bold part to see what i'm missing//contains objects which we added so there wont be double adding private List<object> _addedObjects; public FakeGenericRepositoryExtension() { _addedObjects = new List<object>(); } public void Create<T>(T entity) where T : class { //add to created objects _addedObjects.Add(entity); //do something with object //... //start recircle process Type entityType = typeof(T); //run thrue each member of Type foreach (var member in typeof(Type).GetProperties()) { //get member value var member_value = member.GetValue(entity, null); //if not null //we must test this otherwise we can't get .BaseType if (member_value != null) { //get current member's base type string memberBaseType = member.GetValue(entity, null).GetType().BaseTyp

C#NET2008 FrmMain using DELEGATE CLASS Method



Hullo Good Guys,


I am back here seeking help. Please Help me.


Here us the description of what I was ihstructed to do by the System Analyst.


Create DELEGATE Class to perform Mortgage computation and return the result back to the calling FrmMortgage.cs. Apparently my coding are not working as I am not familiar with DELEGATE Class


Here are the Erro

Calling a static method in a static class from a base class.


I have the following static class and method:

public static class GenericList


      public static List<DocumentElement> PopulateGenericList()



What is the syntax to call the PopulteGenericList() method from a base class?



Connect DataTemplate from resource , to existing class.

<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"


<src:CatList x:Key="cat"/>


first Thanks.

Where <sr

Unusual problem using a class method


I have a class that runs calculations on numbers and populates the results to my SQL database.  My code behind page instantiates the class object, and in a loop it makes use of the method five times (once per loop).  Essentially, my code behind collects the information from controls and passes the information to the class method for processing.  The method works just fine most of the time.

On one of the iterations I get a error before the code even gets to the class.  The error is, "Arithmetic operation resulted in an overflow."  What strikes me as odd is that while stepping through the code, the loop crashes with that error before getting to the class that runs the calculations.  Additionally, no arethmetic operations are performed on the form's code-behind page (which calls the method).  I even put a break-point on the class constructor but the code crashed before reaching that constructor.

The information being sent is the results of matches from a sporting event.  As a troubleshooting measure I changed the order of the matches by deleting them an re-entering them into the database in a different order.  Again only this one particular match crashed.

Here is the code that crashes:

cRating.SetRating(dMatchDate, iSetID, 8, iHPlayerID, 

Executing method of the Generic class using Reflection.



I have a generic class:

 abstract public class BaseTC<T>:IExecutable where T : Core, new()
    private Type2 testInfo;
    private Type1 settings;
    private T core = null;

and I want to load such class from library the class is located in, and create an instance of it and execute methods later on.

I know how to use non-generic classes, but no idea how to call the same with generics.

very weird method in partial class not listed in intellisense


I have created partial class for winform many times with no problem. When doing the same thing in asp.net I am stucked even with the most basic sample code:


using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

public partial class _Default : System.Web.UI.Page
protected void Page

On clicking a button, call a method with extra arguments


I have a small question about Button.Click events, namely how can I call a method with some extra arguments?

My code is this:

btn.Click += new RoutedEventHandler(Method);

But I would really like it to be of the following form:

btn.Click += new RoutedEventHandler(Method(x));

That is, having an extra argument. However, this does not work.

How can I create something that has the desired operation?

How to visist the method or member of service class?


i have a service interface such as IPublishService(PublishService), and i run the service like below:

Uri publishAddress = new Uri("net.tcp://localhost:8004/QTAServer");
publishHost = new ServiceHost(typeof(PublishService), publishAddress);

suppose the pulishservice has a public member news, how can i visit the news memeber in the server client, i have tried method like below:

PublishService ps = publishHost.SingletonInstance as PublishService;


but it is wrong, why is my method not correct?  is there any other method?

Sequence and Class Diagram of an Existing Website



I want to undertand and change an existing website which was written long time back. It cntains a lot of code and I dont know where to start as there is no dicumentation.

Is there any way by which i can create a class diagram and sequence diagram of the existing one as I want to incorporate all the existing functionalities in the new one and dont miss out anyone. Only way I know is to debug the current application and go through whole of the code individually. Is there any way out by which I can undertand the current application quickly?

Any help is greatly appreciated!



how to inherit a dynamic class from existing base class in C#?

i have created   dynamic class using CodeDom,but now i,want to inherit the dynamic class from my base class...becoz i have created methods in my base class n now i want to inherits these methods from that base clss in  my new dynamic class....plzzzzzzzzzzzz someone help me i have search alottt but didnt find any piece of code...i also tried reflection.emit but i face same problem in Reflection.emit...so plz help me..

My custom class, Why method table only contain 4 methods?

using System;
using System.Text;

namespace C2
{ class TypeSample { TypeSample(int x, int y, int z) { coordinates.x = x; coordinates.y = y; coordinates.z = z; } private struct Coordinates { public int x; public int y; public int z; } private Coordinates coordinates; public void AddCoordinates() { int hashCode = GetHashCode(); lock (this) { Coordinates tempCoord; tempCoord.x = coordinates.x + 100; tempCoord.y = coordinates.y + 50; tempCoord.z = coordinates.z + 100; System.Console.WriteLine("x={0}, y={1}, z={2}", tempCoord.x, tempCoord.y, tempCoord.z); } } static void Main(string[] args) { TypeSample sample = new TypeSample(10,5,10); sample.AddCoordinates(); } } }

I always get 4 methods information in method table.
0:000> dd 009d308c
009d308c  00000000 00000014 00040011 00000004
NO main,  AddCoordinates and ctor
Have no idea of it,  Any help will be appreciated greatly. Thank your help very much!

See details below:

1. Use windbg to open this PE
2. .load sosex.dll
3. !bpsc TypeSample.cs 41
4. !bpsc TypeSample.cs 34
5. g

0:000> !loadby sos.dll mscorwks

Thinking about new C# method prototypes: object as dictionary

I recently had to write a small Flickr API. I know many .Net API for Flickr already exist but I needed one for a Silverlight application. Whatever, it's only about building some querystrings so I did it by myself. It's been an opportunity to think again about a classical question: how to pass parameters to a method ?

Imagine you have a generic method to call some Flickr functions.
ASP.NetWindows Application  .NET Framework  C#  VB.Net  ADO.Net  
Sql Server  SharePoint  Silverlight  Others  All   

Hall of Fame    Twitter   Terms of Service    Privacy Policy    Contact Us    Archives   Tell A Friend