internal virtual void ParseKnownAttributes(AttributesHelper attributes, ParseResult result, string baseUri, bool addImageQuery) { // version is optional int version; if (TryParse(result, attributes, ATTR_VISUAL_VERSION, out version)) { this.Version = version; } if (Context != NotificationType.Toast) { // Branding is optional Branding branding; if (TryParseEnum(result, attributes, ATTR_VISUAL_BRANDING, out branding, false)) // not case-sensitive { this.Branding = branding; } // DisplayName is optional XAttribute attrDisplayName = attributes.PopAttribute(ATTR_VISUAL_DISPLAY_NAME, false); // not case-sensitive if (attrDisplayName != null) { this.DisplayName = attrDisplayName.Value; } } }
/// <summary> /// Creates a new Detour. /// </summary> /// <param name="target"> /// The original function to detour. (This delegate should already be registered via /// Magic.RegisterDelegate) /// </param> /// <param name="newTarget">The new function to be called. (This delegate should NOT be registered!)</param> /// <param name="name">The name of the detour.</param> /// <returns> /// A <see cref="Detour" /> object containing the required methods to apply, remove, and call the original /// function. /// </returns> public Detour Create(Delegate target, Delegate newTarget, string name) { if (target == null) { throw new ArgumentNullException(nameof(target)); } if (newTarget == null) { throw new ArgumentNullException(nameof(newTarget)); } if (string.IsNullOrEmpty(name)) { throw new ArgumentNullException(nameof(name)); } if (!AttributesHelper.HasUfpAttribute(target)) { throw new Exception( "The target delegate does not have the proper UnmanagedFunctionPointer attribute!"); } if (!AttributesHelper.HasUfpAttribute(newTarget)) { throw new Exception( "The new target delegate does not have the proper UnmanagedFunctionPointer attribute!"); } if (InternalItems.ContainsKey(name)) { throw new ArgumentException($"The {name} detour already exists!", nameof(name)); } InternalItems[name] = new Detour(target, newTarget, name, MemoryPlus); return(InternalItems[name]); }
internal void ParseActivatableElementAttributes(XElement node, AttributesHelper attributes, ParseResult result) { IActivatableElement el = this as IActivatableElement; // activationType is optional ActivationType type; if (TryParseEnum(result, attributes, ATTR_ACTIVATIONTYPE, out type)) { el.ActivationType = type; } // arguments is required XAttribute attrArguments = attributes.PopAttribute(ATTR_ARGUMENTS); if (attrArguments == null) { // If we're in an activation type that requires attributes if (el.ActivationType != ActivationType.None) { result.AddErrorButRenderAllowed("arguments attribute is required.", XmlTemplateParser.GetErrorPositionInfo(node)); throw new IncompleteElementException(); } } else { el.Arguments = attrArguments.Value; } }
/// <summary>Annotates the specified tree node.</summary> /// <param name="treeNode">The tree node.</param> /// <param name="attribute">The attribute.</param> public static void Annotate(this ITreeNode treeNode, CodeAnnotationAttribute attribute) { var owner = treeNode as IAttributesOwnerDeclaration; if (owner == null) { return; } string attributeName; switch (attribute) { case CodeAnnotationAttribute.NotNull: attributeName = CodeAnnotationsCache.NotNullAttributeShortName; break; case CodeAnnotationAttribute.CanBeNull: attributeName = CodeAnnotationsCache.CanBeNullAttributeShortName; break; default: return; } AttributesHelper.SetAttribute(owner, attributeName); }
internal override void ParseKnownAttributes(XElement node, AttributesHelper attributes, ParseResult result, string baseUri, bool addImageQuery) { base.ParseKnownAttributes(node, attributes, result, baseUri, addImageQuery); // placement defaults to inline Placement placement; if (TryParseEnum(result, attributes, ATTR_IMAGE_PLACEMENT, out placement)) { this.Placement = placement; } // hint-removeMargin is optional bool hintRemoveMargin; if (TryParse(result, attributes, ATTR_IMAGE_HINT_REMOVE_MARGIN, out hintRemoveMargin)) { this.HintRemoveMargin = hintRemoveMargin; } // hint-align is optional HintImageAlign hintAlign; if (TryParseEnum(result, attributes, ATTR_IMAGE_HINT_ALIGN, out hintAlign)) { this.HintAlign = hintAlign; } }
internal virtual void ParseKnownAttributes(XElement node, AttributesHelper attributes, ParseResult result, string baseUri, bool addImageQuery) { // src is required XAttribute attrSrc = attributes.PopAttribute(ATTR_IMAGE_SRC); if (attrSrc == null) { result.AddError("src attribute on image element is required.", XmlTemplateParser.GetErrorPositionInfo(node)); throw new IncompleteElementException(); } this.Src = XmlTemplateParser.ConstructUri(attrSrc.Value, baseUri, addImageQuery); // alt is optional, I don't use it right now either attributes.PopAttribute(ATTR_IMAGE_ALT); // hint-crop is optional HintCrop hintCrop; if (TryParseEnum(result, attributes, ATTR_IMAGE_HINT_CROP, out hintCrop)) { this.HintCrop = hintCrop; } }
internal void Parse(ParseResult result, XElement node, string baseUri, bool addImageQuery) { if (!XmlTemplateParser.EnsureNodeOnlyHasElementsAsChildren(result, node)) { throw new IncompleteElementException(); } AttributesHelper attributes = new AttributesHelper(node.Attributes()); ParseKnownAttributes(node, attributes, result, baseUri, addImageQuery); HandleRemainingAttributes(attributes, result); // 0-n children foreach (XElement child in node.Elements()) { try { HandleChild(result, child, baseUri, addImageQuery); } catch (IncompleteElementException) { } } }
internal bool TryParseEnum <TEnum>(ParseResult result, AttributesHelper attributes, string attributeName, out TEnum answer, bool caseSensitive = true) where TEnum : struct, IConvertible { XAttribute attr = attributes.PopAttribute(attributeName, caseSensitive); // If it has the attribute if (attr != null) { // And the attribute has a value if (attr.Value != null) { if (TryParseEnum(attr.Value, out answer)) { return(true); } // Couldn't find matching enum result.AddWarning($@"Unknown value ""{attr.Value}"" on {attributeName} attribute", GetErrorPositionInfo(attr)); if (TryGetUnknownEnum(out answer)) { return(true); } } // Attribute doesn't have a value else { result.AddWarning($@"Attribute {attributeName} has no value specified", GetErrorPositionInfo(attr)); } } // Attribute isn't found, no warning answer = default(TEnum); return(false); }
internal virtual void ParseKnownAttributes(XElement node, AttributesHelper attributes, ParseResult result) { // id is required XAttribute attrId = attributes.PopAttribute(ATTR_ID); if (attrId == null) { result.AddError("id attribute on action element is required.", XmlTemplateParser.GetErrorPositionInfo(node)); throw new IncompleteElementException(); } this.Id = attrId.Value; // arguments is required XAttribute attrArguments = attributes.PopAttribute(ATTR_ARGUMENTS); if (attrArguments == null) { result.AddErrorButRenderAllowed("arguments attribute on action element is required.", XmlTemplateParser.GetErrorPositionInfo(node)); throw new IncompleteElementException(); } this.Arguments = attrArguments.Value; // activationType is optional ActivationType type; if (TryParseEnum(result, attributes, ATTR_ACTIVATIONTYPE, out type)) { this.ActivationType = type; } }
internal virtual void ParseKnownAttributes(XElement node, AttributesHelper attributes, ParseResult result) { // src is optional var srcAttr = attributes.PopAttribute(ATTR_SRC); if (srcAttr != null) { Uri srcUri; if (Uri.TryCreate(srcAttr.Value, UriKind.RelativeOrAbsolute, out srcUri)) { Src = srcUri; } else { result.AddWarning("Audio src value must be a valid Uri.", XmlTemplateParser.GetErrorPositionInfo(node)); } } // loop is optional, must be bool bool boolean; if (TryParse(result, attributes, ATTR_LOOP, out boolean)) { Loop = boolean; } if (TryParse(result, attributes, ATTR_SILENT, out boolean)) { Silent = boolean; } }
public static PropertyColumnMetamodel Create(LambdaExpression property, int width, ColumnWidthMode widthMode, FilterMetamodel filterMetamodel) { var name = ObjectHelper.GetPropertyName(property); var caption = AttributesHelper.GetPropertyDisplayName(property) ?? property.Name; // TODO: maybe better to provide explicite caption parameter? return(new PropertyColumnMetamodel(name, caption, width, widthMode, property.ReturnType, filterMetamodel)); }
internal void Parse(ParseResult result, XElement node) { if (!XmlTemplateParser.EnsureNodeOnlyHasElementsAsChildren(result, node)) { throw new IncompleteElementException(); } AttributesHelper attributes = new AttributesHelper(node.Attributes()); ParseKnownAttributes(node, attributes, result); HandleRemainingAttributes(attributes, result); // 0-n children foreach (XElement child in node.Elements()) { if (!result.IsOkForRender()) { break; } try { HandleChild(result, child); } catch (IncompleteElementException) { } } }
internal void Parse(ParseResult result, XElement node) { AttributesHelper attributes = new AttributesHelper(node.Attributes()); ParseKnownAttributes(node, attributes, result); HandleRemainingAttributes(attributes, result); // 0-n children foreach (XElement child in node.Elements()) { if (!result.IsOkForRender()) { break; } try { HandleChild(result, child); } catch (IncompleteElementException) { } } }
static Scanner() { ConstantTokensLookup = AttributesHelper.GetLookUpTable <Token, ConstantTokenAttribute>() .ToDictionary(x => x.Value.ReservedWord, x => x.Key); PatternTokensLookup = AttributesHelper.GetLookUpTable <Token, PatternTokenAttribute>(); IgnoredTokensLookup = AttributesHelper.GetLookUpTable <Token, IgnoredTokenAttribute>(); }
public void Test__GetPropertyAttributeValues__Working() { var name = AttributesHelper.GetPropertyAttributeValue <TestViewModel, DisplayAttribute, string>(x => x.Title, a => a.Name); var description = AttributesHelper.GetPropertyAttributeValue <TestViewModel, DisplayAttribute, string>(x => x.TypeName, a => a.Description); Assert.That(name, Is.EqualTo("Tytuł")); Assert.That(description, Is.EqualTo("Coś")); }
internal void Parse(ParseResult result, XElement node) { AttributesHelper attributes = new AttributesHelper(node.Attributes()); ParseKnownAttributes(node, attributes, result); HandleRemainingAttributes(attributes, result); }
internal void Parse(ParseResult result, XElement node, string baseUri, bool addImageQuery) { AttributesHelper attributes = new AttributesHelper(node.Attributes()); ParseKnownAttributes(node, attributes, result, baseUri, addImageQuery); HandleRemainingAttributes(attributes, result); }
private void ParseHintWeight(AttributesHelper attributes, ParseResult result) { int hintWeight; if (TryParse(result, attributes, ATTR_SUBGROUP_HINT_WEIGHT, out hintWeight)) { this.HintWeight = hintWeight; } }
internal void ParseKnownAttributes(AttributesHelper attributes, ParseResult result, bool isBindingRootLevel) { // Max lines is supported on non-toasts, and adaptive toasts, and group/subgroups if (Context != NotificationType.Toast || SupportedFeatures.AdaptiveToasts || !isBindingRootLevel) { // hint-max-lines is optional int hintMaxLines; if (TryParse(result, attributes, ATTR_TEXT_HINT_MAX_LINES, out hintMaxLines)) { this.HintMaxLines = hintMaxLines; } } // These features are supported on non-toasts, and group/subgroups if (Context != NotificationType.Toast || !isBindingRootLevel) { // hint-align is optional HintAlign hintAlign; if (TryParseEnum(result, attributes, ATTR_TEXT_HINT_ALIGN, out hintAlign)) { this.HintAlign = hintAlign; } // hint-min-lines is optional int hintMinLines; if (TryParse(result, attributes, ATTR_TEXT_HINT_MIN_LINES, out hintMinLines)) { this.HintMinLines = hintMinLines; } // hint-style is optional HintStyle hintStyle; if (TryParseEnum(result, attributes, ATTR_TEXT_HINT_STYLE, out hintStyle)) { this.HintStyle = hintStyle; } // hint-wrap is optional bool hintWrap; if (TryParse(result, attributes, ATTR_TEXT_HINT_WRAP, out hintWrap)) { this.HintWrap = hintWrap; } } if (Context == NotificationType.Tile) { Id = attributes.PopAttributeValue(ATTR_TEXT_ID); } TextPlacement placement; if (TryParseEnum(result, attributes, ATTR_TEXT_PLACEMENT, out placement)) { this.Placement = placement; } }
private void HandleHintCrop(ParseResult result, AttributesHelper attributes) { HintCrop hintCrop; if (TryParseEnum(result, attributes, ATTR_IMAGE_HINT_CROP, out hintCrop)) { this.HintCrop = hintCrop; } }
protected override void ParseKnownAttributes(XElement node, AttributesHelper attributes, ParseResult result, string baseUri, bool addImageQuery) { base.ParseKnownAttributes(node, attributes, result, baseUri, addImageQuery); // Template is required XAttribute attrTemplate = attributes.PopAttribute(ATTR_BINDING_TEMPLATE); if (attrTemplate == null) { result.AddWarning("template attribute wasn't provided on binding element.", GetErrorPositionInfo(node)); throw new IncompleteElementException(); } // If template is unknown, stop there Template template; if (!TryParseEnum(attrTemplate.Value, out template)) { result.AddWarning($"template attribute \"{attrTemplate.Value}\" is not supported.", GetErrorPositionInfo(attrTemplate)); throw new IncompleteElementException(); } this.Template = template; // Branding is optional Branding branding; if (TryParseEnum(result, attributes, ATTR_BINDING_BRANDING, out branding, false)) // not case-sensitive { this.Branding = branding; } // Display name is optional XAttribute attrDisplayName = attributes.PopAttribute(ATTR_BINDING_DISPLAY_NAME, false); // not case-sensitive if (attrDisplayName != null) { this.DisplayName = attrDisplayName.Value; } // hint-overlay is optional double hintOverlay; if (TryParse(result, attributes, ATTR_BINDING_HINT_OVERLAY, out hintOverlay)) { this.HintOverlay = hintOverlay; } // hint-textStacking is optional HintTextStacking hintTextStacking; if (TryParseEnum(result, attributes, ATTR_BINDING_HINT_TEXT_STACKING, out hintTextStacking)) { this.HintTextStacking = hintTextStacking; } }
internal void ParseKnownAttributes(XElement node, AttributesHelper attributes, ParseResult result) { // hint-systemCommands is optional HintSystemCommands hintSystemCommands; if (TryParseEnum(result, attributes, ATTR_HINT_SYSTEMCOMMANDS, out hintSystemCommands)) { this.HintSystemCommands = hintSystemCommands; } }
private void HandleHintOverlay(ParseResult result, AttributesHelper attributes) { // hint-overlay is optional double hintOverlay; if (TryParse(result, attributes, ATTR_HINT_OVERLAY, out hintOverlay)) { this.HintOverlay = hintOverlay; } }
internal void Parse(ParseResult result, XElement node) { // Inner text this.Text = node.Value; AttributesHelper attributes = new AttributesHelper(node.Attributes()); ParseKnownAttributes(attributes, result); HandleRemainingAttributes(attributes, result); }
protected void ParseKnownAttributes(XElement node, AttributesHelper attributes, ParseResult result, string baseUri, bool addImageQuery) { if (Context != NotificationType.Toast) { // hint-textStacking is optional HintTextStacking hintTextStacking; if (TryParseEnum(result, attributes, ATTR_TEXT_STACKING, out hintTextStacking)) { this.HintTextStacking = hintTextStacking; } } }
internal void ParseKnownAttributes(AttributesHelper attributes, ParseResult result, string baseUri, bool addImageQuery) { if (Context != NotificationType.Tile && Context != NotificationType.Toast) { // actionId is optional var attrActionId = attributes.PopAttribute(ATTR_ACTIONID); if (attrActionId != null) { this.ActionId = attrActionId.Value; } } }
internal void ParseKnownAttributes(XElement node, AttributesHelper attributes, ParseResult result) { // id is required XAttribute attrId = attributes.PopAttribute(ATTR_ID); if (attrId == null) { result.AddError("id attribute on input element is required.", XmlTemplateParser.GetErrorPositionInfo(node)); throw new IncompleteElementException(); } this.Id = attrId.Value; }
internal void Parse(ParseResult result, XElement node) { if (!XmlTemplateParser.EnsureNodeOnlyHasElementsAsChildren(result, node)) { throw new IncompleteElementException(); } AttributesHelper attributes = new AttributesHelper(node.Attributes()); ParseKnownAttributes(node, attributes, result); HandleRemainingAttributes(attributes, result); }
protected virtual void ParseKnownAttributes(XElement node, AttributesHelper attributes, ParseResult result) { // id is required XAttribute attrId = attributes.PopAttribute(ATTR_ID); if (attrId == null) { result.AddError("id attribute on input element is required.", XmlTemplateParser.GetErrorPositionInfo(node)); throw new IncompleteElementException(); } // type is required InputType type; if (!TryParseEnum(result, attributes, ATTR_TYPE, out type)) { result.AddErrorButRenderAllowed("type attribute on input element is required.", XmlTemplateParser.GetErrorPositionInfo(node)); throw new IncompleteElementException(); } this.Id = attrId.Value; this.Type = type; // title is optional var attrTitle = attributes.PopAttribute(ATTR_TITLE); if (attrTitle != null) { this.Title = attrTitle.Value; } // placeHolderContent is optional var attrPlaceHolderContent = attributes.PopAttribute(ATTR_PLACEHOLDERCONTENT); if (attrPlaceHolderContent != null) { this.PlaceHolderContent = attrPlaceHolderContent.Value; } // defaultInput is optional var attrDefaultInput = attributes.PopAttribute(ATTR_DEFAULTINPUT); if (attrDefaultInput != null) { this.DefaultInput = attrDefaultInput.Value; } }
protected override Expression VisitMember(MemberExpression node) { if (!AttributesHelper.IsAttributesClass(node.Member.DeclaringType)) { throw new NotSupportedException(); } var attributeName = node.ToString(); if (!_attributes.ContainsKey(attributeName)) { throw new AttributeMissingException(attributeName); } return(Expression.Constant(_attributes[attributeName])); }