本文整理汇总了C#中System.Collections.Generic.GetType方法的典型用法代码示例。如果您正苦于以下问题:C# System.Collections.Generic.GetType方法的具体用法?C# System.Collections.Generic.GetType怎么用?C# System.Collections.Generic.GetType使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Collections.Generic
的用法示例。
在下文中一共展示了System.Collections.Generic.GetType方法的14个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Should_render_include_with_same_model
public void Should_render_include_with_same_model()
{
var model = new { Name = "Joe" };
RegisterTemplate("person", SyntaxTree.Block(
SyntaxTree.WriteExpression(SyntaxTreeExpression.Property(model.GetType(), "Name"))
));
var template = SyntaxTree.Block(
SyntaxTree.WriteString("Hello "),
SyntaxTree.Include("person", SyntaxTreeExpression.Self(model.GetType()))
);
var result = ExecuteTemplate(template, model);
Assert.That(result, Is.EqualTo("Hello Joe"));
}
示例2: Should_map_an_anonymous_object_to_the_settings
public void Should_map_an_anonymous_object_to_the_settings()
{
var converterCache = new DynamicObjectConverterCache(new DynamicImplementationBuilder());
var cache = new DictionaryConverterCache();
var source = new
{
Host = "localhost",
VirtualHost = "vortex",
Username = "joe",
Password = "guess",
Port = 5672,
};
IDictionaryConverter converter = cache.GetConverter(source.GetType());
IDictionary<string, object> dictionary = converter.GetDictionary(source);
IObjectConverter objectConverter = converterCache.GetConverter(typeof(RabbitMqSettings));
var settings = (RabbitMqSettings)objectConverter.GetObject(dictionary);
Assert.IsNotNull(settings);
Assert.AreEqual("localhost", settings.Host);
Assert.AreEqual("vortex", settings.VirtualHost);
Assert.AreEqual("joe", settings.Username);
Assert.AreEqual("guess", settings.Password);
Assert.AreEqual(5672, settings.Port);
Assert.AreEqual(0, settings.Heartbeat);
Assert.IsNull(settings.Options);
}
示例3: Should_render_include_with_same_sub_model
public void Should_render_include_with_same_sub_model()
{
var model = new { Name = "Joe", Company = new { Name = "Foo" } };
RegisterTemplate("company", SyntaxTree.Block(
SyntaxTree.WriteExpression(SyntaxTreeExpression.Property(model.Company.GetType(), "Name"))
));
RegisterTemplate("person", SyntaxTree.Block(
SyntaxTree.WriteExpression(SyntaxTreeExpression.Property(model.GetType(), "Name"))
));
var template = SyntaxTree.Block(
SyntaxTree.WriteString("Welcome from "),
SyntaxTree.Include("company", SyntaxTreeExpression.Property(model.GetType(), "Company")),
SyntaxTree.WriteString(" the amazing "),
SyntaxTree.Include("person", SyntaxTreeExpression.Self(model.GetType())),
SyntaxTree.WriteString(".")
);
var result = ExecuteTemplate(template, model);
Assert.That(result, Is.EqualTo("Welcome from Foo the amazing Joe."));
}
示例4: Should_use_items_from_collection_as_scope
public void Should_use_items_from_collection_as_scope()
{
var model = new { Items = new[] { new ItemModel { Name = "John" }, new ItemModel { Name = "Kim" } } };
var template = SyntaxTree.Block(SyntaxTree.Iterate(
SyntaxTreeExpression.Property(model.GetType(), "Items"),
SyntaxTree.Block(
SyntaxTree.WriteExpression(SyntaxTreeExpression.Property(typeof(ItemModel), "Name"))
)
));
var result = ExecuteTemplate(template, model);
Assert.That(result, Is.EqualTo("JohnKim"));
}
示例5: Should_throw_if_unable_to_load_template
public void Should_throw_if_unable_to_load_template()
{
var model = new { Name = "Joe" };
var template = SyntaxTree.Block(
SyntaxTree.WriteString("Hello "),
SyntaxTree.Include("person", SyntaxTreeExpression.Self(model.GetType()))
);
Assert.Throws<VeilCompilerException>(() =>
{
ExecuteTemplate(template, model);
});
}
示例6: Should_be_able_to_output_value_types_from_collections
public void Should_be_able_to_output_value_types_from_collections()
{
var model = new { Items = new[] { "1", "2", "3", "4" } };
var template = SyntaxTree.Block(SyntaxTree.Iterate(
SyntaxTreeExpression.Property(model.GetType(), "Items"),
SyntaxTree.Block(
SyntaxTree.WriteExpression(SyntaxTreeExpression.Self(typeof(string)))
)
));
var result = ExecuteTemplate(template, model);
Assert.That(result, Is.EqualTo("1234"));
}
示例7: SholdKnowIfATypeIsAListOfResources
public void SholdKnowIfATypeIsAListOfResources()
{
var list = new List<IBehaveAsResource>();
var array = new[] {new SomeResource()};
var notAResourceList = new List<int>();
var notAResourceArray = new[] {1, 2};
Assert.IsTrue(list.GetType().IsAListOfResources());
Assert.IsTrue(array.GetType().IsAListOfResources());
Assert.IsFalse(notAResourceList.GetType().IsAListOfResources());
Assert.IsFalse(notAResourceArray.GetType().IsAListOfResources());
}
示例8: Should_be_able_to_iterate_an_array
public void Should_be_able_to_iterate_an_array()
{
var model = new { Items = new[] { "1", "2" } };
var template = SyntaxTree.Block(SyntaxTree.Iterate(
SyntaxTreeExpression.Property(model.GetType(), "Items"),
SyntaxTree.Block(
SyntaxTree.WriteString("Item")
),
SyntaxTree.Block(
SyntaxTree.WriteString("Empty")
)
));
var result = ExecuteTemplate(template, model);
Assert.That(result, Is.EqualTo("ItemItem"));
}
示例9: Root_model_of_template_should_be_the_model_executed_against
public void Root_model_of_template_should_be_the_model_executed_against()
{
var model = new { Name = "Joe", Company = new { Name = "Foo", Departments = new[] { "IT", "Admin" } } };
RegisterTemplate("company", SyntaxTree.Block(
SyntaxTree.WriteExpression(SyntaxTreeExpression.Property(model.Company.GetType(), "Name")),
SyntaxTree.WriteString(" - "),
SyntaxTree.Iterate(SyntaxTreeExpression.Property(model.Company.GetType(), "Departments"), SyntaxTree.Block(
SyntaxTree.WriteExpression(SyntaxTreeExpression.Property(model.Company.GetType(), "Name", ExpressionScope.RootModel))
))
));
var template = SyntaxTree.Block(
SyntaxTree.Include("company", SyntaxTreeExpression.Property(model.GetType(), "Company"))
);
var result = ExecuteTemplate(template, model);
Assert.That(result, Is.EqualTo("Foo - FooFoo"));
}
示例10: Does_encode_unicode
public void Does_encode_unicode()
{
string test = "<\"I get this : ";
var obj = new { test };
using (var mem = new System.IO.MemoryStream())
{
ServiceStack.Text.JsonSerializer.SerializeToStream(obj, obj.GetType(), mem);
var encoded = System.Text.Encoding.UTF8.GetString(mem.ToArray());
var copy1 = JsonObject.Parse(encoded);
Assert.That(test, Is.EqualTo(copy1["test"]));
System.Diagnostics.Debug.WriteLine(copy1["test"]);
}
}
示例11: Should_be_able_to_extend_a_template
public void Should_be_able_to_extend_a_template()
{
var model = new { Name = "Bob" };
RegisterTemplate("master", SyntaxTree.Block(
SyntaxTree.WriteString("<html><head>"),
SyntaxTree.Override("head"),
SyntaxTree.WriteString("</head></html>")
));
var template = SyntaxTree.Extend("master", new Dictionary<string, SyntaxTreeNode> {
{
"head",
SyntaxTree.Block(
SyntaxTree.WriteString("<title>"),
SyntaxTree.WriteExpression(SyntaxTreeExpression.Property(model.GetType(), "Name")),
SyntaxTree.WriteString("</title>")
)
}
});
var result = ExecuteTemplate(template, model);
Assert.That(result, Is.EqualTo("<html><head><title>Bob</title></head></html>"));
}
示例12: AnonObjectIsNotSimpleType
public void AnonObjectIsNotSimpleType()
{
var dummyObject = new { id = 1, Name = "fred" };
Assert.That(reader.IsSimpleType(dummyObject.GetType()), Is.False);
}
示例13: Should_render_empty_block_no_items_in_collection
public void Should_render_empty_block_no_items_in_collection()
{
var model = new { Items = new List<string> { } };
var template = SyntaxTree.Block(SyntaxTree.Iterate(
SyntaxTreeExpression.Property(model.GetType(), "Items"),
SyntaxTree.Block(
SyntaxTree.WriteString("Item")
),
SyntaxTree.Block(
SyntaxTree.WriteString("Empty")
)
));
var result = ExecuteTemplate(template, model);
Assert.That(result, Is.EqualTo("Empty"));
}
示例14: GetFlowAuths
public IList<dynamic> GetFlowAuths(decimal flowId)
{
using (var ctx = new OAContext())
{
var x = new
{
flow_id = 1m,
auth_to = 1m,
auth_to_name = ""
};
var t = x.GetType();
var re = ctx.SqlDynamic(string.Format(@"
select fa.*,nvl(o.org_name,'') || nvl(d.dept_name,'') || nvl(r.role_name,'') as auth_name from t_flow_auth fa left join t_org o on fa.auth_to = o.org_id
left join t_dept d on fa.auth_to = d.dept_id
left join t_role r on fa.auth_to = r.role_id
where fa.flow_id={0}", flowId));
return re;
}
}