public override void VisitControl(ResolvedControl control) { var helperDefinition = HelperDefinitionsStack.Peek(); var dataContextNameSet = false; if (control.TryGetProperty(DotvvmBindableObject.DataContextProperty, out var property)) { if (property is ResolvedPropertyBinding dataContextProperty) { var dataContextName = dataContextProperty.Binding.Value; helperDefinition.DataContextPrefixes.Add(dataContextName); dataContextNameSet = true; } } var controlType = control.Metadata.Type; if (controlType == typeof(DotvvmMarkupControl)) { var controlTreeRoot = seleniumGenerator.ResolveControlTree(control.Metadata.VirtualPath); if (controlTreeRoot != null && controlTreeRoot.Directives.TryGetValue("baseType", out var baseTypeDirectives)) { var(typeName, assemblyName) = GetSplitTypeName(baseTypeDirectives); var baseType = GetControlType(typeName, assemblyName); if (generators.ContainsKey(baseType)) { controlType = baseType; } } } if (generators.TryGetValue(controlType, out var generator)) { // generate the content var context = new SeleniumGeneratorContext() { Control = control, ExistingUsedSelectors = helperDefinition.ExistingUsedSelectors, UsedNames = helperDefinition.UsedNames, Visitor = this }; if (generator.CanAddDeclarations(helperDefinition, context)) { generator.AddDeclarations(helperDefinition, context); return; } } base.VisitControl(control); if (dataContextNameSet) { helperDefinition.DataContextPrefixes.RemoveAt(helperDefinition.DataContextPrefixes.Count - 1); } }
public static string GetValueOrNull(this ResolvedControl control, IPropertyDescriptor property) { IAbstractPropertySetter value; if (!control.TryGetProperty(property, out value) || !(value is ResolvedPropertyValue)) { return(null); } return(((ResolvedPropertyValue)value).Value?.ToString()); }
public static ResolvedPropertyBinding GetValueBindingOrNull(this ResolvedControl control, IPropertyDescriptor property) { IAbstractPropertySetter binding; if (!control.TryGetProperty(property, out binding)) { return(null); } return(binding as ResolvedPropertyBinding); }
public static string GetValue(this ResolvedControl control, IPropertyDescriptor property) { IAbstractPropertySetter value; if (!control.TryGetProperty(property, out value) || !(value is ResolvedPropertyValue)) { throw new CodeValidationException(string.Format(ValidationErrorMessages.MissingPropertyError, control.Metadata.Type.Name, property.Name)); } return(((ResolvedPropertyValue)value).Value?.ToString()); }
internal static string TryGetNameFromProperty(ResolvedControl control, DotvvmProperty property) { if (control.TryGetProperty(property, out IAbstractPropertySetter setter)) { switch (setter) { case ResolvedPropertyValue propertySetter: return(propertySetter.Value?.ToString()); case ResolvedPropertyBinding propertyBinding: return(propertyBinding.Binding.Value); } } return(null); }
public static string GetValueBindingTextOrNull(this ResolvedControl control, IPropertyDescriptor property) { IAbstractPropertySetter binding; if (!control.TryGetProperty(property, out binding) || !(binding is ResolvedPropertyBinding)) { return(null); } var typedBinding = (ResolvedPropertyBinding)binding; if (typedBinding.Binding.BindingType != typeof(ValueBindingExpression)) { return(null); } return(typedBinding.Binding.Value.Trim()); }
protected string TryGetNameFromProperty(ResolvedControl control, DotvvmProperty property) { IAbstractPropertySetter setter; if (control.TryGetProperty(property, out setter)) { if (setter is ResolvedPropertyValue) { return(RemoveNonIdentifierCharacters(((ResolvedPropertyValue)setter).Value?.ToString())); } else if (setter is ResolvedPropertyBinding) { var binding = ((ResolvedPropertyBinding)setter).Binding; return(RemoveNonIdentifierCharacters(binding.Value)); } } return(null); }
public static string GetCommandBindingText(this ResolvedControl control, IPropertyDescriptor property) { IAbstractPropertySetter binding; if (!control.TryGetProperty(property, out binding) || !(binding is ResolvedPropertyBinding)) { throw new CodeValidationException(string.Format(ValidationErrorMessages.MissingPropertyError, control.Metadata.Type.Name, property.Name)); } var typedBinding = (ResolvedPropertyBinding)binding; if (typedBinding.Binding.BindingType != typeof(CommandBindingExpression)) { throw new CodeValidationException(string.Format(ValidationErrorMessages.CommandBindingExpected, control.Metadata.Type.Name, property.Name)); } return(typedBinding.Binding.Value.Trim()); }