Skip to content

Instantly share code, notes, and snippets.

@brantb
Created April 19, 2011 17:25
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save brantb/928920 to your computer and use it in GitHub Desktop.
Save brantb/928920 to your computer and use it in GitHub Desktop.
C# syntax highlighting sample
using System; // R# Namespace Identifier
using System.Dynamic;
using System.Linq; // R# Dead code
using System.Xml.XPath;
// Disable various dead code warnings
#pragma warning disable 168
#pragma warning disable 219
// ReSharper disable RedundantAssignment
// ReSharper disable SuggestUseVarKeywordEvident
// ReSharper disable ConvertToConstant.Local
// ReSharper disable FieldCanBeMadeReadOnly.Local
// ReSharper disable UnusedMember.Global
// ReSharper disable RedundantNameQualifier
// ReSharper disable CheckNamespace
namespace Solarized
{
/// <summary>Enterprisey Hello World</summary>
public static class Hello // R# Static Class Identifier
{
public static void Main(string[] parameters)
{
OnWorldGreeted = () => Console.WriteLine("World was greeted");
var hello = new HelloTextFactory();
System.Console.WriteLine(hello); // R# Namespace Identifier
System.Console.WriteLine("You entered the following " +
"{0} {1} command line arguments:", // R# Format String Item
parameters.Length, "cool");
foreach (var t in parameters) // R# Parameter Identifier
{
Console.WriteLine("{0}", t);
}
// TODO: Write unit tests! // R# Todo Item
OnWorldGreeted();
}
public static event OnHelloEventHandler OnWorldGreeted;
}
public delegate void OnHelloEventHandler();
public class HelloTextFactory : IHasHello<String>
{
private const string CONSTANT = "Hello, World!";
public string Text { get; protected set; }
private int _field = 1;
public int AlsoAField { get; set; }
public HelloTextFactory()
{
string local = "test";
Text = CONSTANT; // R# Constant Identifier
AlsoAField = _field; // R# Field Identifier
int mutableLocalVariable = 0; // R# Mutable Local Variable Identifier
int localVariable = 1; // R# Local Variable Identifier
Text = "test".ExtensionMethod(); // R# Extension Mehod Identifier
mutableLocalVariable += localVariable;
mutableLocalVariable.ToString(); // R# Method Identifier
var x = AlsoAField.CompareTo(4 + 4); // R# Method Identifier
dynamic thingy = new ExpandoObject();
thingy.LateBoundIdentifier = @"Whee!"; // R# Late Bound Identifier
Hello.OnWorldGreeted += () => "foo"; // R# Static Class Identifier
// VS2010 highlight rules are ignored when R#'s "Color Identifiers" option is enabled
C.D referenceType = new C.D(); // VS: User Types R#: Class Identifier
Func<Object> foo = () => "x"; // VS: User Types (Delegates) R#: Delegate Identifier
Int32 valueType = new Int32(); // VS: User Types (Value Types) R#: Struct Identifier
Languages enumType = Languages.Ruby; // VS: User Types (Enums) R#: Enum Identifier
IHasHello<string> i = new HelloTextFactory(); // VS: User Types (Interfaces) R#: Interface Identifier
}
}
#region More tests
public enum Languages
{
English,
Ruby,
CSharp
}
public interface IHasHello<out TOfGreeting>
{
TOfGreeting Text { get; } // R# Type Parameter Identifier
}
public class C
{
public class D
{
}
}
#endregion
public static class SyntaxTestExtensions
{
public static string ExtensionMethod(this string parameter)
{
return parameter;
}
}
}
#pragma warning restore 219
// ReSharper restore FieldCanBeMadeReadOnly.Local
// ReSharper restore SuggestUseVarKeywordEvident
// ReSharper restore ConvertToConstant.Local
// ReSharper restore UnusedMember.Global
// ReSharper restore RedundantNameQualifier
// ReSharper restore RedundantAssignment
// ReSharper restore CheckNamespace
#pragma warning restore 168
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment