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


C# ITemplate.AddMember方法代码示例

本文整理汇总了C#中ITemplate.AddMember方法的典型用法代码示例。如果您正苦于以下问题:C# ITemplate.AddMember方法的具体用法?C# ITemplate.AddMember怎么用?C# ITemplate.AddMember使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在ITemplate的用法示例。


在下文中一共展示了ITemplate.AddMember方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: TryProcess

		public bool TryProcess(IDocumentProcessor docProcessor, XmlNode node, bool isRoot, ITemplate template, IRenderFunction currentRenderFunction) {
			if (node.NodeType != XmlNodeType.ProcessingInstruction || node.Name != "view")
				return false;
			if (!isRoot)
				throw ParserUtils.TemplateErrorException(string.Format("The view directive can only appear outside of the template.", node.Name));

			string[] serverTypeArr = Utils.RegexExec(node.Value, "modelType=\"([^\"]*)\"", "");
			string[] clientTypeArr = Utils.RegexExec(node.Value, "clientModelType=\"([^\"]*)\"", "");
			if (serverTypeArr == null && clientTypeArr != null)
				throw ParserUtils.TemplateErrorException("You cannot specify a client type for the model if you don't specify a server type");

			if (template.HasMember("Model") || template.HasMember("model") || template.HasMember("Saltarelle.Mvc.IView.Model"))
				throw ParserUtils.TemplateErrorException("The template already defines at least one of the members essential to use the view directive. Have you specified <?view?> more than once?");

			string serverType = (serverTypeArr != null ? serverTypeArr[1] : "object"), clientType = (clientTypeArr != null ? clientTypeArr[1] : null);
			string viewInterface = "Saltarelle.Mvc.IView<" + serverType + ">";

			if (template.ImplementsServerInterface(viewInterface))
				throw ParserUtils.TemplateErrorException("The template already implements the interface " + viewInterface + ".");

			template.AddServerInterface(viewInterface);
			template.AddMember(new FieldMember("model", serverType, clientType));
			template.AddMember(new PropertyMember("Model", serverType, null, AccessModifier._Public, "model", serverType, null, true, true, "ModelChanged", false));
			template.AddMember(new PropertyMember("Saltarelle.Mvc.IView.Model", "object", null, AccessModifier._None, "model", serverType, null, true, true, "ModelChanged", false));

			return true;
		}
开发者ID:fiinix00,项目名称:Saltarelle,代码行数:27,代码来源:ViewDirectiveNodeProcessor.Shared.cs

示例2: TryProcess

		public bool TryProcess(IDocumentProcessor docProcessor, XmlNode node, bool isRoot, ITemplate template, IRenderFunction currentRenderFunction) {
			if (node.NodeType != XmlNodeType.Element || node.Name != "copyright")
				return false;

			if (node.ChildNodes.Count != 1 || node.ChildNodes[0].NodeType != XmlNodeType.Text)
				throw new TemplateErrorException("The copyright node must have a single text child.");

			CopyrightMember m = new CopyrightMember();
			if (template.HasMember(m.Name))
				throw new TemplateErrorException("Duplicate definition of the member " + m.Name);
			template.AddMember(m);
			
			currentRenderFunction.AddFragment(new CopyrightFragment(node.ChildNodes[0].Value));
			
			return true;
		}
开发者ID:fiinix00,项目名称:Saltarelle,代码行数:16,代码来源:CopyrightNodeProcessor.cs

