Browse Source

Allow references to unbound types in typeof/GetType expressions.

git-svn-id: svn://svn.sharpdevelop.net/sharpdevelop/trunk@529 1ccf3a8d-04fe-1044-b7c0-cef0b8235c61
shortcuts
Daniel Grunwald 20 years ago
parent
commit
8afa7cc805
  1. 6
      src/AddIns/Misc/HtmlHelp2/Project/src/Service/HtmlHelp2Options.cs
  2. 5
      src/AddIns/Misc/SubversionAddIn/Project/Src/Gui/HistoryViewDisplayBinding/InfoPanel.cs
  3. 12
      src/AddIns/Misc/SubversionAddIn/Project/Src/Gui/ProjectBrowserVisitor/OverlayIconManager.cs
  4. 1
      src/Libraries/ICSharpCode.TextEditor/Project/Src/Gui/CompletionWindow/CodeCompletionWindow.cs
  5. 2496
      src/Libraries/NRefactory/Project/Src/Parser/CSharp/Parser.cs
  6. 113
      src/Libraries/NRefactory/Project/Src/Parser/CSharp/cs.ATG
  7. 929
      src/Libraries/NRefactory/Project/Src/Parser/VBNet/Parser.cs
  8. 45
      src/Libraries/NRefactory/Project/Src/Parser/VBNet/VBNET.ATG
  9. 99
      src/Libraries/NRefactory/Test/Parser/Expressions/TypeOfExpressionTests.cs

6
src/AddIns/Misc/HtmlHelp2/Project/src/Service/HtmlHelp2Options.cs

@ -92,10 +92,10 @@ namespace HtmlHelp2.OptionsPanel
#region ReRegister #region ReRegister
void ReregisterButtonClick(object sender, EventArgs e) void ReregisterButtonClick(object sender, EventArgs e)
{ {
new MethodInvoker(DoReregister).BeginInvoke(null, null); System.Threading.ThreadPool.QueueUserWorkItem(DoReregister);
} }
void DoReregister() void DoReregister(object state)
{ {
try try
{ {

5
src/AddIns/Misc/SubversionAddIn/Project/Src/Gui/HistoryViewDisplayBinding/InfoPanel.cs

@ -9,6 +9,7 @@ using System;
using System.Collections; using System.Collections;
using System.Drawing; using System.Drawing;
using System.Reflection; using System.Reflection;
using System.Threading;
using System.Windows.Forms; using System.Windows.Forms;
using ICSharpCode.SharpDevelop.Gui; using ICSharpCode.SharpDevelop.Gui;
using NSvn.Common; using NSvn.Common;
@ -95,7 +96,7 @@ namespace ICSharpCode.Svn
if (!isLoadingChangedPaths) { if (!isLoadingChangedPaths) {
isLoadingChangedPaths = true; isLoadingChangedPaths = true;
loadChangedPathsItem = item; loadChangedPathsItem = item;
new MethodInvoker(LoadChangedPaths).BeginInvoke(null, null); ThreadPool.QueueUserWorkItem(LoadChangedPaths);
} }
} else { } else {
int pathWidth = 70; int pathWidth = 70;
@ -133,7 +134,7 @@ namespace ICSharpCode.Svn
ListViewItem loadChangedPathsItem; ListViewItem loadChangedPathsItem;
volatile bool isLoadingChangedPaths; volatile bool isLoadingChangedPaths;
void LoadChangedPaths() void LoadChangedPaths(object state)
{ {
try { try {
LogMessage logMessage = (LogMessage)loadChangedPathsItem.Tag; LogMessage logMessage = (LogMessage)loadChangedPathsItem.Tag;

12
src/AddIns/Misc/SubversionAddIn/Project/Src/Gui/ProjectBrowserVisitor/OverlayIconManager.cs

@ -91,7 +91,7 @@ namespace ICSharpCode.Svn
lock (queue) { lock (queue) {
queue.Enqueue(node); queue.Enqueue(node);
if (queue.Count == 1) { if (queue.Count == 1) {
new ThreadStart(Run).BeginInvoke(null, null); ThreadPool.QueueUserWorkItem(Run);
} }
} }
} }
@ -117,14 +117,14 @@ namespace ICSharpCode.Svn
} }
if (wasEmpty) { if (wasEmpty) {
new ThreadStart(Run).BeginInvoke(null, null); ThreadPool.QueueUserWorkItem(Run);
} }
} }
} }
static Client client; static Client client;
static void Run() static void Run(object state)
{ {
LoggingService.Debug("SVN: OverlayIconManager Thread started"); LoggingService.Debug("SVN: OverlayIconManager Thread started");
Thread.Sleep(2); // sleep 1 ms to give main thread time to add more jobs to the queue Thread.Sleep(2); // sleep 1 ms to give main thread time to add more jobs to the queue
@ -164,9 +164,9 @@ namespace ICSharpCode.Svn
} }
} }
if (node.TreeView != null) { if (node.TreeView != null) {
node.TreeView.BeginInvoke(new ThreadStart(delegate { node.TreeView.BeginInvoke(new MethodInvoker(delegate {
node.Overlay = GetImage(status); node.Overlay = GetImage(status);
})); }));
} }
} }
} }

