Skip to content

Instantly share code, notes, and snippets.

View Nilzor's full-sized avatar

Frode Nilsen Nilzor

  • Forse.no
  • Oslo, Norway
View GitHub Profile
@Nilzor
Nilzor / IDisposableTemplate.cs
Created August 19, 2011 09:08
IDisposable korrekt implementasjon
public class Resource : IDisposable
{
private IntPtr nativeResource = Marshal.AllocHGlobal(100);
private AnotherResource managedResource = new AnotherResource();
// Dispose() calls Dispose(true)
public void Dispose()
{
Dispose(true);
GC.SuppressFinalize(this);
@Nilzor
Nilzor / GenerateInserts.sql
Created September 30, 2011 09:33
MSSQL SP for creating inserts
USE [InfoClient]
GO
/****** Object: StoredProcedure [dbo].[GenerateInserts] Script Date: 09/30/2011 11:32:13 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
ALTER PROC [dbo].[GenerateInserts]
(
@Nilzor
Nilzor / _Items-Enumerator.cs
Created October 13, 2011 16:32
Items-enumerator for NetOffice
/// <summary>
/// Returns an enumerator for the _Items class
/// </summary>
/// <returns>An enumerator for the _Items class</returns>
public IEnumerator GetEnumerator()
{
return new ItemsEnumerator(this);
}
#endregion
@Nilzor
Nilzor / BackgroundLoadingList.cs
Created November 5, 2011 11:30
A CSLA list that loads in the background giving the consumer an option to specifiy a load indicator object
using System;
using System.ComponentModel;
using Csla;
using Csla.Core;
using ErrorEventArgs = Csla.Core.ErrorEventArgs;
namespace Business.Entities
{
public delegate void ExceptionEventHandler(object sender, ErrorEventArgs args);
@Nilzor
Nilzor / DynamicSalutationRulesActivity .cs
Created November 25, 2011 10:17
DynamicSalutationRulesActivity - WF4 dynamic activity
/// <summary>
/// Translates a "MyRule" object to a Sequence of If-Then-Assign-Actions
/// </summary>
public class DynamicSalutationRulesActivity : Activity
{
public InArgument<Person> Person { get; set; }
public DynamicSalutationRulesActivity(List<SalutationAssignmentRule> rules)
{
Common.AddVbSetting(this);
@Nilzor
Nilzor / ICollection.ToString.cs
Created January 18, 2012 15:53
Converts an ICollection of T to a comma separated list of strings
/// <summary>
/// Prints the collection as a comma separated string
/// </summary>
public static string ToStringList<T>(this ICollection<T> list)
{
var sb = new StringBuilder();
int i = 0;
foreach (var elem in list)
{
sb.Append(elem.ToString());
@Nilzor
Nilzor / IEnumerable.ToStringList.cs
Created January 18, 2012 16:53
Converts an IEnumerable list to a comma separated list of string
/// <summary>
/// Prints the collection as a comma separated string
/// </summary>
public static string ToStringList<T>(this IEnumerable<T> list)
{
if (list == null) return String.Empty;
var sb = new StringBuilder();
foreach (var elem in list)
{
@Nilzor
Nilzor / XmlPrettyPrint.cs
Created January 19, 2012 16:13
String to String XML pretty Printer in C#
public string PrettyPrint(string xml)
{
XmlDocument doc = new XmlDocument();
doc.LoadXml(xml);
var sb = new StringBuilder();
var sw = new StringWriter(sb);
var xw = new XmlTextWriter(sw);
xw.Formatting = Formatting.Indented;
doc.WriteTo(xw);
@Nilzor
Nilzor / saveLocalUsersToFile.vbs
Created March 7, 2012 11:47
Saving all local users to a text file
On Error Resume Next
Set objWMIService = GetObject("winmgmts:\\.\root\cimv2")
Set listLocalUsers = objWMIService.ExecQuery("Select * from Win32_UserAccount Where LocalAccount = True")
dim Text
For Each localUser in listLocalUsers
Text = Text & "Short Name: " & localuser.Name
Text = Text & ", Full Name: " & localUser.FullName
Text = Text & ", Description: " & localUser.Description
Text = Text & chr(13)& chr(10)
@Nilzor
Nilzor / SerializationTest.cs
Created March 21, 2012 10:10
Serialization-4.0-fail
[TestClass]
public class SerializationTest
{
[TestMethod]
public void TestSerialize()
{
var serializer = new XmlSerializer(typeof(Entity));
}