Acceso directo para crear propiedades en Visual Studio?
He visto a algunas personas crear propiedades en C# muy rápido, pero ¿cómo lo hicieron?
¿Qué accesos directos están disponibles en Visual Studio (actualmente usando Visual Studio 2010) para crear propiedades?
Estoy usando C#.
Por ejemplo,
public string myString {get;set;}
16 answers
Puede escribir "prop" y luego presionar tab dos veces. Eso generará lo siguiente.
public TYPE Type { get; set; }
Luego cambia "TYPE " y"Type":
public string myString {get; set;}
También puede obtener la propiedad completa escribiendo "propfull" y luego tabular dos veces. Eso generaría el campo y la propiedad completa.
private int myVar;
public int MyProperty
{
get { return myVar;}
set { myVar = value;}
}
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-03-22 13:00:01
Además de La respuesta de Amra , puedes encontrar otros fragmentos escribiendo
Ctrl + K, Ctrl + X
Que se asigna a Editar.Inserta un código en mi Visual Studio y te muestra la lista completa de fragmentos de código disponibles.
También recuerde que puede configurar sus propios fragmentos utilizando el Administrador de fragmentos, que está disponible en el menú Tools
, Code Snippets Manager...
.
Básicamente se crea un archivo *.snippet
y se utiliza el botón Importar en el Administrador de fragmentos de código para añadirlo a Visual Studio.
Para obtener un tutorial completo, puede ir a los documentos; Tutorial: Crear un fragmento de código.
En Visual Studio los fragmentos de código se manejan de forma ligeramente diferente que en Visual Studio. Puede acceder a todos los fragmentos escribiendo Ctrl + Shift + P y escriba snippet
. Deben existir dos opciones, Insert Snippet
y Preferences: Configure User Snippets
.
El primero inserta un fragmento de su lista de fragmentos (usando el Modo de idioma que puede ver en la barra de estado), y con esta última puede crear sus propios fragmentos para cualquier Modo de idioma.
Si conoce el shortname, puede escribirlo y usar Tab para expandir el fragmento. Para insertar una propiedad C# tiene tres fragmentos de código disponibles, prop
, propfull
, y propg
, para diferentes propósitos.
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
2018-10-04 10:18:41
Coloque el cursor dentro de su campo private int _i;
y luego Edit menu o RMB - Refactor - Encapsulate Field... (CtrlR, CtrlE) para crear el estándar descriptores de acceso.
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-01-25 15:55:28
Escriba "propfull". Es mucho mejor usar, y generará la propiedad y la variable privada.
Escriba "propfull" y luego TAB dos veces.
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-02-21 17:30:18
Después de escribir "prop" + Tab + Tab según lo sugerido por Amra,
puede escribir inmediatamente el tipo de la propiedad (que reemplazará el predeterminado int
), escribir otra pestaña y escribir el nombre de la propiedad (que reemplazará el predeterminado MyProperty). Termina presionando Enter.
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-02-21 17:31:34
Creo que Alt+R+F es el correcto para crear una propiedad a partir de una declaración de variable
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
2012-10-05 11:47:30
Comienza desde:
private int myVar;
Cuando seleccione "myVar" y haga clic derecho, seleccione "Refactor" y seleccione "Encapsular campo".
Creará automáticamente:
{
get { return myVar; }
set { myVar = value; }
}
O puede contextual pulsando Ctrl + R + E.
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-02-21 17:33:40
Cuando escribes en Visual Studio,
public ServiceTypesEnum Type { get; set; }
public string TypeString { get { return this.Type.ToString();}}
ReSharper seguirá sugiriendo convertirlo a:
public string TypeString => Type.ToString();
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-02-21 17:36:01
Ir a
Herramientas > > Opciones > > Editor de texto > > C# > > IntelliSense
En la sección comportamiento de los fragmentos de código:
Asegúrese de que "Incluir siempre fragmentos" esté seleccionado.
Espero que funcione para ti también.
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-11-02 23:12:36
Lo que me gustó en el IDE fue que pude escribir algunas variables como:
private int id;
private string name;
private string version;
private string description;
private string status;
private string symbol;
Observe que los nombres de las variables comienzan con letras pequeñas, y, a continuación, seleccione el bloque entero, y pulse Ctrl+R, Ctrl+E, Aplicar. Las propiedades se generan con la letra mayúscula:
public int Id
{
get
{
return id;
}
set
{
id = value;
}
}
Etc.
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
2018-04-24 19:05:32
ReSharper ofrece generación de propiedades en su extenso conjunto de características. (Sin embargo, no es barato, a menos que estés trabajando en un proyecto de código abierto.)
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-03-22 13:00:45
Type P + Pestaña + Tab .
Cambie el tipo de datos, presione TAB , cambie el nombre de la propiedad y presione End + Introduzca .
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-02-21 17:34:57
Si está utilizando Visual Studio 2013, 2015 o superior, simplemente haga clic en el enlace de abajo. Le dará los accesos directos completos en Visual Studio!
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-02-21 17:37:37
Usando VsVim los fragmentos de código parecen funcionar un poco divertidos. El acceso directo que estaba buscando cuando acabé aquí es mucho más sencillo: después de que un miembro nombre tipo de {g;s;
Tengo el cierre automático del delimitador activado, por lo que la llave de cierre aparece activada {, y escribir un punto y coma activa un autocompletar para obtener y establecer.
Funciona en VS2013 y VS2015, y VS2012 solo carece de la coincidencia automática de llaves.
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-01-26 21:06:59
En la comunidad de visual studio 2017, la clave es ctrl + .
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-07-18 06:26:25
En C#:
private string studentName;
Al final de la línea después del punto y coma(;) Simplemente Presione
Ctrl + R + E
Mostrará una ventana emergente como esta: Al hacer clic de Aplicar o presionar de ENTRAR generará el siguiente código de propiedad:
public string StudentName
{
get
{
return studentName;
}
set
{
studentName = value;
}
}
En VB:
Private _studentName As String
Al final de la línea (después de la cadena) Presione, Asegúrese de colocar _(subrayado) al principio porque agregará un número al final de la propiedad:
Ctrl + R + E
Al hacer clic en Apply o presionar ENTER generará el siguiente código de propiedad con número al final así:
Public Property StudentName As String
Get
Return _studentName
End Get
Set(value As String)
_studentName = value
End Set
End Property
Las propiedades con número son así:
Private studentName As String
Public Property StudentName1 As String
Get
Return studentName
End Get
Set(value As String)
studentName = value
End Set
End Property
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-08-25 12:23:08