当前位置: 首页>>代码示例>>C#>>正文


C# IPublishedContent.GetType方法代码示例

本文整理汇总了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;
 }
开发者ID:ksolberg,项目名称:Hybrid-Framework-for-Umbraco-v7-Best-Practises,代码行数:7,代码来源:ModelLogic.cs

示例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
					};
		}
开发者ID:elrute,项目名称:Triphulcas,代码行数:59,代码来源:DynamicPublishedContent.cs


注:本文中的IPublishedContent.GetType方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。