示例3: TryProcess

		public bool TryProcess(IDocumentProcessor docProcessor, XmlNode node, bool isRoot, ITemplate template, IRenderFunction currentRenderFunction) {
			if (node.NodeType != XmlNodeType.ProcessingInstruction || node.Name != "field")
				return false;
			if (!isRoot)
				throw ParserUtils.TemplateErrorException(string.Format("The {0} directive can only appear outside of the template.", node.Name));

			string[] typeArr       = Utils.RegexExec(node.Value, "type=\"([^\"]*)\"", "");
			string[] serverTypeArr = Utils.RegexExec(node.Value, "serverType=\"([^\"]*)\"", "");
			string[] clientTypeArr = Utils.RegexExec(node.Value, "clientType=\"([^\"]*)\"", "");
			string[] nameArr       = Utils.RegexExec(node.Value, "name=\"([^\"]*)\"", "");

			string serverType, clientType;
			if (typeArr != null) {
				if (string.IsNullOrEmpty(typeArr[1].Trim()))
					throw ParserUtils.TemplateErrorException("No type was specified for the field");
				if (serverTypeArr != null || clientTypeArr != null)
					throw ParserUtils.TemplateErrorException("field elements cannot have both server/client type and type specified.");
				serverType = clientType = typeArr[1].Trim();
			}
			else if (serverTypeArr != null && clientTypeArr != null) {
				if (string.IsNullOrEmpty(serverTypeArr[1].Trim()))
					throw ParserUtils.TemplateErrorException("No server type was specified for the field");
				if (string.IsNullOrEmpty(clientTypeArr[1].Trim()))
					throw ParserUtils.TemplateErrorException("No client type was specified for the field");
				serverType = serverTypeArr[1].Trim();
				clientType = clientTypeArr[1].Trim();
			}
			else
				throw ParserUtils.TemplateErrorException("field elements must have the type specified (either 'type' or 'serverType' and 'clientType').");

			string name = nameArr != null ? nameArr[1].Trim() : null;
			if (string.IsNullOrEmpty(name))
				throw ParserUtils.TemplateErrorException("field elements must have a name specified.");

			if (template.HasMember(name))
				throw ParserUtils.TemplateErrorException("Duplicate member " + name);

			template.AddMember(new FieldMember(name, serverType, clientType));

			return true;
		}
开发者ID:fiinix00,项目名称:Saltarelle,代码行数:41,代码来源:FieldNodeProcessor.Shared.cs

示例4: ProcessDefFragment

		internal static void ProcessDefFragment(IDocumentProcessor docProcessor, XmlNode node, ITemplate template) {
			XmlAttribute nameAttr   = (XmlAttribute)node.Attributes.GetNamedItem("name");
			XmlAttribute paramsAttr = (XmlAttribute)node.Attributes.GetNamedItem("params");
			
			if (nameAttr == null)
				throw ParserUtils.TemplateErrorException("The <def-fragment> element must have the name attribute specified.");
			string name = nameAttr.Value;
			if (!ParserUtils.IsValidUnqualifiedName(name))
				throw ParserUtils.TemplateErrorException("The name " + name + " is not a valid unqualified identifier.");
			if (template.HasMember(name))
				throw ParserUtils.TemplateErrorException("Duplicate definition of member " + name + ".");

			RenderFunctionMember m = new RenderFunctionMember(nameAttr.Value, paramsAttr != null ? paramsAttr.Value : "");

			Utils.DoForEachChild(node, delegate(XmlNode n) {
				docProcessor.ProcessRecursive(n, template, m);
			});

			if (template.HasMember(name))
				throw ParserUtils.TemplateErrorException("Duplicate definition of member " + name + "."); // Just in case it has already been added during the recursive call.
			template.AddMember(m);
		}
开发者ID:fiinix00,项目名称:Saltarelle,代码行数:22,代码来源:FunctionDefinitionAndCallNodeProcessor.Shared.cs

