Skip to content

Instantly share code, notes, and snippets.

@qwertie
Created January 20, 2012 20:02
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save qwertie/1649289 to your computer and use it in GitHub Desktop.
Save qwertie/1649289 to your computer and use it in GitHub Desktop.
C# code snippets for using UpdateControls
<?xml version="1.0" encoding="utf-8" ?>
<CodeSnippets xmlns="http://schemas.microsoft.com/VisualStudio/2005/CodeSnippet">
<CodeSnippet Format="1.0.0">
<Header>
<Title>dep</Title>
<Shortcut>dep</Shortcut>
<Description>Code snippet to help you make properties based on 'Dependent&lt;T&gt;', an Update Controls class that represents a value computed based on one or more Independents. Note: in most cases you should just write a normal property instead of using Dependent&lt;T&gt;. Dependent&lt;T&gt; is useful to cache the result of a computation when the value of the property is expensive to compute.</Description>
<Author>David Piepgrass</Author>
<SnippetTypes>
<SnippetType>Expansion</SnippetType>
</SnippetTypes>
</Header>
<Snippet>
<Declarations>
<Literal>
<ID>type</ID>
<Default>string</Default>
<ToolTip>Data type</ToolTip>
</Literal>
<Literal>
<ID>name</ID>
<Default>CalculatedProperty</Default>
<ToolTip>A name for this computed property</ToolTip>
</Literal>
<Literal>
<ID>expr</ID>
<Default>TODO</Default>
<ToolTip>Write an expression here to compute the value of the Dependent</ToolTip>
</Literal>
</Declarations>
<Code Language="csharp"><![CDATA[Dependent<$type$> _$name$;
public $type$ $name$
{
get {
if (_$name$ == null)
_$name$ = new Dependent<$type$>("$name$",
() => $expr$);
return _$name$.Value;
}
}]]>
</Code>
</Snippet>
</CodeSnippet>
</CodeSnippets>
<?xml version="1.0" encoding="utf-8" ?>
<CodeSnippets xmlns="http://schemas.microsoft.com/VisualStudio/2005/CodeSnippet">
<CodeSnippet Format="1.0.0">
<Header>
<Title>depList</Title>
<Shortcut>depList</Shortcut>
<Description>Code snippet for 'DependentList&lt;T&gt;', which is used to compute a list of values based on a set of other values that utilize Independent, Dependent or other classes in Update Controls.</Description>
<Author>David Piepgrass</Author>
<SnippetTypes>
<SnippetType>Expansion</SnippetType>
</SnippetTypes>
</Header>
<Snippet>
<Declarations>
<Literal>
<ID>type</ID>
<Default>string</Default>
<ToolTip>Data type of each element</ToolTip>
</Literal>
<Literal>
<ID>name</ID>
<Default>List</Default>
<ToolTip>Property Name</ToolTip>
</Literal>
<Literal>
<ID>expr</ID>
<Default>return TODO;</Default>
<ToolTip>Write a LINQ query or other code to compute the list of items as IEnumerable&lt;T%gt;.</ToolTip>
</Literal>
</Declarations>
<Code Language="csharp"><![CDATA[DependentList<$type$> _$name$;
public DependentList<$type$> $name$
{
get {
if (_$name$ == null)
_$name$ = new DependentList<$type$>("$name$", () => {
$expr$
});
return _$name$;
}
}]]>
</Code>
</Snippet>
</CodeSnippet>
</CodeSnippets>
<?xml version="1.0" encoding="utf-8" ?>
<CodeSnippets xmlns="http://schemas.microsoft.com/VisualStudio/2005/CodeSnippet">
<CodeSnippet Format="1.0.0">
<Header>
<Title>ind</Title>
<Shortcut>ind</Shortcut>
<Description>Code snippet for 'Independent&lt;T&gt;'</Description>
<Author>David Piepgrass</Author>
<SnippetTypes>
<SnippetType>Expansion</SnippetType>
</SnippetTypes>
</Header>
<Snippet>
<Declarations>
<Literal>
<ID>type</ID>
<Default>string</Default>
<ToolTip>Data type</ToolTip>
</Literal>
<Literal>
<ID>name</ID>
<Default>Name</Default>
<ToolTip>Property Name</ToolTip>
</Literal>
</Declarations>
<Code Language="csharp"><![CDATA[Independent<$type$> _$name$ = new Independent<$type$>("$name$", default($type$));
public $type$ $name$
{
get { return _$name$.Value; }
set { _$name$.Value = value; }
}]]>
</Code>
</Snippet>
</CodeSnippet>
</CodeSnippets>
<?xml version="1.0" encoding="utf-8" ?>
<CodeSnippets xmlns="http://schemas.microsoft.com/VisualStudio/2005/CodeSnippet">
<CodeSnippet Format="1.0.0">
<Header>
<Title>indList</Title>
<Shortcut>indList</Shortcut>
<Description>Code snippet for 'IndependentList&lt;T&gt;'</Description>
<Author>David Piepgrass</Author>
<SnippetTypes>
<SnippetType>Expansion</SnippetType>
</SnippetTypes>
</Header>
<Snippet>
<Declarations>
<Literal>
<ID>type</ID>
<Default>string</Default>
<ToolTip>Data type of each element</ToolTip>
</Literal>
<Literal>
<ID>name</ID>
<Default>List</Default>
<ToolTip>Property Name</ToolTip>
</Literal>
</Declarations>
<Code Language="csharp"><![CDATA[IndependentList<$type$> _$name$ = new IndependentList<$type$>();
public IList<$type$> $name$
{
get { return _$name$; }
}]]>
</Code>
</Snippet>
</CodeSnippet>
</CodeSnippets>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment