Formatear parámetros literales de un fragmento de código C #


¿Hay alguna forma de que pueda cambiar cómo se renderiza un Literal de un fragmento de código cuando se usa en el código que genera el fragmento?

Específicamente me gustaría saber si puedo tener un literal llamado say, Proper propertyName and y luego obtener el motor de fragmentos para renderizar "_ _ propertyName where donde el primer carácter se hace en minúsculas.

No puedo permitirme R#. Por favor ayuda :)

Author: Michael Lang, 2008-10-03

3 answers

Desafortunadamente parece que no hay manera. Los fragmentos de código ofrecen un soporte increíblemente limitado para funciones de transformación como puede ver.

Hay que seguir con la solución estándar VS, que consiste en escribir dos literales: uno para el nombre de la propiedad y el otro para el nombre de la variable miembro.

 21
Author: Caerbanog,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2015-10-16 18:22:32

Una "solución" puede ser usar un prefijo en el nombre o la variable miembro, es decir:

string m_$name$;
string $name$
{
 get{return m_$name$;}
 set{m_$name$=value;}
};
 4
Author: fred,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2013-08-17 13:06:43

Puede introducir una primera letra superior, luego un nombre de propiedad, luego una primera letra inferior. Prueba este fragmento:

<?xml version="1.0" encoding="utf-8"?>
<CodeSnippet Format="1.0.0" xmlns="http://schemas.microsoft.com/VisualStudio/2005/CodeSnippet">
  <Header>
    <Title>Notifiable Property</Title>
    <Author>Nikolay Makhonin</Author>
    <Shortcut>propn</Shortcut>
    <Description>Property With in Built Property Changed method implementation.</Description>
    <SnippetTypes>
      <SnippetType>SurroundsWith</SnippetType>
      <SnippetType>Expansion</SnippetType>
    </SnippetTypes>
  </Header>
  <Snippet>
    <Declarations>
        <Literal>
            <ID>Type</ID>
            <Default>Type</Default>
        </Literal>
        <Literal>
            <ID>P</ID>
            <Default>P</Default>
        </Literal>
        <Literal>
            <ID>roperty</ID>
            <Default>ropertyName</Default>
        </Literal>
        <Literal>
            <ID>p</ID>
            <Default>p</Default>
        </Literal>
        <Literal>
            <ID>Ownerclass</ID>
            <ToolTip>The owning class of this Property.</ToolTip>
            <Function>ClassName()</Function>
            <Default>Ownerclass</Default>
        </Literal>
    </Declarations>
    <Code Language="CSharp">
      <![CDATA[#region $P$$roperty$

        private Field<$Type$> _$p$$roperty$;
        public static readonly string $P$$roperty$PropertyName = GetPropertyName(() => (($Ownerclass$)null).$P$$roperty$);
        public $Type$ $P$$roperty$
        {
            get { return _$p$$roperty$; }
            set { Set(ref _$p$$roperty$, value); }
        }

        #endregion

]]>
    </Code>
  </Snippet>
</CodeSnippet>
 1
Author: Nikolay Makhonin,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2017-12-13 09:39:00