示例5: TryProcess

		public bool TryProcess(IDocumentProcessor docProcessor, XmlNode node, bool isRoot, ITemplate template, IRenderFunction currentRenderFunction) {
			if (node.NodeType != XmlNodeType.Element || node.Name != "control")
				return false;
			
			if (isRoot)
				throw ParserUtils.TemplateErrorException("The root element can not be a control.");

			string id = null;
			string type = null;
			bool customInstantiate = false;
			Dictionary<string, TypedMarkupData> additionalProperties = new Dictionary<string, TypedMarkupData>();

			Utils.DoForEachAttribute(node, delegate(XmlAttribute attr) {
				if (attr.Name == "id") {
					if (!ParserUtils.IsValidUnqualifiedName(attr.Value))
						throw ParserUtils.TemplateErrorException("The id '" + attr.Value + "' is not a valid identifier.");
					id = attr.Value;
				}
				else if (attr.Name == "type") {
					if (string.IsNullOrEmpty(attr.Value))
						throw ParserUtils.TemplateErrorException("The control type '" + attr.Value + "' is invalid.");
					type = attr.Value;
				}
				else if (attr.Name == "customInstantiate") {
					string v = attr.Value.ToLowerCase();
					customInstantiate = Utils.ParseBool(v);
				}
				else {
					additionalProperties[attr.Name] = docProcessor.ParseTypedMarkup(attr.Value);
				}
			});
			
			if (customInstantiate && additionalProperties.Count > 0)
				throw ParserUtils.TemplateErrorException("There can not be any property assignments when customInstantiate is true.");

			if (type == null)
				throw ParserUtils.TemplateErrorException("The control '" + id + "' does not have a type specified.");
			if (id == null)
				id = template.GetUniqueId();
			if (template.HasMember(id))
				throw ParserUtils.TemplateErrorException("Duplicate definition of member " + id);

			var dependencies = new List<IMember>();
			int numInnerFragments = 0;
			if (Utils.GetNumChildNodes(node) > 0) {
				Utils.DoForEachChild(node, delegate(XmlNode n) {
					if (n.OuterXml.Trim() != "") {
						numInnerFragments++;
						string innerName = id + "_inner" + Utils.ToStringInvariantInt(numInnerFragments);
						if (template.HasMember(innerName))
							throw ParserUtils.TemplateErrorException("The internal name " + innerName + " is already in use.");
						IRenderFunction innerFunction = new RenderFunctionMember(innerName, "");
						template.AddMember((IMember)innerFunction);
						docProcessor.ProcessRecursive(n, template, innerFunction);
						dependencies.Add(innerFunction);
					}
				});
			}
			
			if (!template.HasMember("Container"))
				template.AddMember(new PropertyMember("Container", "IContainer", "IContainer", AccessModifier._Public, "_container", "IContainer", "IContainer", true, true, null, true));

			IMember controlMember = new InstantiatedControlMember(id, type, customInstantiate, additionalProperties, dependencies);
			template.AddMember(controlMember);

			currentRenderFunction.AddFragment(new InstantiatedControlFragment(id, customInstantiate, numInnerFragments));
			currentRenderFunction.AddDependency(controlMember);

			return true;
		}
开发者ID:fiinix00,项目名称:Saltarelle,代码行数:70,代码来源:ControlInstantiationNodeProcessor.Shared.cs

示例6: TryProcess

		public bool TryProcess(IDocumentProcessor docProcessor, XmlNode node, bool isRoot, ITemplate template, IRenderFunction currentRenderFunction) {
			if (node.NodeType != XmlNodeType.Element)
				return false;

			GenericElementProcessorContext context = new GenericElementProcessorContext();

			currentRenderFunction.AddFragment(new LiteralFragment("<" + node.Name));
			AddAttributeFragments(docProcessor, node, isRoot, template, currentRenderFunction, context);

			if (context.Id != null) {
				string tagName = node.Name;
				if (tagName.ToLowerCase() == "input" && context.Type != null)
					tagName += "/" + context.Type;
				template.AddMember(new NamedElementMember(tagName, context.Id));
			}

			if (noContentTags.Contains(node.Name)) {
				if (Utils.GetNumChildNodes(node) > 0)
					throw ParserUtils.TemplateErrorException("The tag " + node.Name + " can not have children.");
				currentRenderFunction.AddFragment(new LiteralFragment("/>"));
			}
			else {
				currentRenderFunction.AddFragment(new LiteralFragment(">"));
				Utils.DoForEachChild(node, delegate(XmlNode child) {
					docProcessor.ProcessRecursive(child, template, currentRenderFunction);
				});
				currentRenderFunction.AddFragment(new LiteralFragment("</" + node.Name + ">"));
			}

			return true;
		}
开发者ID:fiinix00,项目名称:Saltarelle,代码行数:31,代码来源:GenericElementProcessor.Shared.cs


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