Macros
Messages   Related Types
This message was discovered on ASPFriends.com 'aspngcodegiveawayswap' list.


Twomley, Jonathan
-- Moved from [ngfx-io] to [aspngcodegiveawayswap] by Alex Lowe <Click here to reveal e-mail address> --

Does anyone have any macros that they would like to share with all of us?

Reply to this message...
 
    
Glenn Cook
I have been using a collection of C# conditional macros for VS.NET
that I found at codeproject.com that are quite useful.
http://www.codeproject.com/macro/vscsharpmacros.asp" target="_blank">http://www.codeproject.com/macro/vscsharpmacros.asp

They have several others you might be interested in as well:
http://www.codeproject.com/macro/#VS.NET%20Macros

Take Care,
Glenn Cook

---------- Original Message ----------------------------------
From: "Twomley, Jonathan" <Click here to reveal e-mail address>
Reply-To: "aspngcodegiveawayswap"
<Click here to reveal e-mail address>
Date: Thu, 15 Aug 2002 07:45:41 -0700

>-- Moved from [ngfx-io] to [aspngcodegiveawayswap] by Alex Lowe
<Click here to reveal e-mail address> --
[Original message clipped]

________________________________________________________________
Sent via the Mail Systems at planetdev.com

Reply to this message...
 
    
Andy Smith
here's a macro I wrote which makes public properties in c#,vb, and =
jscript.
I don't know if this is the "best" way to do it, but it works.
just put the cursor where you want the property, and start the macro.

Public Module MakeFoo

Sub MakeProperty()
' Get property info from user
Dim propertyType As String =3D InputBox("Property Type?")
If propertyType =3D "" Then Return

Dim propertyName As String =3D InputBox("Property Public Name?")
If propertyName =3D "" Then Return

Dim propertyPrivateName As String =3D InputBox("Property Private =
Name?", , GeneratePrivateName(propertyName))
If propertyPrivateName =3D "" Then Return

' Create a code generator
Dim provider As CodeDomProvider
Dim generator As ICodeGenerator
Dim codeString As System.IO.StringWriter
Dim options As New CodeGeneratorOptions()

If DTE.ActiveDocument.FullName.ToLower().EndsWith(".vb") Then
provider =3D New Microsoft.VisualBasic.VBCodeProvider()
ElseIf DTE.ActiveDocument.FullName.ToLower().EndsWith(".cs") =
Then
provider =3D New Microsoft.CSharp.CSharpCodeProvider()
ElseIf DTE.ActiveDocument.FullName.ToLower().EndsWith(".js") =
Then
provider =3D New Microsoft.JScript.JScriptCodeProvider()
Else
Return
End If

generator =3D provider.CreateGenerator()

' make sure the user entered valid variable names
propertyName =3D generator.CreateValidIdentifier(propertyName)
propertyPrivateName =3D =
generator.CreateValidIdentifier(propertyPrivateName)

' create the public property
Dim newProperty As New CodeMemberProperty()
newProperty.Name =3D propertyName
newProperty.Type =3D New CodeTypeReference(propertyType)
newProperty.Attributes =3D MemberAttributes.Public
newProperty.HasGet =3D True
newProperty.HasSet =3D True

Dim getter As New CodeMethodReturnStatement()
getter.Expression =3D New =
CodeVariableReferenceExpression(propertyPrivateName)
newProperty.GetStatements.Add(getter)

Dim setter As New CodeAssignStatement()
setter.Left =3D New =
CodeVariableReferenceExpression(propertyPrivateName)
setter.Right =3D New CodePropertySetValueReferenceExpression()
newProperty.SetStatements.Add(setter)

' create the private field
Dim privateDeclaration As New =
CodeVariableDeclarationStatement(propertyType, propertyPrivateName)

'Generate The Code And Add It To The Document

'HACK i wrap this with a class because the generator can't =
generate from the property by itself
Dim hackType As New CodeTypeDeclaration("hack")
hackType.IsClass =3D True
hackType.Members.Add(newProperty)
codeString =3D New StringWriter()
generator.GenerateCodeFromType(hackType, codeString, New =
CodeGeneratorOptions())
Dim myCode As String =3D codeString.ToString()
myCode =3D RemoveHackClass(myCode)
'ENDHACK

Dim mySelection As TextSelection =3D =
DTE.ActiveDocument.Selection
mySelection.Insert(myCode, =
vsInsertFlags.vsInsertFlagsInsertAtEnd)
mySelection.LineDown()
mySelection.NewLine()

codeString =3D New StringWriter()
generator.GenerateCodeFromStatement(privateDeclaration, =
codeString, New CodeGeneratorOptions())
mySelection.Text =3D codeString.ToString()

End Sub

Private Function GeneratePrivateName(ByVal publicName As String) As =
String
If DTE.ActiveDocument.FullName.ToLower().EndsWith(".vb") Then
Return "m" & publicName
ElseIf DTE.ActiveDocument.FullName.ToLower().EndsWith(".cs") =
Then
Return publicName.Substring(0, 1).ToLower() & =
publicName.Substring(1)
ElseIf DTE.ActiveDocument.FullName.ToLower().EndsWith(".js") =
Then
Return "_" & publicName
Else
Return String.Empty
End If
End Function

Private Function RemoveHackClass(ByVal hack As String) As String
Dim unHack As String =3D hack
unHack =3D =
unHack.Substring(unHack.IndexOf(System.Environment.NewLine))
unHack =3D unHack.Substring(0, =
unHack.LastIndexOf(System.Environment.NewLine))
unHack =3D unHack.Substring(0, =
unHack.LastIndexOf(System.Environment.NewLine))
Return unHack
End Function

End Module

__
Andy Smith
Keyboard Jockey #3a7-2.78.1

Reply to this message...
 
 
Microsoft.CSharp.CSharpCodeProvider
Microsoft.JScript.JScriptCodeProvider
Microsoft.VisualBasic.VBCodeProvider
System.CodeDom.CodeAssignStatement
System.CodeDom.CodeMemberProperty
System.CodeDom.CodeMethodReturnStatement
System.CodeDom.CodePropertySetValueReferenceExpression
System.CodeDom.CodeTypeDeclaration
System.CodeDom.CodeTypeReference
System.CodeDom.CodeVariableDeclarationStatement
System.CodeDom.CodeVariableReferenceExpression
System.CodeDom.Compiler.CodeDomProvider
System.CodeDom.Compiler.CodeGeneratorOptions
System.CodeDom.Compiler.ICodeGenerator
System.CodeDom.MemberAttributes
System.Environment
System.IO.StringWriter
System.String




Ad
MBR BootFX
Best-of-breed application framework for .NET projects, developed by Matthew Baxter-Reynolds and MBR IT
 
 Copyright © Matthew Baxter-Reynolds 2001-2008. '.NET 247 Software Development Services' is a trading style of MBR IT Solutions Ltd.
Contact Us - Terms of Use - Privacy Policy - www.dotnet247.com