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


C# ITemplate.AddServerInterface方法代码示例

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


在下文中一共展示了ITemplate.AddServerInterface方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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.ProcessingInstruction || (node.Name != "inherits" && node.Name != "implements"))
				return false;

			if (!isRoot)
				throw ParserUtils.TemplateErrorException(string.Format("The {0} directive can only appear outside of the template.", node.Name));
				
			string[] sideArr = Utils.RegexExec(node.Value, "side=\"([^\"]*)\"", "");
			string[] typeArr = Utils.RegexExec(node.Value, "type=\"([^\"]*)\"", "");
	
			if (typeArr == null)
				throw ParserUtils.TemplateErrorException(node.Name + " elements must have the type specified.");
			if (sideArr == null)
				throw ParserUtils.TemplateErrorException(node.Name + " elements must have the side specified.");

			string side = sideArr[1].Trim(), type = typeArr[1].Trim();

			bool serverSide, clientSide;
			switch (side) {
				case "client":
					serverSide = false;
					clientSide = true;
					break;
				case "server":
					serverSide = true;
					clientSide = false;
					break;
				case "both":
					serverSide = true;
					clientSide = true;
					break;
				default:
					throw ParserUtils.TemplateErrorException("The side attribute of the " + node.Name + " element must be 'client', 'server', or 'both'.");
			}

			if (node.Name == "implements") {
				if (serverSide) {
					if (template.ImplementsServerInterface(type))
						throw ParserUtils.TemplateErrorException("The interface " + type + " is implemented more than once on the server side.");
					template.AddServerInterface(type);
				}
				if (clientSide) {
					if (template.ImplementsClientInterface(type))
						throw ParserUtils.TemplateErrorException("The interface " + type + " is implemented more than once on the client side.");
					template.AddClientInterface(type);
				}
			}
			else {
				if (serverSide) {
					if (template.ServerInherits != null)
						throw ParserUtils.TemplateErrorException("Cannot inherit from more than one class on the server side.");
					template.ServerInherits = type;
				}
				if (clientSide) {
					if (template.ClientInherits != null)
						throw ParserUtils.TemplateErrorException("Cannot inherit from more than one class on the client side.");
					template.ClientInherits = type;
				}
			}

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


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