Getting installed powershell version

Ok. you have powershell but you dont know what is the version of it ?
Just write “$host.version” than press enter ūüôā

Advertisements

Optional parameters for functions in c#

C# (before .net 4.0) does not support optional method arguments. However, there may be times when you are using components that were created in a language that supports optional arguments, such as legacy COM components or components created with Microsoft Visual Basic .NET.

class Example {    public void Test()     {        object missing = Type.Missing;       object urlblog = "http://blog.bugrapostaci.com";        VBTestService yourObject = new VBTestService();         // first parameter is url and other 3 are optional in definition of OptionalParameterFuction coded VB        yourObject.OptionalParameterFuction(ref urlblog, ref missing, ref missing, ref missing, ref missing);     } }

Happy Codding…

c# getting day name for specific culture

Here is a small example for getting day name of a date by specific culture:

 

DateTime startDate = DateTime.Now;

DateTime endDate = DateTime.Now.AddDays(2);

 

CultureInfo c = new CultureInfo("tr-TR");

string startDayName = c.DateTimeFormat.DayNames[(int)startDate.DayOfWeek];

string endDayName = c.DateTimeFormat.DayNames[(int)endDate.DayOfWeek];

 

 

Happy Tips.

The given expression is never of the provided warning.

When you try to getting type of Generic variable “T” you get this warning.Here is the sample :

class CauseWarning {     public void make<T>(T value)     {     if (typeof(T) is Test)         Console.Write("Something");     } } public class Test { }

Here is the solution:


class CauseWarning {     public void make<T>(T value)     {     if (typeof(T).IsAssignableFrom(typeof( Test)))         Console.Write("Something");     } } public class Test { }

Type.IsAssignableFrom Method Determines whether an instance of the current Type can be assigned from an instance of the specified Type.true if the c parameter and the current Type represent the same type, or if the current Type is in the inheritance hierarchy of c, or if the current Type is an interface that c supports. false if none of these conditions are the case, or if c is a null reference.

which process lock my dll

Sometimes you want to know whats happinging at the background or wonder which app or process using specific dll. Or may be like me when try to copy a dll getting error “DLL is used by another process” . So what now ?

Process Explorer is one of great tool for this.

Download:

http://download.sysinternals.com/Files/ProcessExplorer.zip

c# setting xmlns root attribute serialization

ńįf you want to ¬†set xmlns attribute when serialization process you can ¬†use XmlRoot attribute namespace .

[Serializable]

[XmlRoot(Namespace= @”http://schemas.microsoft.com/sharepoint/&#8221;) ]

public class Elements

{

public Elements()

{

}

private string _ID;

[XmlAttribute]

public string ID

{

get { return _ID; }

set { _ID = value; }

}

}

happy tips..

Get URL without QueryString in ASP.NET

Is there an easy way to get the url part without the query string of a given Url?

Yeap .

string  sample = Request.Url.GetLeftPart(UriPartial.Path);

Or long way:

string stringUri = “http://blog.bugrapostaci.com/test.aspx?lang=en&#8221;;
Uri uri = new Uri(stringUri);
string query = uri.Query;
string url = stringUri.Substring(0, stringUri.Length – query.Length);

happy tips.bye.