1
src/Libraries/ICSharpCode.TextEditor/Project/Src/Gui/CompletionWindow/CodeCompletionWindow.cs

@ -264,7 +264,6 @@ namespace ICSharpCode.TextEditor.Gui.CompletionWindow
control.Document.Remove(startOffset, endOffset - startOffset); control.Document.Remove(startOffset, endOffset - startOffset);
} }
if (dataProvider.InsertSpace) { if (dataProvider.InsertSpace) {
Console.WriteLine("Inserting space..");
control.Document.Insert(startOffset++, " "); control.Document.Insert(startOffset++, " ");
} }
control.ActiveTextAreaControl.Caret.Position = control.Document.OffsetToPosition(startOffset); control.ActiveTextAreaControl.Caret.Position = control.Document.OffsetToPosition(startOffset);

2496
src/Libraries/NRefactory/Project/Src/Parser/CSharp/Parser.cs

File diff suppressed because it is too large Load Diff

113
src/Libraries/NRefactory/Project/Src/Parser/CSharp/cs.ATG

@ -21,12 +21,14 @@ public string ContainingAssembly {
} }
Token t { Token t {
[System.Diagnostics.DebuggerStepThrough]
get { get {
return lexer.Token; return lexer.Token;
} }
} }
Token la { Token la {
[System.Diagnostics.DebuggerStepThrough]
get { get {
return lexer.LookAhead; return lexer.LookAhead;
} }
@ -890,8 +892,8 @@ ClassBase<out List<TypeReference> names>
names = new List<TypeReference>(); names = new List<TypeReference>();
.) .)
= =
":" ClassType<out typeRef> (. if (typeRef != null) { names.Add(typeRef); } .) ":" ClassType<out typeRef, false> (. if (typeRef != null) { names.Add(typeRef); } .)
{ "," TypeName<out typeRef> (. if (typeRef != null) { names.Add(typeRef); } .) } { "," TypeName<out typeRef, false> (. if (typeRef != null) { names.Add(typeRef); } .) }
. .
ClassBody ClassBody
@ -914,8 +916,8 @@ StructInterfaces<out List<TypeReference> names>
names = new List<TypeReference>(); names = new List<TypeReference>();
.) .)
= =
":" TypeName<out typeRef> (. if (typeRef != null) { names.Add(typeRef); } .) ":" TypeName<out typeRef, false> (. if (typeRef != null) { names.Add(typeRef); } .)
{ "," TypeName<out typeRef> (. if (typeRef != null) { names.Add(typeRef); } .) } { "," TypeName<out typeRef, false> (. if (typeRef != null) { names.Add(typeRef); } .) }
. .
StructBody StructBody
@ -938,8 +940,8 @@ InterfaceBase<out List<TypeReference> names>
names = new List<TypeReference>(); names = new List<TypeReference>();
.) .)
= =
":" TypeName<out typeRef> (. if (typeRef != null) { names.Add(typeRef); } .) ":" TypeName<out typeRef, false> (. if (typeRef != null) { names.Add(typeRef); } .)
{ "," TypeName<out typeRef> (. if (typeRef != null) { names.Add(typeRef); } .) } { "," TypeName<out typeRef, false> (. if (typeRef != null) { names.Add(typeRef); } .) }
. .
InterfaceBody InterfaceBody
@ -954,45 +956,24 @@ EnumBody (. FieldDeclaration f; .)
. .
Type<out TypeReference type> Type<out TypeReference type>
(.
string name;
int pointer = 0;
type = null;
.)
= =
( ClassType<out type> TypeWithRestriction<out type, true, false>
| SimpleType<out name> (. type = new TypeReference(name); .)
[ NullableQuestionMark<ref type> ]
| "void" "*" (. pointer = 1; type = new TypeReference("void"); .)
) (. List<int> r = new List<int>(); .)
{ IF (IsPointerOrDims()) (. int i = 0; .)
( "*" (. ++pointer; .)
| "[" { "," (. ++i; .) } "]" (. r.Add(i); .)
)
}
(. if (type != null) {
type.RankSpecifier = r.ToArray();
type.PointerNestingLevel = pointer;
}
.)
. .
TypeWONullableQuestionMark<out TypeReference type> TypeWithRestriction<out TypeReference type, bool allowNullable, bool canBeUnbound>
(. (.
string name; string name;
int pointer = 0; int pointer = 0;
type = null; type = null;
.) .)
= =
( ClassTypeWONullableQuestionMark<out type> ( ClassType<out type, canBeUnbound>
| SimpleType<out name> (. type = new TypeReference(name); .) | SimpleType<out name> (. type = new TypeReference(name); .)
| "void" "*" (. pointer = 1; type = new TypeReference("void"); .) | "void" "*" (. pointer = 1; type = new TypeReference("void"); .)
) (. List<int> r = new List<int>(); .) ) (. List<int> r = new List<int>(); .)
[ IF (allowNullable && la.kind == Tokens.Question) NullableQuestionMark<ref type> ]
{ IF (IsPointerOrDims()) (. int i = 0; .) { IF (IsPointerOrDims()) (. int i = 0; .)
( "*" (. ++pointer; .) ( "*" (. ++pointer; .)
| "[" { "," (. ++i; .) } "]" (. r.Add(i); .) | "[" { "," (. ++i; .) } "]" (. r.Add(i); .)
@ -1013,12 +994,13 @@ NonArrayType<out TypeReference type>
type = null; type = null;
.) .)
= =
( ClassType<out type> ( ClassType<out type, false>
| SimpleType<out name> (. type = new TypeReference(name); .) | SimpleType<out name> (. type = new TypeReference(name); .)
[ NullableQuestionMark<ref type> ]
| "void" "*" (. pointer = 1; type = new TypeReference("void"); .) | "void" "*" (. pointer = 1; type = new TypeReference("void"); .)
) )
[ NullableQuestionMark<ref type> ]
{ IF (IsPointer()) { IF (IsPointer())
"*" (. ++pointer; .) "*" (. ++pointer; .)
} }
@ -1106,20 +1088,12 @@ TypeModifier<Modifiers m>
| ident (. if (t.val == "partial") { m.Add(Modifier.Partial, t.Location); } .) | ident (. if (t.val == "partial") { m.Add(Modifier.Partial, t.Location); } .)
. .
ClassType<out TypeReference typeRef> ClassType<out TypeReference typeRef, bool canBeUnbound>
(. TypeReference r; typeRef = null; .) (. TypeReference r; typeRef = null; .)
= =
TypeName<out r> (. typeRef = r; .) TypeName<out r, canBeUnbound> (. typeRef = r; .)
| "object" (. typeRef = new TypeReference("object"); .) | "object" (. typeRef = new TypeReference("object"); .)
| "string" (. typeRef = new TypeReference("string"); .) | "string" (. typeRef = new TypeReference("string"); .)
.
ClassTypeWONullableQuestionMark<out TypeReference typeRef>
(. TypeReference r; typeRef = null; .)
=
TypeNameWONullableQuestionMark<out r> (. typeRef = r; .)
| "object" (. typeRef = new TypeReference("object"); .)
| "string" (. typeRef = new TypeReference("string"); .)
. .
IntegralType<out string name> (. name = ""; .) IntegralType<out string name> (. name = ""; .)
@ -1945,11 +1919,11 @@ CatchClauses<out ArrayList catchClauses>
( (
Block<out stmt> (. catchClauses.Add(new CatchClause(stmt)); .) Block<out stmt> (. catchClauses.Add(new CatchClause(stmt)); .)
/*--- specific catch clause */ /*--- specific catch clause */
| "(" ClassType<out typeRef> (. identifier = null; .) | "(" ClassType<out typeRef, false> (. identifier = null; .)
[ ident (. identifier = t.val; .) ] [ ident (. identifier = t.val; .) ]
")" Block<out stmt> ")" Block<out stmt>
(. catchClauses.Add(new CatchClause(typeRef, identifier, stmt)); .) (. catchClauses.Add(new CatchClause(typeRef, identifier, stmt)); .)
{ IF (IsTypedCatch()) "catch" "(" ClassType<out typeRef> (. identifier = null; .) { IF (IsTypedCatch()) "catch" "(" ClassType<out typeRef, false> (. identifier = null; .)
[ ident (. identifier = t.val; .) ] [ ident (. identifier = t.val; .) ]
")" Block<out stmt> ")" Block<out stmt>
(. catchClauses.Add(new CatchClause(typeRef, identifier, stmt)); .) } (. catchClauses.Add(new CatchClause(typeRef, identifier, stmt)); .) }
@ -2074,7 +2048,7 @@ PrimaryExpr<out Expression pexpr>
| "null" (.pexpr = new PrimitiveExpression(null, "null"); .) /* from literal token */ | "null" (.pexpr = new PrimitiveExpression(null, "null"); .) /* from literal token */
| Literal (.pexpr = new PrimitiveExpression(t.literalValue, t.val); .) | Literal (.pexpr = new PrimitiveExpression(t.literalValue, t.val); .)
| IF (la.kind == Tokens.Identifier && Peek(1).kind == Tokens.DoubleColon) | IF (la.kind == Tokens.Identifier && Peek(1).kind == Tokens.DoubleColon)
TypeName<out type> (. pexpr = new TypeReferenceExpression(type); .) TypeName<out type, false> (. pexpr = new TypeReferenceExpression(type); .)
/*--- simple name: */ /*--- simple name: */
| ident (. pexpr = new IdentifierExpression(t.val); .) | ident (. pexpr = new IdentifierExpression(t.val); .)
/*--- parenthesized expression: */ /*--- parenthesized expression: */
@ -2152,7 +2126,7 @@ PrimaryExpr<out Expression pexpr>
| "typeof" "(" | "typeof" "("
( (
IF (NotVoidPointer()) "void" (. type = new TypeReference("void"); .) IF (NotVoidPointer()) "void" (. type = new TypeReference("void"); .)
| Type<out type> | TypeWithRestriction<out type, true, true>
) ")" (. pexpr = new TypeOfExpression(type); .) ) ")" (. pexpr = new TypeOfExpression(type); .)
| IF (la.kind == Tokens.Default && Peek(1).kind == Tokens.OpenParenthesis) | IF (la.kind == Tokens.Default && Peek(1).kind == Tokens.OpenParenthesis)
@ -2288,7 +2262,8 @@ RelationalExpr<ref Expression outExpr>
"is" (. op = BinaryOperatorType.TypeCheck; .) "is" (. op = BinaryOperatorType.TypeCheck; .)
| "as" (. op = BinaryOperatorType.AsCast; .) | "as" (. op = BinaryOperatorType.AsCast; .)
) )
TypeWONullableQuestionMark<out type> (. outExpr = new BinaryOperatorExpression(outExpr, op, new TypeReferenceExpression(type)); .) TypeWithRestriction<out type, false, false>
(. outExpr = new BinaryOperatorExpression(outExpr, op, new TypeReferenceExpression(type)); .)
} }
. .
@ -2343,7 +2318,7 @@ MultiplicativeExpr<ref Expression outExpr>
/* .NET 2.0 rules */ /* .NET 2.0 rules */
TypeName<out TypeReference typeRef> TypeName<out TypeReference typeRef, bool canBeUnbound>
(. List<TypeReference> typeArguments = null; (. List<TypeReference> typeArguments = null;
string alias = null; string alias = null;
string qualident; string qualident;
@ -2354,32 +2329,14 @@ TypeName<out TypeReference typeRef>
"::" "::"
] ]
Qualident<out qualident> Qualident<out qualident>
[ TypeArgumentList<out typeArguments> ] ( IF (canBeUnbound && la.kind == Tokens.LessThan && (Peek(1).kind == Tokens.GreaterThan || Peek(1).kind == Tokens.Comma))
(. (. typeArguments = new List<TypeReference>(); .)
if (alias == null) { "<"
typeRef = new TypeReference(qualident, typeArguments); (. typeArguments.Add(NullTypeReference.Instance); .)
} else if (alias == "global") { { "," (. typeArguments.Add(NullTypeReference.Instance); .) }
typeRef = new TypeReference(qualident, typeArguments); ">"
typeRef.IsGlobal = true; | [TypeArgumentList<out typeArguments>]
} else { )
typeRef = new TypeReference(alias + "." + qualident, typeArguments);
}
.)
[ NullableQuestionMark<ref typeRef> ]
.
TypeNameWONullableQuestionMark<out TypeReference typeRef>
(. List<TypeReference> typeArguments = null;
string alias = null;
string qualident;
.)
=
[ IF (la.kind == Tokens.Identifier && Peek(1).kind == Tokens.DoubleColon)
ident (. alias = t.val; .)
"::"
]
Qualident<out qualident>
[ TypeArgumentList<out typeArguments> ]
(. (.
if (alias == null) { if (alias == null) {
typeRef = new TypeReference(qualident, typeArguments); typeRef = new TypeReference(qualident, typeArguments);

929
src/Libraries/NRefactory/Project/Src/Parser/VBNet/Parser.cs

File diff suppressed because it is too large Load Diff

45
src/Libraries/NRefactory/Project/Src/Parser/VBNet/VBNET.ATG

@ -1714,7 +1714,7 @@ SimpleExpr<out Expression pexpr>
| /* 11.11 */ "TryCast" "(" Expr<out expr> "," TypeName<out type> ")" (. pexpr = new BinaryOperatorExpression(expr, BinaryOperatorType.AsCast, new TypeReferenceExpression(type)); .) | /* 11.11 */ "TryCast" "(" Expr<out expr> "," TypeName<out type> ")" (. pexpr = new BinaryOperatorExpression(expr, BinaryOperatorType.AsCast, new TypeReferenceExpression(type)); .)
| /* 11.11 */ CastTarget<out type> "(" Expr<out expr> ")" (. pexpr = new CastExpression(type, expr, true); .) | /* 11.11 */ CastTarget<out type> "(" Expr<out expr> ")" (. pexpr = new CastExpression(type, expr, true); .)
| /* 11.4.5 */ "AddressOf" Expr<out expr> (. pexpr = new AddressOfExpression(expr); .) | /* 11.4.5 */ "AddressOf" Expr<out expr> (. pexpr = new AddressOfExpression(expr); .)
| /* 11.5.1 */ "GetType" "(" TypeName<out type> ")" (. pexpr = new TypeOfExpression(type); .) | /* 11.5.1 */ "GetType" "(" GetTypeTypeName<out type> ")" (. pexpr = new TypeOfExpression(type); .)
| /* 11.5.2 */ "TypeOf" SimpleExpr<out expr> "Is" TypeName<out type> (. pexpr = new TypeOfIsExpression(expr, type); .) | /* 11.5.2 */ "TypeOf" SimpleExpr<out expr> "Is" TypeName<out type> (. pexpr = new TypeOfIsExpression(expr, type); .)
) )
{ {
@ -1899,7 +1899,7 @@ ObjectCreateExpression<out Expression oce>
ArrayList arguments = null; ArrayList arguments = null;
oce = null; oce = null;
.) = .) =
"New" NonArrayTypeName<out type> "New" NonArrayTypeName<out type, false>
["(" [ ArgumentList<out arguments> ] ")" ] ["(" [ ArgumentList<out arguments> ] ")" ]
[ ArrayInitializer<out initializer> ] [ ArrayInitializer<out initializer> ]
(. (.
@ -1945,36 +1945,53 @@ Argument<out Expression argumentexpr>
/* 7.1. */ /* 7.1. */
TypeName<out TypeReference typeref> TypeName<out TypeReference typeref>
(. ArrayList rank = null; typeref = null; .) (. ArrayList rank = null; .)
= =
NonArrayTypeName<out typeref> NonArrayTypeName<out typeref, false>
ArrayTypeModifiers<out rank> ArrayTypeModifiers<out rank>
(. (. if (rank != null && typeref != null) {
if (rank != null && typeref != null) { typeref.RankSpecifier = (int[])rank.ToArray(typeof(int));
}
.)
.
GetTypeTypeName<out TypeReference typeref>
(. ArrayList rank = null; .)
=
NonArrayTypeName<out typeref, true>
ArrayTypeModifiers<out rank>
(. if (rank != null && typeref != null) {
typeref.RankSpecifier = (int[])rank.ToArray(typeof(int)); typeref.RankSpecifier = (int[])rank.ToArray(typeof(int));
} }
.) .)
. .
/* 7.1 */ /* 7.1 */
NonArrayTypeName<out TypeReference typeref> NonArrayTypeName<out TypeReference typeref, bool canBeUnbound>
(. (.
string name; string name;
typeref = null; typeref = null;
bool isGlobal = false;
.) = .) =
Qualident<out name> (. typeref = new TypeReference(name); .) (
[ "Global" "." (. isGlobal = true; .) ]
Qualident<out name>
(. typeref = new TypeReference(name); typeref.IsGlobal = isGlobal; .)
[IF (la.kind == Tokens.OpenParenthesis && Peek(1).kind == Tokens.Of) [IF (la.kind == Tokens.OpenParenthesis && Peek(1).kind == Tokens.Of)
"(" "Of" TypeArgumentList<typeref.GenericTypes> ")" "(" "Of"
( IF (canBeUnbound && (la.kind == Tokens.CloseParenthesis || la.kind == Tokens.Comma))
(. typeref.GenericTypes.Add(NullTypeReference.Instance); .)
{ "," (. typeref.GenericTypes.Add(NullTypeReference.Instance); .) }
| TypeArgumentList<typeref.GenericTypes>
)
")"
] ]
)
| "Object" (. typeref = new TypeReference("System.Object"); .) | "Object" (. typeref = new TypeReference("System.Object"); .)
| "Global" "." Qualident<out name>
(. typeref = new TypeReference(name); typeref.IsGlobal = true; .)
[IF (la.kind == Tokens.OpenParenthesis && Peek(1).kind == Tokens.Of)
"(" "Of" TypeArgumentList<typeref.GenericTypes> ")"
]
| PrimitiveTypeName<out name> (. typeref = new TypeReference(name); .) | PrimitiveTypeName<out name> (. typeref = new TypeReference(name); .)
. .
/* 7.9 */ /* 7.9 */
ArrayNameModifier<out ArrayList arrayModifiers> ArrayNameModifier<out ArrayList arrayModifiers>
(. (.

99
src/Libraries/NRefactory/Test/Parser/Expressions/TypeOfExpressionTests.cs

@ -1,4 +1,4 @@
// <file> // <file>
// <copyright see="prj:///doc/copyright.txt">2002-2005 AlphaSierraPapa</copyright> // <copyright see="prj:///doc/copyright.txt">2002-2005 AlphaSierraPapa</copyright>
// <license see="prj:///doc/license.txt">GNU General Public License</license> // <license see="prj:///doc/license.txt">GNU General Public License</license>
// <owner name="Mike Krüger" email="mike@icsharpcode.net"/> // <owner name="Mike Krüger" email="mike@icsharpcode.net"/>
@ -24,22 +24,115 @@ namespace ICSharpCode.NRefactory.Tests.AST
Assert.AreEqual("MyNamespace.N1.MyType", toe.TypeReference.Type); Assert.AreEqual("MyNamespace.N1.MyType", toe.TypeReference.Type);
} }
[Test]
public void CSharpGlobalTypeOfExpressionTest()
{
TypeOfExpression toe = (TypeOfExpression)ParseUtilCSharp.ParseExpression("typeof(global::System.Console)", typeof(TypeOfExpression));
Assert.AreEqual("System.Console", toe.TypeReference.Type);
}
[Test]
public void CSharpPrimitiveTypeOfExpressionTest()
{
TypeOfExpression toe = (TypeOfExpression)ParseUtilCSharp.ParseExpression("typeof(int)", typeof(TypeOfExpression));
Assert.AreEqual("System.Int32", toe.TypeReference.SystemType);
}
[Test]
public void CSharpVoidTypeOfExpressionTest()
{
TypeOfExpression toe = (TypeOfExpression)ParseUtilCSharp.ParseExpression("typeof(void)", typeof(TypeOfExpression));
Assert.AreEqual("System.Void", toe.TypeReference.SystemType);
}
[Test]
public void CSharpArrayTypeOfExpressionTest()
{
TypeOfExpression toe = (TypeOfExpression)ParseUtilCSharp.ParseExpression("typeof(MyType[])", typeof(TypeOfExpression));
Assert.AreEqual("MyType", toe.TypeReference.Type);
Assert.AreEqual(new int[] {0}, toe.TypeReference.RankSpecifier);
}
[Test] [Test]
public void CSharpGenericTypeOfExpressionTest() public void CSharpGenericTypeOfExpressionTest()
{ {
TypeOfExpression toe = (TypeOfExpression)ParseUtilCSharp.ParseExpression("typeof(MyNamespace.N1.MyType<string>)", typeof(TypeOfExpression)); TypeOfExpression toe = (TypeOfExpression)ParseUtilCSharp.ParseExpression("typeof(MyNamespace.N1.MyType<string>)", typeof(TypeOfExpression));
Assert.AreEqual("MyNamespace.N1.MyType", toe.TypeReference.Type); Assert.AreEqual("MyNamespace.N1.MyType", toe.TypeReference.Type);
Assert.AreEqual("string", toe.TypeReference.GenericTypes[0].Type); Assert.AreEqual("System.String", toe.TypeReference.GenericTypes[0].SystemType);
}
[Test]
public void CSharpNullableTypeOfExpressionTest()
{
TypeOfExpression toe = (TypeOfExpression)ParseUtilCSharp.ParseExpression("typeof(MyStruct?)", typeof(TypeOfExpression));
Assert.AreEqual("System.Nullable", toe.TypeReference.SystemType);
Assert.AreEqual("MyStruct", toe.TypeReference.GenericTypes[0].Type);
}
[Test]
public void CSharpUnboundTypeOfExpressionTest()
{
TypeOfExpression toe = (TypeOfExpression)ParseUtilCSharp.ParseExpression("typeof(MyType<,>)", typeof(TypeOfExpression));
Assert.AreEqual("MyType", toe.TypeReference.Type);
Assert.IsTrue(toe.TypeReference.GenericTypes[0].IsNull);
Assert.IsTrue(toe.TypeReference.GenericTypes[1].IsNull);
} }
#endregion #endregion
#region VB.NET #region VB.NET
[Test] [Test]
public void SimpleTypeOfExpressionTest() public void VBSimpleTypeOfExpressionTest()
{ {
TypeOfExpression toe = (TypeOfExpression)ParseUtilVBNet.ParseExpression("GetType(MyNamespace.N1.MyType)", typeof(TypeOfExpression)); TypeOfExpression toe = (TypeOfExpression)ParseUtilVBNet.ParseExpression("GetType(MyNamespace.N1.MyType)", typeof(TypeOfExpression));
Assert.AreEqual("MyNamespace.N1.MyType", toe.TypeReference.Type); Assert.AreEqual("MyNamespace.N1.MyType", toe.TypeReference.Type);
} }
[Test]
public void VBGlobalTypeOfExpressionTest()
{
TypeOfExpression toe = (TypeOfExpression)ParseUtilVBNet.ParseExpression("GetType(Global.System.Console)", typeof(TypeOfExpression));
Assert.AreEqual("System.Console", toe.TypeReference.Type);
}
[Test]
public void VBPrimitiveTypeOfExpressionTest()
{
TypeOfExpression toe = (TypeOfExpression)ParseUtilVBNet.ParseExpression("GetType(integer)", typeof(TypeOfExpression));
Assert.AreEqual("System.Int32", toe.TypeReference.SystemType);
}
[Test]
public void VBVoidTypeOfExpressionTest()
{
TypeOfExpression toe = (TypeOfExpression)ParseUtilVBNet.ParseExpression("GetType(void)", typeof(TypeOfExpression));
Assert.AreEqual("System.Void", toe.TypeReference.SystemType);
}
[Test]
public void VBArrayTypeOfExpressionTest()
{
TypeOfExpression toe = (TypeOfExpression)ParseUtilVBNet.ParseExpression("GetType(MyType())", typeof(TypeOfExpression));
Assert.AreEqual("MyType", toe.TypeReference.Type);
Assert.AreEqual(new int[] {0}, toe.TypeReference.RankSpecifier);
}
[Test]
public void VBGenericTypeOfExpressionTest()
{
TypeOfExpression toe = (TypeOfExpression)ParseUtilVBNet.ParseExpression("GetType(MyNamespace.N1.MyType(Of string))", typeof(TypeOfExpression));
Assert.AreEqual("MyNamespace.N1.MyType", toe.TypeReference.Type);
Assert.AreEqual("System.String", toe.TypeReference.GenericTypes[0].SystemType);
}
[Test]
public void VBUnboundTypeOfExpressionTest()
{
TypeOfExpression toe = (TypeOfExpression)ParseUtilVBNet.ParseExpression("GetType(MyType(Of ,))", typeof(TypeOfExpression));
Assert.AreEqual("MyType", toe.TypeReference.Type);
Assert.IsTrue(toe.TypeReference.GenericTypes[0].IsNull);
Assert.IsTrue(toe.TypeReference.GenericTypes[1].IsNull);
}
#endregion #endregion
} }
} }

Loading…
Cancel
Save