我在哪里可以下载 Visual Studio 的片段,比如 pf pmvx、cmvx 等?我虽然这些将在 github 项目中可用,但找不到它们......
问问题
2692 次
4 回答
18
我已经创建了自己的。请记住,这些是 ReSharper 的模板。
mvxcom -> 用于命令
#region $region$ command
private MvxCommand _$NAME$Command;
public ICommand $PNAME$Command
{
get
{
_$NAME$Command = _$NAME$Command ?? new MvxCommand(Do$PNAME$Command);
return _$NAME$Command;
}
}
private void Do$PNAME$Command()
{
$END$
}
#endregion
mvxprop -> 用于属性
#region $region$
private $TYPE$ _$NAME$;
public $TYPE$ $PNAME$
{
get { return _$NAME$; }
set { _$NAME$ = value; RaisePropertyChanged(() => $PNAME$); }
}
#endregion
$END$
mvxset -> 绑定集
var set = this.CreateBindingSet<$VIEW$, $VIEW$Model>();
set.Bind($ELEMENT$).To(vm => vm$END$);
set.Apply();
您可以使用 ReSharper>Template Explorer>Live Templates>New Template 将它们添加到您的 ReSharper。
请随意更改它们,但你愿意。
于 2013-08-15T07:06:15.060 回答
6
这是基于上述 Aboo 回答的原生 VS 版本的片段。
<?xml version="1.0" encoding="utf-8"?>
<CodeSnippets xmlns="http://schemas.microsoft.com/VisualStudio/2005/CodeSnippet">
<CodeSnippet Format="1.0.0">
<Header>
<Title>MvvMCross Property</Title>
<Description>Insert a property block with a backing field and property change notification</Description>
<Shortcut>mvxprop</Shortcut>
<Author>Andrew Coates (based on Aboo's SO ReSharper Answer)</Author>
<HelpUrl>http://stackoverflow.com/questions/18200679/mvvmcross-code-snippets-for-visual-studio</HelpUrl>
</Header>
<Snippet>
<Declarations>
<Literal>
<ID>backingfield</ID>
<ToolTip></ToolTip>
<Default>propertyName</Default>
</Literal>
<Literal>
<ID>property</ID>
<ToolTip></ToolTip>
<Default>PropertyName</Default>
</Literal>
<Literal>
<ID>propertyType</ID>
<ToolTip></ToolTip>
<Default>int</Default>
</Literal>
</Declarations>
<Code Language="CSharp">
<![CDATA[private $propertyType$ $backingfield$;
public $propertyType$ $property$
{
get { return $backingfield$; }
set { if($backingfield$ == value) return; $backingfield$ = value; RaisePropertyChanged(() => $property$); }
}
$end$]]>
</Code>
</Snippet>
</CodeSnippet>
<CodeSnippet Format="1.0.0">
<Header>
<Title>MvvMCross Command</Title>
<Description>Insert a Command declaration for an MvvMCross View Model</Description>
<Shortcut>mvxcom</Shortcut>
<Author>Andrew Coates (based on Aboo's SO ReSharper Answer)</Author>
<HelpUrl>http://stackoverflow.com/questions/18200679/mvvmcross-code-snippets-for-visual-studio</HelpUrl>
</Header>
<Snippet>
<Declarations>
<Literal>
<ID>backingfield</ID>
<ToolTip></ToolTip>
<Default>commandName</Default>
</Literal>
<Literal>
<ID>Name</ID>
<ToolTip></ToolTip>
<Default>CommandName</Default>
</Literal>
</Declarations>
<Code Language="CSharp">
<![CDATA[private MvxCommand $backingfield$Command;
public MvxCommand $Name$Command
{
get
{
$backingfield$Command = $backingfield$Command ?? new MvxCommand(Do$Name$Command);
return $backingfield$Command;
}
}
private void Do$Name$Command()
{
$end$
}
]]>
</Code>
</Snippet>
</CodeSnippet>
<CodeSnippet Format="1.0.0">
<Header>
<Title>MvvMCross Binding Set</Title>
<Description>Create a binding set and bind an element</Description>
<Shortcut>mvxset</Shortcut>
<Author>Andrew Coates (based on Aboo's SO ReSharper Answer)</Author>
<HelpUrl>http://stackoverflow.com/questions/18200679/mvvmcross-code-snippets-for-visual-studio</HelpUrl>
</Header>
<Snippet>
<Declarations>
<Literal>
<ID>viewName</ID>
<ToolTip></ToolTip>
<Default>viewName</Default>
</Literal>
<Literal>
<ID>element</ID>
<ToolTip></ToolTip>
<Default>element</Default>
</Literal>
</Declarations>
<Code Language="CSharp">
<![CDATA[var set = this.CreateBindingSet<$viewName$View, $viewName$ViewModel>();
set.Bind($element$).To(vm => vm$end$);
set.Apply();
]]>
</Code>
</Snippet>
</CodeSnippet>
</CodeSnippets>
于 2014-03-01T05:58:23.477 回答
3
如果我的假设是正确的,那么您指的是 Stuart 在他的 MvvmCross 演示中使用的快捷方式。这些是他使用 ReSharper 编写并分配给快捷方式的代码片段,不公开提供,但如果您问得好,它们可以导出和共享。当然,您可以随时使用本教程制作自己的“实时模板”
于 2013-08-13T10:18:33.100 回答
1
我修改了@Coasty 的答案以包含一个改编自https://stackoverflow.com/questions/17187113/how-can-i-use-async-in-an-mvvmcross-view-model的异步命令并更改了快捷方式,因此它们没有不再与 mvx 命名空间发生冲突。
<?xml version="1.0" encoding="utf-8"?>
<CodeSnippets xmlns="http://schemas.microsoft.com/VisualStudio/2005/CodeSnippet">
<CodeSnippet Format="1.0.0">
<Header>
<Title>MvvmCross Property</Title>
<Description>Insert a property block with a backing field and property change notification</Description>
<Shortcut>mvvmcrossprop</Shortcut>
<Author>Andrew Coates (based on Aboo's SO ReSharper Answer)</Author>
<HelpUrl>https://stackoverflow.com/questions/18200679/MvvmCross-code-snippets-for-visual-studio</HelpUrl>
</Header>
<Snippet>
<Declarations>
<Literal>
<ID>backingfield</ID>
<ToolTip></ToolTip>
<Default>propertyName</Default>
</Literal>
<Literal>
<ID>property</ID>
<ToolTip></ToolTip>
<Default>PropertyName</Default>
</Literal>
<Literal>
<ID>propertyType</ID>
<ToolTip></ToolTip>
<Default>int</Default>
</Literal>
</Declarations>
<Code Language="CSharp">
<![CDATA[private $propertyType$ $backingfield$;
public $propertyType$ $property$
{
get { return $backingfield$; }
set { $backingfield$ = value; RaisePropertyChanged(() => $property$); }
}
$end$]]>
</Code>
</Snippet>
</CodeSnippet>
<CodeSnippet Format="1.0.0">
<Header>
<Title>MvvmCross Command</Title>
<Description>Insert a Command declaration for an MvvmCross View Model</Description>
<Shortcut>mvvmcrosscom</Shortcut>
<Author>Andrew Coates (based on Aboo's SO ReSharper Answer)</Author>
<HelpUrl>https://stackoverflow.com/questions/18200679/MvvmCross-code-snippets-for-visual-studio</HelpUrl>
</Header>
<Snippet>
<Declarations>
<Literal>
<ID>backingfield</ID>
<ToolTip></ToolTip>
<Default>commandName</Default>
</Literal>
<Literal>
<ID>Name</ID>
<ToolTip></ToolTip>
<Default>CommandName</Default>
</Literal>
</Declarations>
<Code Language="CSharp">
<![CDATA[private MvxCommand $backingfield$Command;
public MvxCommand $Name$Command
{
get
{
$backingfield$ = $backingfield$ ?? new MvxCommand(Do$Name$);
return $backingfield$;
}
}
private void Do$Name$()
{
$end$
}
]]>
</Code>
</Snippet>
</CodeSnippet>
<CodeSnippet Format="1.0.0">
<Header>
<Title>MvvmCross Async Command</Title>
<Description>Insert an Async Command declaration for an MvvmCross View Model</Description>
<Shortcut>mvvmcrossacom</Shortcut>
<Author>Benjamin Hysell (based on Andrew Coates Command Answer)</Author>
<HelpUrl>https://stackoverflow.com/questions/18200679/MvvmCross-code-snippets-for-visual-studio</HelpUrl>
</Header>
<Snippet>
<Declarations>
<Literal>
<ID>backingfield</ID>
<ToolTip></ToolTip>
<Default>commandName</Default>
</Literal>
<Literal>
<ID>Name</ID>
<ToolTip></ToolTip>
<Default>CommandName</Default>
</Literal>
</Declarations>
<Code Language="CSharp">
<![CDATA[private MvxCommand $backingfield$Command;
public MvxCommand $Name$Command
{
get
{
$backingfield$ = $backingfield$ ?? new MvxCommand(async () => await Do$Name$());
return $backingfield$;
}
}
private async Task Do$Name$()
{
$end$
}
]]>
</Code>
</Snippet>
</CodeSnippet>
<CodeSnippet Format="1.0.0">
<Header>
<Title>MvvmCross Binding Set</Title>
<Description>Create a binding set and bind an element</Description>
<Shortcut>mvvmcrossset</Shortcut>
<Author>Andrew Coates (based on Aboo's SO ReSharper Answer)</Author>
<HelpUrl>https://stackoverflow.com/questions/18200679/MvvmCross-code-snippets-for-visual-studio</HelpUrl>
</Header>
<Snippet>
<Declarations>
<Literal>
<ID>viewName</ID>
<ToolTip></ToolTip>
<Default>viewName</Default>
</Literal>
<Literal>
<ID>element</ID>
<ToolTip></ToolTip>
<Default>element</Default>
</Literal>
</Declarations>
<Code Language="CSharp">
<![CDATA[var set = this.CreateBindingSet<$viewName$View, $viewName$ViewModel>();
set.Bind($element$).To(vm => vm$end$);
set.Apply();
]]>
</Code>
</Snippet>
</CodeSnippet>
</CodeSnippets>
于 2015-03-16T18:23:17.207 回答