本文整理汇总了C#中IPublishedContent.GetType方法的典型用法代码示例。如果您正苦于以下问题:C# IPublishedContent.GetType方法的具体用法?C# IPublishedContent.GetType怎么用?C# IPublishedContent.GetType使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类IPublishedContent
的用法示例。
在下文中一共展示了IPublishedContent.GetType方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: CreateMagicModel
private static object CreateMagicModel(Type genericType, IPublishedContent content)
{
var contentType = content.GetType();
var modelType = genericType.MakeGenericType(contentType);
var model = Activator.CreateInstance(modelType, content);
return model;
}
示例2: GetPropertyInternal
private PropertyResult GetPropertyInternal(string alias, IPublishedContent content, bool checkUserProperty = true)
{
if (alias.IsNullOrWhiteSpace()) throw new ArgumentNullException("alias");
if (content == null) throw new ArgumentNullException("content");
//if we're looking for a user defined property
if (checkUserProperty)
{
var prop = content.GetProperty(alias);
return prop == null
? null
: new PropertyResult(prop, PropertyResultType.UserProperty)
{
DocumentTypeAlias = content.DocumentTypeAlias,
DocumentId = content.Id
};
}
//reflect
Func<string, Attempt<object>> getMember =
memberAlias =>
{
try
{
return new Attempt<object>(true,
content.GetType().InvokeMember(memberAlias,
System.Reflection.BindingFlags.GetProperty |
System.Reflection.BindingFlags.Instance |
System.Reflection.BindingFlags.Public,
null,
content,
null));
}
catch (MissingMethodException ex)
{
return new Attempt<object>(ex);
}
};
//try with the current casing
var attempt = getMember(alias);
if (!attempt.Success)
{
//if we cannot get with the current alias, try changing it's case
attempt = alias[0].IsUpperCase()
? getMember(alias.ConvertCase(StringAliasCaseType.CamelCase))
: getMember(alias.ConvertCase(StringAliasCaseType.PascalCase));
}
return !attempt.Success
? null
: new PropertyResult(alias, attempt.Result, Guid.Empty, PropertyResultType.ReflectedProperty)
{
DocumentTypeAlias = content.DocumentTypeAlias,
DocumentId = content.Id
};
}