本文整理汇总了C#中Foo.GetType方法的典型用法代码示例。如果您正苦于以下问题:C# Foo.GetType方法的具体用法?C# Foo.GetType怎么用?C# Foo.GetType使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Foo
的用法示例。
在下文中一共展示了Foo.GetType方法的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: the_nested_property_should_have_the_assigned_value
public void the_nested_property_should_have_the_assigned_value()
{
var value = 123;
var foo = new Foo { Bar = new Bar { Number = 0 } };
var setter = PropertySetter.Create(foo.GetType(), "Bar.Number");
setter.Set(foo, value);
Assert.That(foo.Bar.Number, Is.EqualTo(value));
}
示例2: Test_structs
public void Test_structs()
{
JsConfig<Text>.SerializeFn = text => text.ToString();
var dto = new Foo { Content1 = "My content", Name = "My name" };
var json = JsonSerializer.SerializeToString(dto, dto.GetType());
Assert.That(json, Is.EqualTo("{\"Name\":\"My name\",\"Content1\":\"My content\"}"));
}
示例3: ReturnsWhatTheSerializeToStringInterfaceMethodOnTheDefaultXmlSerializerReturns
public void ReturnsWhatTheSerializeToStringInterfaceMethodOnTheDefaultXmlSerializerReturns()
{
var foo = new Foo { Bar = "abc123" };
var result = foo.ToXml();
var expectedResult = DefaultXmlSerializer.Current.SerializeToString(foo, foo.GetType());
Assert.That(result, Is.EqualTo(expectedResult));
}
示例4: Main
public static int Main(string[]
args)
{
Foo
f
=
new
Foo
();
MethodInfo
m
=
(MethodInfo)
(f.GetType
().FindMembers
(MemberTypes.All,
BindingFlags.Public
|
BindingFlags.Static,
Type.FilterName,
"Sum"))[0];
int[]
numbers
=
new
int[3]{4,
5,
6};
object[]
parms
=
new
object[1]{numbers};
int
sum
=
(int)m.Invoke
(f,
parms);
Console.WriteLine
("sum is "
+
sum);
if
(sum
!=
15)
return
1;
return
0;
}
示例5: SetsIdOnMatchingProperty
public void SetsIdOnMatchingProperty(SUT sut, IInvocation invocation, int barId)
{
var foo = new Foo { BarId = barId };
var bar = new Bar();
invocation.Method.Returns(foo.GetType().GetProperty("Bar").GetGetMethod());
invocation.InvocationTarget.Returns(foo);
invocation.ReturnValue = bar;
sut.Intercept(invocation);
bar.Id.Should().Be(barId);
}
示例6: Test_structs_with_double_quotes
public void Test_structs_with_double_quotes()
{
var dto = new Foo { Content1 = "My \"quoted\" content", Name = "My \"quoted\" name" };
JsConfig<Text>.SerializeFn = text => text.ToString();
JsConfig<Text>.DeSerializeFn = v => new Text(v);
var json = JsonSerializer.SerializeToString(dto, dto.GetType());
Assert.That(json, Is.EqualTo("{\"Name\":\"My \\\"quoted\\\" name\",\"Content1\":\"My \\\"quoted\\\" content\"}"));
var foo = JsonSerializer.DeserializeFromString<Foo>(json);
Assert.That(foo.Content1, Is.EqualTo(dto.Content1));
}
示例7: SetsPropertyOnValueReturn
public void SetsPropertyOnValueReturn(SUT sut, IInvocation invocation)
{
// Setup fixture
var foo = new Foo();
var bar = new Bar();
invocation.Method.Returns(foo.GetType().GetProperty("Bar").GetGetMethod());
invocation.InvocationTarget.Returns(foo);
invocation.ReturnValue = bar;
// Exercise system
sut.Intercept(invocation);
// Verify outcome
foo.Bar.Should().Be(bar);
}
开发者ID:bardock,项目名称:AutoFixture.AutoEntityFramework,代码行数:16,代码来源:SetPropertyReturnValueInterceptorTest.cs
示例8: Main
static void Main(string[] args)
{
var lua = new Lua();
Console.WriteLine("LuaTable disposal stress test...");
{
lua.DoString("a={b={c=0}}");
for (var i = 0; i < 100000; ++i)
{
// Note that we don't even need the object type to be LuaTable - c is an int.
// Simply indexing through tables in the string expression was enough to cause
// the bug...
var z = lua["a.b.c"];
}
}
Console.WriteLine(" ... passed");
Console.WriteLine("LuaFunction disposal stress test...");
{
lua.DoString("function func() return func end");
for (var i = 0; i < 100000; ++i)
{
var f = lua["func"];
}
}
Console.WriteLine(" ... passed");
lua["x"] = 3;
lua.DoString("y=x");
Console.WriteLine("y={0}", lua["y"]);
{
lua.DoString("luanet.load_assembly('SimpleTest')");
lua.DoString("Foo = luanet.import_type('SimpleTest.Foo')");
lua.DoString("method = luanet.get_method_bysig(Foo, 'OutMethod', 'SimpleTest.Foo', 'out SimpleTest.Bar')");
Console.WriteLine(lua["method"]);
}
{
object[] retVals = lua.DoString("return 1,'hello'");
Console.WriteLine("{0},{1}", retVals[0], retVals[1]);
}
{
KopiLua.Lua.lua_pushcfunction(lua.luaState, Func);
KopiLua.Lua.lua_setglobal(lua.luaState, "func");
Console.WriteLine("registered 'func'");
double result = (double)lua.DoString("return func(1,2,3)")[0];
Console.WriteLine("{0}", result);
}
{
Bar bar = new Bar();
bar.x = 2;
lua["bar"] = bar;
Console.WriteLine("'bar' registered");
object o = lua["bar"];
Console.WriteLine("'bar' read back as {0}", o);
Console.WriteLine(o == bar ? "same" : "different");
Console.WriteLine("LuaInterface says bar.x = {0}", lua["bar.x"]);
double result = (double)lua.DoString("return bar.x")[0];
Console.WriteLine("lua says bar.x = {0}", result);
lua.DoString("bar.x = 4");
Console.WriteLine("now bar.x = {0}", bar.x);
}
{
Foo foo = new Foo();
lua.RegisterFunction("multiply", foo, foo.GetType().GetMethod("multiply"));
Console.WriteLine("registered 'multiply'");
double result = (double)lua.DoString("return multiply(3)")[0];
Console.WriteLine("{0}", result);
}
Console.WriteLine("Finished, press Enter to quit");
Console.ReadLine();
}
示例9: Dispatch
private object Dispatch(Foo o, string methodName, params object[] args)
{
return Dispatch(o, o.GetType(), methodName, args);
}
示例10: Main
static void Main(string[] args)
{
Lua lua = new Lua();
lua["x"] = 3;
lua.DoString("y=x");
Console.WriteLine("y={0}", lua["y"]);
{
object[] retVals = lua.DoString("return 1,'hello'");
Console.WriteLine("{0},{1}", retVals[0], retVals[1]);
}
{
KopiLua.Lua.lua_pushcfunction(lua.luaState, Func);
KopiLua.Lua.lua_setglobal(lua.luaState, "func");
Console.WriteLine("registered 'func'");
double result = (double)lua.DoString("return func(1,2,3)")[0];
Console.WriteLine("{0}", result);
}
{
Bar bar = new Bar();
bar.x = 2;
lua["bar"] = bar;
Console.WriteLine("'bar' registered");
object o = lua["bar"];
Console.WriteLine("'bar' read back as {0}", o);
Console.WriteLine(o == bar ? "same" : "different");
Console.WriteLine("LuaInterface says bar.x = {0}", lua["bar.x"]);
double result = (double)lua.DoString("return bar.x")[0];
Console.WriteLine("lua says bar.x = {0}", result);
lua.DoString("bar.x = 4");
Console.WriteLine("now bar.x = {0}", bar.x);
}
{
Foo foo = new Foo();
lua.RegisterFunction("multiply", foo, foo.GetType().GetMethod("multiply"));
Console.WriteLine("registered 'multiply'");
double result = (double)lua.DoString("return multiply(3)")[0];
Console.WriteLine("{0}", result);
}
Console.ReadLine();
}
示例11: Main
public static void Main() {
var foo = new Foo();
Console.WriteLine(foo.GetType().ToString());
}
示例12: Main
static void Main(string[] args)
{
Lua lua = new Lua();
lua["x"] = 3;
lua.DoString("y=x");
Console.WriteLine("y={0}", lua["y"]);
{
lua.DoString("luanet.load_assembly('SimpleTest')");
lua.DoString("Foo = luanet.import_type('SimpleTest.Foo')");
lua.DoString("method = luanet.get_method_bysig(Foo, 'OutMethod', 'SimpleTest.Foo', 'out SimpleTest.Bar')");
Console.WriteLine(lua["method"]);
}
{
object[] retVals = lua.DoString("return 1,'hello'");
Console.WriteLine("{0},{1}", retVals[0], retVals[1]);
}
{
KopiLua.Lua.lua_pushcfunction(lua.luaState, Func);
KopiLua.Lua.lua_setglobal(lua.luaState, "func");
Console.WriteLine("registered 'func'");
double result = (double)lua.DoString("return func(1,2,3)")[0];
Console.WriteLine("{0}", result);
}
{
Bar bar = new Bar();
bar.x = 2;
lua["bar"] = bar;
Console.WriteLine("'bar' registered");
object o = lua["bar"];
Console.WriteLine("'bar' read back as {0}", o);
Console.WriteLine(o == bar ? "same" : "different");
Console.WriteLine("LuaInterface says bar.x = {0}", lua["bar.x"]);
double result = (double)lua.DoString("return bar.x")[0];
Console.WriteLine("lua says bar.x = {0}", result);
lua.DoString("bar.x = 4");
Console.WriteLine("now bar.x = {0}", bar.x);
}
{
Foo foo = new Foo();
lua.RegisterFunction("multiply", foo, foo.GetType().GetMethod("multiply"));
Console.WriteLine("registered 'multiply'");
double result = (double)lua.DoString("return multiply(3)")[0];
Console.WriteLine("{0}", result);
}
Console.WriteLine("Finished, press Enter to quit");
Console.ReadLine();
}