本文整理汇总了C#中ITemplate.HasMember方法的典型用法代码示例。如果您正苦于以下问题:C# ITemplate.HasMember方法的具体用法?C# ITemplate.HasMember怎么用?C# ITemplate.HasMember使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ITemplate
的用法示例。
在下文中一共展示了ITemplate.HasMember方法的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;
}
示例2: 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);
}
示例3: 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;
}
示例4: 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;
}
示例5: AddSingleAttributeFragments
internal static void AddSingleAttributeFragments(IDocumentProcessor docProcessor, string attrName, string attrValue, bool isRoot, ITemplate template, IRenderFunction fragments, GenericElementProcessorContext context) {
string actualName;
if (attrName == "actualName") {
// This will translate into "name", but not with our ID prefixed. We need this because for top-level templates we want the names undisturbed to allow for a nice form submission.
// However, for nested forms which we won't submit using the normal techniques, we need to prefix it in order to make radio buttons work reliably.
actualName = "name";
}
else
actualName = attrName;
fragments.AddFragment(new LiteralFragment(" " + actualName + "=\""));
if (attrName == "id") {
if (isRoot)
throw ParserUtils.TemplateErrorException("Can't specify an ID for the top level element.");
if (template.HasMember(attrValue))
throw ParserUtils.TemplateErrorException("Duplicate member " + attrValue);
context.Id = attrValue;
fragments.AddFragment(new IdFragment());
fragments.AddFragment(new LiteralFragment("_" + attrValue));
}
else if (attrName.ToLowerCase() == "for" || attrName.ToLowerCase() == "name") {
fragments.AddFragment(new IdFragment());
fragments.AddFragment(new LiteralFragment("_" + attrValue));
}
else {
IFragment f = docProcessor.ParseUntypedMarkup(attrValue);
fragments.AddFragment(f);
if (attrName.ToLowerCase() == "type") {
if (f is LiteralFragment)
context.Type = ((LiteralFragment)f).Text;
}
else if (isRoot && attrName.ToLowerCase() == "style") {
if (!(f is LiteralFragment) || !((LiteralFragment)f).Text.Trim().EndsWith(";"))
fragments.AddFragment(new LiteralFragment(";"));
fragments.AddFragment(new PositionFragment());
}
}
fragments.AddFragment(new LiteralFragment("\""));
}
示例6: 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;
}