I copy and paste source of WebMatrix.WebData.IDatabase
but VStudio mark Dynamic words and said
Do not use 'System.Runtime.CompilerServices.DynamicAttribute'. Use the 'dynamic' keyword instead.
Why i get this error when original .net framework used it?
The source code is here:
namespace WebMatrix.WebData
{
using System;
using System.Collections.Generic;
using System.Runtime.CompilerServices;
internal interface IDatabase : IDisposable
{
int Execute(string commandText, params object[] args);
[return: Dynamic(new bool[] { false, true })]
IEnumerable<object> Query(string commandText, params object[] parameters);
[return: Dynamic]
object QuerySingle(string commandText, params object[] args);
[return: Dynamic]
object QueryValue(string commandText, params object[] parameters);
}
}
and I get same error here:
namespace WebMatrix.WebData
{
internal class DatabaseWrapper : IDatabase, IDisposable
{
private readonly Database _database;
public DatabaseWrapper(Database database)
{
this._database = database;
}
public void Dispose()
{
this._database.Dispose();
}
public int Execute(string commandText, params object[] parameters)
{
return this._database.Execute(commandText, parameters);
}
[return: Dynamic(new bool[] { false, true })]
public IEnumerable<object> Query(string commandText, params object[] parameters)
{
return this._database.Query(commandText, parameters);
}
[return: Dynamic]
public object QuerySingle(string commandText, params object[] parameters)
{
return this._database.QuerySingle(commandText, parameters);
}
[return: Dynamic]
public object QueryValue(string commandText, params object[] parameters)
{
return this._database.QueryValue(commandText, parameters);
}
}
}
That maps to:
IEnumerable<dynamic> Query(string commandText, params object[] parameters);
dynamic QuerySingle(string commandText, params object[] args);
dynamic QueryValue(string commandText, params object[] parameters);
The only reason I can think of to use the alternative syntax is for compiling it on a down-level compiler that doesn't know about the dynamic
keyword. However, [DynamicAttribute]
has only existed since .NET 4.0, which includes a compiler with dynamic
support. Thoughts:
dynamic
was incompleteIf you look at the current source, it uses dynamic
, supporting the hypothesis that any [Dynamic]
usage was purely transitional.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With