Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

In Method Argument Scope? #23

Open
Mike-E-angelo opened this issue Jan 4, 2016 · 2 comments
Open

In Method Argument Scope? #23

Mike-E-angelo opened this issue Jan 4, 2016 · 2 comments

Comments

@Mike-E-angelo
Copy link

I use PostSharp and I am finding myself using a lot of contract guards for my method attributes. It would be nice to make these ZenSharp templates and I am wondering if there is a scope to enable in method definitions?

@Mike-E-angelo
Copy link
Author

Sounds like a no. 😉

@Mike-E-angelo
Copy link
Author

Mike-E-angelo commented Feb 26, 2018

In case anyone else is interested, I was able to work around this by using InCSharpFile:

scope "InCSharpFile" {
  start ::= ""="T" type | ""=P parameter
}

So now when I hit T or P I get access to the type selection offered by ZenSharp, or a type selection followed by a parameter, respectively.

I actually got quite a bit implemented in the past day learning and configuring my ZenSharp template (finally 😆). In addition to the default behaviors I have added support for generic arguments for methods and classes, as well as multiple parameter definitions for methods. ZenSharp handles recursive templates, so that is pretty nice. I've also added a template generator for extension methods which have always been a hassle for me. Here is the file in case anyone might find it of interest/value:

// C# templates
space ::= " "
cursor ::= "$END$"

// Resharper macros:
identifier ::= <name default="$name$" macros = "suggestVariableName()">
suggest ::= <type default="$type$" macros = "completeType()">

// Common:
access ::= ((internal=i | public=p | private=_ | protected=r) space)?
name ::= space identifier (""="`" "<" <T1 default="$T1$" macros = "complete()"> (", "="`" <T2 default="$T2$" macros = "complete()">)? ">")?

// Primive types:
type      ::= (known | primitive ("?"="?")? | suggest) ("[]"=a)?
primitive ::= string=s | byte=bY | bool=b | "System.DateTime"=dT | decimal=dC | double=d | int=i | uint=uI | "System.Guid"=g | "System.Uri"=u | "System.Xml.Linq.XElement"=x |
			   object=o

// Complex types:
observable  ::= "System.IObservable"=O definition
action  ::= "System.Action"=A definition
func ::= "System.Func"=F definition
func2 ::= "System.Func"=F2 definition2
funcB ::= "System.Func<"=FB type ", bool>"
array    ::= "System.Collections.Immutable.ImmutableArray"=I definition
generic1 ::= (SCG ("IList"=l | "IEnumerable"="~")) definition
generic2 ::= (SCG ("SortedList"=sl | "IDictionary"=di)) definition2
SCG      ::= "System.Collections.Generic."
definition ::= "<" type ">"
definition2 ::= "<" type ", " type ">"

// Custom:
command  ::= "DragonSpark.ICommand"=C definition
source  ::= "DragonSpark.Sources.ISource"="S1" definition
source2  ::= "DragonSpark.Sources.ISource"="S2" definition2
specification ::= "DragonSpark.Specifications.ISpecification"="S3" definition
custom ::= command | source | source2 | specification

known ::= generic1 | generic2 | array | action | func | func2 | funcB | custom

// Auto properties:
property        ::= access ("abstract "=ap | "static "=P | "virtual "=vp | ""=p) type space identifier propertyBody cursor
propertyBody    ::= "{ get;" propertySetAccessor " set; }"
propertySetAccessor ::= "protected "="+p" | ""="+" | "private "

// Methods:
constructor ::= "public "="C" <ctor default="$ctor$" macros="typeName();completeSmart()"> "(" parameters cursor") {}"
method ::= access ("virtual "=vm | "abstract "=am | "static "=M | ""=m) declaration "(" parameters ")" methodBody
declaration ::= (type | "void") name
methodBody ::= " { " cursor " }"
parameter ::= type space identifier (", "="," parameter)?
extension ::= "public static "=x declaration "(this "=":" type " @this" (", " parameter)? ")" methodBody

// Consts:
const ::= access "const "=c primType space identifier "= """ identifier """;"

// Fields:
// field ::= "readonly "=r type space identifier ("="="=" identifier2 ";" | ";")

// Classes:
class ::= className classExtend
className ::= access (("sealed "=s) | ("static "=S))? ("class"=c) name
classExtend ::= (extend (""="B" body)?) | body
extend ::= " : "=" " type
body ::= "{" cursor "}"

//Enums:
enum ::= access space "enum"=e space identifier body

scope "InCSharpFile" {
  start ::= ""="_" type (""=" " space identifier)? | "params "="P+" type "[]" identifier | ""="tia" <array default="$array$" macros="enumerableVariable())"> ".ToImmutableArray()"
}

scope "InCSharpClass" {
  start ::= constructor | method | extension | property | const | ""=tf "[Fact] public void " identifier "(){" cursor "}"
}

//| ""=ts "[Theory, AutoData] public void " identifier "( " identifier " sut ){" cursor "}"

scope "InCSharpTypeAndNamespace" {
  start ::=
	| class
	| interface
	| enum

  interface ::= access "interface "=i "I" identifier extend body

}

scope "InCSharpInterface" {
  start ::=
	| type space identifier propertyBody cursor
	| method
	| property

  propertyBody ::= "{ get; }" | "{ get; set; }"="+"
  access ::= ""
  methodBody ::= ";"
}

scope "InCSharpStruct" {
}

scope "InCSharpStatement" {
  start ::=
	| "if ("=ifr identifier " == null) return;"
	| "Log."=l (Fatal=f | Info=i | Error=e | Trace=t | Debug=d) "(""" cursor """);"
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant