Created
February 16, 2012 01:14
-
-
Save giggio/1840538 to your computer and use it in GitHub Desktop.
Exemplo de binding estático e dinâmico em C#
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using Microsoft.VisualStudio.TestTools.UnitTesting; | |
namespace TestProject3 | |
{ | |
[TestClass] | |
public class BindingTest | |
{ | |
[TestMethod] | |
public void EstaticoString() | |
{ | |
Assert.AreEqual("object", Classe.Estatico("")); | |
} | |
[TestMethod] | |
public void EstaticoObject() | |
{ | |
Assert.AreEqual("object", Classe.Estatico(1)); | |
} | |
[TestMethod] | |
public void DinamicoString() | |
{ | |
Assert.AreEqual("string", Classe.Dinamico("")); | |
} | |
[TestMethod] | |
public void DinamicoObject() | |
{ | |
Assert.AreEqual("object", Classe.Dinamico(1)); | |
} | |
} | |
public class Classe | |
{ | |
public static string Dinamico(dynamic d) | |
{ | |
return Metodo(d); | |
} | |
public static string Estatico(object o) | |
{ | |
return Metodo(o); | |
} | |
private static string Metodo(string s) | |
{ | |
return "string"; | |
} | |
private static string Metodo(object o) | |
{ | |
return "object"; | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment