Saturday, September 7, 2013

Sitecore PowerShell Extensions Mixing C# and PowerShell



$code = @"
using System;

namespace AwesomeNamespace {
    public enum AwesomeActivityType {
        Nothing,
        Sleeping,
        Eating,
        UsingSPE
    }
    public class AwesomeClass {
        public string DoSomethingAwesome(AwesomeActivityType activity) {
            return String.Format("Your awesome activity is {0}. That's awesome!", activity);
        }
        
        public static string DoSomethingAwesomeAnytime(){
            return "There, their, the're";
        }
    }
}
"@
Add-Type $code

$awesome = New-Object AwesomeNamespace.AwesomeClass
$awesome.DoSomethingAwesome([AwesomeNamespace.AwesomeActivityType]::UsingSPE)
[AwesomeNamespace.AwesomeClass]::DoSomethingAwesomeAnytime()

No comments:

Post a Comment