6
6

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

Xamarinは非常に素晴らしいクロスプラットフォームの開発環境だと思いますが、たまにコードを書くのがかなり長くなる時があり以外と億劫になりがちです。(私だけかもしれませんが)
という事で、今回はVisual Studio向けのコードスニペットを幾つか置いておきたいと思います
今の所はBindablePropertyのスニペットくらいですが、今後も幾つか種類を増やしていこうかと思っています
なお、ここに記載されているスニペットのいくつかはネット上の記事を参考に書きました。

BindablePropertyを作成するスニペット

BindablePropertyのみ生成するスニペット

<?xml version="1.0" encoding="utf-8"?>
<CodeSnippets xmlns="http://schemas.microsoft.com/VisualStudio/2005/CodeSnippet">
  <CodeSnippet Format="1.0.0">
    <Header>
      <SnippetTypes>
        <SnippetType>Expansion</SnippetType>
      </SnippetTypes>
      <Title>bprop</Title>
      <Author>Microsoft Corporation</Author>
      <Description>Code snippet</Description>
      <HelpUrl>
      </HelpUrl>
      <Shortcut>bprop</Shortcut>
    </Header>
    <Snippet>
      <Declarations>
        <Literal Editable="true">
          <ID>name</ID>
          <ToolTip>name</ToolTip>
          <Default>name</Default>
          <Function>
          </Function>
        </Literal>
        <Literal Editable="true">
          <ID>owner</ID>
          <ToolTip>owner</ToolTip>
          <Default>Owner</Default>
          <Function>
          </Function>
        </Literal>
        <Literal Editable="true">
          <ID>type</ID>
          <ToolTip>type</ToolTip>
          <Default>Type</Default>
          <Function>
          </Function>
        </Literal>
      </Declarations>
      <Code Language="csharp"><![CDATA[public static readonly BindableProperty $name$Property = BindableProperty.Create(nameof($name$), typeof($type$), typeof($owner$), default($type$));

public $type$ $name$
{
    get { return ($type$)GetValue($name$Property); }
    set { SetValue($name$Property, value); }
}$end$]]></Code>
    </Snippet>
  </CodeSnippet>
</CodeSnippets>

PropertyChangedメソッドも生成するスニペット

<?xml version="1.0" encoding="utf-8"?>
<CodeSnippets xmlns="http://schemas.microsoft.com/VisualStudio/2005/CodeSnippet">
  <CodeSnippet Format="1.0.0">
    <Header>
      <SnippetTypes>
        <SnippetType>Expansion</SnippetType>
      </SnippetTypes>
      <Title>bpropc</Title>
      <Author>Microsoft Corporation</Author>
      <Description>Code snippet</Description>
      <HelpUrl>
      </HelpUrl>
      <Shortcut>bpropc</Shortcut>
    </Header>
    <Snippet>
      <Declarations>
        <Literal Editable="true">
          <ID>name</ID>
          <ToolTip>name</ToolTip>
          <Default>name</Default>
          <Function>
          </Function>
        </Literal>
        <Literal Editable="true">
          <ID>owner</ID>
          <ToolTip>owner</ToolTip>
          <Default>Owner</Default>
          <Function>
          </Function>
        </Literal>
        <Literal Editable="true">
          <ID>type</ID>
          <ToolTip>type</ToolTip>
          <Default>Type</Default>
          <Function>
          </Function>
        </Literal>
      </Declarations>
      <Code Language="csharp">
        <![CDATA[public static readonly BindableProperty $name$Property = BindableProperty.Create(nameof($name$), typeof($type$), typeof($owner$), default($type$), propertyChanged: (obj, o, n) => (($owner$)obj).$name$PropertyChanged(($type$)o, ($type$)n));

private void $name$PropertyChanged($type$ oldValue, $type$ newValue)
{
}

public $type$ $name$
{
    get { return ($type$)GetValue($name$Property); }
    set { SetValue($name$Property, value); }
}$end$]]></Code>
    </Snippet>
  </CodeSnippet>
</CodeSnippets>
6
6
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
6
6

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?