<?xml version="1.0" encoding="utf-8"?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> <html xmlns:MadCap="http://www.madcapsoftware.com/Schemas/MadCap.xsd" MadCap:lastBlockDepth="2" MadCap:lastHeight="120" MadCap:lastWidth="624" MadCap:disableMasterStylesheet="true" MadCap:tocPath="Basics Operations & Concepts|Activation|Transparent Activation|Collections" MadCap:InPreviewMode="false" MadCap:RuntimeFileType="Topic" MadCap:TargetType="WebHelp" MadCap:PathToHelpSystem="../../../../../" MadCap:HelpSystemFileName="index.xml" MadCap:SearchType="Stem"> <head><title>Using TA Collections Directly</title> <script type="text/javascript">/* <![CDATA[ */ window.onload = function(){ var pathToFlash = $('html').attr('MadCap:PathToHelpSystem') + 'Content/Resources/Code/ZeroClipboard.swf'; ZeroClipboard.setMoviePath(pathToFlash); function bindToClipBord(element,content){ var clip = new ZeroClipboard.Client(); clip.setText(content); clip.glue(element); }; if(location.protocol==='file:'){ $('.copylink-marker').remove(); } else{ $('.copylink-marker').each(function(){ var text = $(this).parent().parent().children('.prettyprint').html(); $(this).hover(function(){ bindToClipBord(this,text); }, function(){}); }); } prettyPrint(); }; /* ]]> */</script> <link href="../../../../SkinSupport/MadCap.css" rel="stylesheet" /> <link href="../../../../Resources/Stylesheets/OnlineStyle.css" rel="stylesheet" /> <script src="../../../../Resources/Code/prettify.js"> </script> <script src="../../../../Resources/Code/lang-vb.js"> </script> <script src="../../../../Resources/Code/jquery.min.js"> </script> <script src="../../../../Resources/Code/ZeroClipboard.js"> </script> <script src="../../../../SkinSupport/MadCapAll.js" type="text/javascript"> </script> </head> <body> <p class="MCWebHelpFramesetLink" style="display: none;"><a href="../../../../../index_CSH.html#basics/activation_concept/transparent_activation_framework/collections/use_ta_collections.htm" style="">Open topic with navigation</a> </p> <div class="MCBreadcrumbsBox"><span class="MCBreadcrumbsPrefix">You are here: </span><a class="MCBreadcrumbsLink" href="../../../../basics.htm">Basics Operations & Concepts</a><span class="MCBreadcrumbsDivider"> > </span><a class="MCBreadcrumbsLink" href="../../../activation.htm">Activation</a><span class="MCBreadcrumbsDivider"> > </span><a class="MCBreadcrumbsLink" href="../../transparent_activation_framework.htm">Transparent Activation</a><span class="MCBreadcrumbsDivider"> > </span><span class="MCBreadcrumbs">Using TA Collections Directly</span> </div> <p> <script type="text/javascript">/*<![CDATA[*/document.write('<a href="' + location.href +'">'); document.write("Direct Link"); document.write('</a>');/*]]>*/</script> </p> <p> </p> <h1>Using TA Collections Directly</h1> <p>You can use the transparent activation aware collections directly in your code. They behavior is the same as the <span class="PrimaryPlattform">.NET</span>-collections. Here are a few tips:</p> <ul> <li value="1">Prefer the collection-interfaces over the concrete classes in your field, parameter and return-type declarations. For example declare a field as a <span MadCap:conditions="Primary..NET">IList<T> instead of a List<T></span></li> <li value="2">Maybe it useful to create a collection factory in your code. Then you have only one play in your code which decides which classes are used. So it easy to replace the implementations.</li> </ul> <p>An example:</p> <div class="codesnippet" MadCap:conditions="Primary.c#"> <pre class="prettyprint" xml:space="preserve">public class Team : ActivatableBase { private readonly IList<Pilot> pilots = new ActivatableList<Pilot>(); public void Add(Pilot pilot) { Activate(ActivationPurpose.Write); pilots.Add(pilot); } public ICollection<Pilot> Pilots { get { Activate(ActivationPurpose.Read); return pilots; } } }</pre> <div class="codesnippet-meta">Team.cs: Using the activation aware collections <div class="codedownload"><a href="../../../../CodeExamples/ta/collections/Example-ta-collections-csharp.zip" class="codedownload" MadCap:conditions="Primary.Online">Download Code</a></div><div class="codedownload copylink-marker" MadCap:conditions="Primary.Online"><a href="#copy">Copy Code</a></div></div> </div> <div class="codesnippet" MadCap:conditions="Primary.VB.NET"> <pre class="prettyprint lang-vb" MadCap:conditions="Primary.Online" xml:space="preserve">Public Class Team Inherits ActivatableBase Private ReadOnly m_pilots As IList(Of Pilot) = New ActivatableList(Of Pilot)() Public Sub Add(ByVal pilot As Pilot) Activate(ActivationPurpose.Write) m_pilots.Add(pilot) End Sub Public ReadOnly Property Pilots() As ICollection(Of Pilot) Get Activate(ActivationPurpose.Read) Return m_pilots End Get End Property End Class</pre> <div class="codesnippet-meta">Team.vb: Using the activation aware collections <div class="codedownload"><a href="../../../../CodeExamples/ta/collections/Example-ta-collections-vb.zip" class="codedownload" MadCap:conditions="Primary.Online">Download Code</a></div><div class="codedownload copylink-marker" MadCap:conditions="Primary.Online"><a href="#copy">Copy Code</a></div></div> </div> <p>Currently these collections are available:</p> <ul MadCap:conditions="Primary..NET"> <li value="1">ActivatableList<T>: An activatable version of the List<T>-class</li> <li value="2">ActivatableDictionary<T>: An activatable version of the Dictionary<T></li> </ul> <script type="text/javascript" src="../../../../SkinSupport/MadCapBodyEnd.js"> </script> </body> </html>