TipsOnLips.net

Your .net tips and tricks source

About the author

Author Name is someone.
E-mail me Send mail

Recent comments

Authors

Disclaimer

The opinions expressed herein are my own personal opinions and do not represent my employer's view in anyway.

© Copyright 2010


C#: Convert an ArrayList of strings to a string[] array

To convert an ArrayList to an array of strings, simply do the following:

string[] stringArray = (string[])arrayList.ToArray(typeof(string));

Where arrayList is an ArrayList of strings and stringArray is an array of strings.

 

Source: Click Here


Categories: CSS
Posted by developer on Thursday, August 05, 2010 4:09 AM
Permalink | Comments (0) | Post RSSRSS comment feed

Create Event in C#

Using EventHandler

Declaration: 

        public event EventHandler UserSaved;

        public void OnUserSaved()

        {       

            if (UserSaved != null)       

            {       

               UserSaved(this, EventArgs.Empty);       

            }       

        }   

 

Event Trigger with parameter:

public void OnCustomerSelected(string customerBusinessKey)          
         {             
 
if (!this.CustomerSelected.IsNotNull()) return
;             
 
var e = new CustomerEventArgs

                 {

                  CustomerBusinessKey = customerBusinessKey

                 };             
         

      this.CustomerSelected(this, e);         

          

}


Using Delegate

public delegate void CreateUserControlValidated(object sender, ValidationEventArgs e);

public event CreateUserControlValidated Validated;

 

public class ValidationEventArgs : EventArgs

{

    public virtual IList<string> ClientExceptionList { get; set; }

}

 

Useful Articles: 1


Categories: C#
Posted by Admin on Friday, April 03, 2009 11:02 AM
Permalink | Comments (0) | Post RSSRSS comment feed

NHibernate Inverse="true" Definition

It means non-owner of the relationship whose table doesn't have the foreign key. Similarly, the Hibernate inverse="false" attribute is equivalent to the ... owner of the relationship whose table has the foreign key.

Source:

http://bchavez.bitarmory.com/archive/2007/10/06/nhibernate-and-inversetruefalse-attribute.aspx


Tags: ,
Categories: NHibernate
Posted by developer on Thursday, July 17, 2008 6:54 AM
Permalink | Comments (0) | Post RSSRSS comment feed

Invoke a method via reflection in C#

To invoke a method via reflection including passing parameters and getting a return value, do the following:

First, create a new class library project called ReflectionTut as show in Fig (1) below: [more]

 

 

                                                                           Fig (1) 

 

Then create a class called Utility and insert the code as in Fig (2);

 

                                           Fig (2)

 

Then create a new windows form project and insert the code in Fig (3) behind the form:

 

                                                                                    Fig (3)

The code in fig (3) first loads the class library assembly ReflectionTut.dll via reflection and because we know that we have only one class (or one type), therefore we are choosing the first type via

 Then we create a new instance of the class Utility:

 Then create an object collection for the method (GetTotal) parameters:

 

 

At last we invoke the GetTotal method via reflection and retrieve the return value which is showing in debug mode:

 

Source code: InvokeMethodReflection.rar (38.72 kb) 

 

 


Posted by developer on Wednesday, March 19, 2008 6:02 AM
Permalink | Comments (0) | Post RSSRSS comment feed