public static IResource InstantiateTemplate(IResource template, object param, string representation, string[] resTypes) { #region Preconditions if (template.Type != FilterManagerProps.ConditionTemplateResName) { throw new InvalidOperationException("Input parameter must be of ConditionTemplate resource type"); } #endregion Preconditions string propName = template.GetStringProp("ApplicableToProp"); ConditionOp op = (ConditionOp)template.GetProp("ConditionOp"); //----------------------------------------------------------------- IResource condition; if (op == ConditionOp.Eq && ResourceTypeHelper.IsDateProperty(propName)) { condition = TimeSpan2Condition((string)param, propName, resTypes); } else if (op == ConditionOp.QueryMatch) { string sectionName = null; if (template.HasProp("SectionOrder")) { sectionName = DocSectionHelper.FullNameByOrder((uint)template.GetIntProp("SectionOrder")); } condition = fMgr.CreateQueryConditionAux(resTypes, (string)param, sectionName); } else if (op == ConditionOp.Eq || op == ConditionOp.Has) { condition = fMgr.CreateStandardConditionAux(resTypes, propName, op, (string)param); } else if (op == ConditionOp.In) { condition = fMgr.CreateStandardConditionAux(resTypes, propName, op, (IResourceList)param); } else if (op == ConditionOp.InRange) { condition = IntRange2Condition((string)param, propName); } else { throw new InvalidOperationException("Not all Operations are supported now"); } FilterRegistry.ReferCondition2Template(condition, template); //----------------------------------------------------------------- // Do not forget to set additional parameters from the template // and representation, e.g. if the template has "custom" style, // propagate it to the aux condition. //----------------------------------------------------------------- ResourceProxy proxy = new ResourceProxy(condition); proxy.BeginUpdate(); if (template.GetStringProp("ConditionType") == "custom") { proxy.SetProp("ConditionType", "custom"); } if (!String.IsNullOrEmpty(representation)) { proxy.SetProp("SurfaceConditionVal", representation); } proxy.EndUpdate(); return(condition); }