Skip to content

Instantly share code, notes, and snippets.

View petarvucetin's full-sized avatar

Petar Vučetin petarvucetin

  • Clear Lines
  • Los Angeles
View GitHub Profile
@petarvucetin
petarvucetin / MemberOf.cs
Created April 18, 2017 03:57
Using reflection to get property name expressed as lambda
using System;
using System.Linq.Expressions;
using System.Reflection;
namespace Infrastructure
{
/// <summary>
/// Class for easily getting information about a type member,
/// and referencing the member by name, or getting it as a
@petarvucetin
petarvucetin / CrmEntityExtensions.cs
Created March 31, 2016 02:34
Useful extension methods for strongly typed access to CRM Entites
public static class CrmEntityExtensions
{
public static OptionSetValue ToOptionSetValue(this Enum e)
{
if (e.GetTypeCode() != TypeCode.Int32)
return null;
var val = (int)Convert.ChangeType(e, e.GetTypeCode());
return new OptionSetValue(val);
@petarvucetin
petarvucetin / Validate-Credentials.ps1
Created April 2, 2015 16:02
PS: Validate-Credentials
function Validate-Credentials([System.Management.Automation.PSCredential]$credentials)
{
$ct = [System.DirectoryServices.AccountManagement.ContextType]::Domain
$nc = $credentials.GetNetworkCredential()
$principal = $nc.Domain.ToString() + "\"+ $nc.UserName.Tostring()
$pctx = New-Object System.DirectoryServices.AccountManagement.PrincipalContext($ct, "axaros.com")
return $pctx.ValidateCredentials($nc.UserName, $nc.Password)
}
public class SelectionList<T> :
ObservableCollection<SelectionItem<T>> where T : IComparable<T>
{
public event EventHandler OnItemSelectionChange;
#region Properties
/// <summary>
/// Returns the selected items in the list
/// </summary>
using System;
using log4net;
using PostSharp.Laos;
// http://exceptionalcode.wordpress.com/2010/02/17/centralizing-vsto-add-in-exception-management-with-postsharp/
namespace Helpers.Vsto.ErrorHandling
{
[Serializable]
public sealed class ExecutionEntryPointAttribute : OnExceptionAspect
namespace AzManWrapperLib
{
using AZROLESLib;
using System;
using System.Runtime.InteropServices;
using System.Security.Principal;
public class AzManAccessControlChecker : IAccessControlChecker, IDisposable
{
#region Private Fields
@petarvucetin
petarvucetin / PrivateReflectionDynamicObject.cs
Created May 12, 2014 17:11
Using dynamic to simplify reflection via David Ebb
using System;
using System.Collections.Concurrent;
using System.Collections.Generic;
using System.Dynamic;
using System.Linq;
using System.Reflection;
namespace Core.Common
{
@petarvucetin
petarvucetin / VisitorPattern.cs
Last active January 4, 2016 07:59
Using a visitor pattern to build a log message out of parameters passed to WCF.
using System;
using System.Collections;
using System.Collections.Concurrent;
using System.Collections.Generic;
using System.Dynamic;
using System.Linq;
using System.Reflection;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
@petarvucetin
petarvucetin / EnumExtensions.cs
Last active January 4, 2016 05:19
Missing enum BCL extensions
using System;
using System.Collections.Generic;
using System.Globalization;
using System.Linq;
namespace iFX.Core
{
public static class EnumExtensions
{
public static T FromString<T>(this Enum e, string value)
@petarvucetin
petarvucetin / SelectionItem<T>.cs
Created October 15, 2013 16:49
SelectionItem<T> and SelectionList<T> for WPF
using System;
using System.ComponentModel;
namespace ClearLines.iFX.WPF
{
public class SelectionItem<T> : INotifyPropertyChanged
{
#region Fields