Ejemplo n.º 1
0
		/// <summary>
		/// Creates an instance of <see cref="ChildType"/> from <paramref name="descriptor"/>.
		/// </summary>
		/// <param name="context">The <see cref="IMansionContext"/>.</param>
		/// <param name="descriptor">The <see cref="ChildTypeDescriptor"/>.</param>
		/// <param name="behavior">The <see cref="CmsBehavior"/>.</param>
		public static void Create(IMansionContext context, ChildTypeDescriptor descriptor, CmsBehavior behavior)
		{
			// validate arguments
			if (context == null)
				throw new ArgumentNullException("context");
			if (descriptor == null)
				throw new ArgumentNullException("descriptor");
			if (behavior == null)
				throw new ArgumentNullException("behavior");

			// get the type
			var type = descriptor.Properties.Get<ITypeDefinition>(context, "type", null);
			var baseType = descriptor.Properties.Get<ITypeDefinition>(context, "baseType", null);
			if (type == null && baseType == null)
				throw new InvalidOperationException(string.Format("Invalid child type descriptor on type '{0}'. Specify either an type or a baseType.", descriptor.TypeDefinition.Name));
			if (type != null && baseType != null)
				throw new InvalidOperationException(string.Format("Invalid child type descriptor on type '{0}'. Ambigious type detected. Specify either an type or a baseType.", descriptor.TypeDefinition.Name));

			if (type != null)
				CreateChildType(context, descriptor, behavior, type);
			else
			{
				CreateChildType(context, descriptor, behavior, baseType);
				foreach (var inheritingType in baseType.GetInheritingTypes(context))
					CreateChildType(context, descriptor, behavior, inheritingType);
			}
		}
Ejemplo n.º 2
0
		/// <summary>
		/// Creates the child type.
		/// </summary>
		/// <param name="context"></param>
		/// <param name="descriptor"></param>
		/// <param name="behavior"></param>
		/// <param name="type"></param>
		private static void CreateChildType(IMansionContext context, ChildTypeDescriptor descriptor, CmsBehavior behavior, ITypeDefinition type)
		{
			// create the child type
			var childType = new ChildType(type);

			// check if there is an is allowed expression
			var isAllowedExpressionString = descriptor.Properties.Get(context, "allowedExpression", string.Empty);
			if (!string.IsNullOrEmpty(isAllowedExpressionString))
			{
				// get the expresion script service
				var expressionScriptService = context.Nucleus.ResolveSingle<IExpressionScriptService>();

				// compile the script
				childType.IsAllowedExpression = expressionScriptService.Parse(context, new LiteralResource(isAllowedExpressionString));
			}

			behavior.Add(childType);
		}