Microsoft – Powershell / Microsoft .Net C# / Interaction-Interface

Microsoft .Net Class – friend.cs



using System;
using System.Collections.Generic;
using System.Collections;

public class friend
{

	ArrayList objListofFriends = null;

	public friend()
	{
		objListofFriends = new ArrayList();
	}

	public void clearLists()
	{
		objListofFriends.Clear();
	}

	public void friendAdd(String friend)
	{
		objListofFriends.Add(friend);
	}

	public void friendAddRange(ArrayList objList)
	{
		objListofFriends.AddRange(objList);
	}

	// return list of Friend
	public ArrayList listofFriends
	{
		get
		{
			
		   return (objListofFriends);
		   
		}
		
	}

}


Microsoft Powershell Class


 $file = 'friend.cs';
$fileFullPath = resolve-path $file;
$Source = [System.IO.File]::ReadAllText($file);

$strLogFormat = "Friend list - Type {0} and # of Entries {1}";
 
$strLog = "Importing Files :- fileFullPath: {0}"`
       -f $fileFullPath
	   
Write-Debug $strLog
Add-Type -TypeDefinition $Source -Language CSharpVersion3;
 
$objFriend = New-Object friend;
 
#To add friends

$objFriend.friendAdd("John Smith");

$objFriend.friendAdd("Sandra B.")
 
# to get list of friends
[array] $objList = $null;
$objList = [array] $objFriend.listofFriends;
 
# to get object type and number of entries

$strLog = $strLogFormat -f $objList.getType(), $objList.Length;

Write-Host($strLog);
 

Leave a Reply

Please log in using one of these methods to post your comment:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s