/// <summary> /// Converts to <see cref="CodeElement"/> type from <paramref name="value"/> /// </summary> /// <param name="context"></param> /// <param name="culture"></param> /// <param name="value"></param> /// <returns></returns> public override object ConvertFrom(ITypeDescriptorContext context, CultureInfo culture, object value) { if (value is string) { DTE dte = (DTE)context.GetService(typeof(DTE)); return(CodeModelUtil.ConvertFromString(dte, (string)value)); } return(base.ConvertFrom(context, culture, value)); }
/// <summary> /// Converts <paramref name="value"/> to type <paramref name="destinationType"/> /// </summary> /// <param name="context"></param> /// <param name="culture"></param> /// <param name="value">A <see cref="CodeElement"/> object</param> /// <param name="destinationType"></param> /// <returns>The FullName property of a <see cref="CodeElement"/></returns> public override object ConvertTo(ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, Type destinationType) { if (value is CodeElement && destinationType == typeof(string)) { return(((CodeElement)value).FullName); } else if (value is string) { DTE dte = (DTE)context.GetService(typeof(DTE)); return(CodeModelUtil.ConvertFromString(dte, (string)value)); } return(base.ConvertTo(context, culture, value, destinationType)); }
/// <summary> /// Obtains the <see cref="CodeClass"/> for the specified paramter "ClassName" /// </summary> /// <param name="currentValue"></param> /// <param name="newValue"></param> /// <returns></returns> /// <seealso cref="ValueProvider.OnBeginRecipe"/> public override bool OnBeginRecipe(object currentValue, out object newValue) { if (currentValue == null) { DTE dte = (DTE)GetService(typeof(DTE)); try { newValue = CodeModelUtil.GetCodeModel(dte).CodeTypeFromFullName(this.className); } catch { newValue = null; } if (newValue != null) { return(true); } } newValue = currentValue; return(false); }
/// <summary> /// Obtains the <see cref="CodeClass"/> for the specified paramter "ClassName" /// </summary> /// <param name="currentValue"></param> /// <param name="newValue"></param> /// <returns></returns> /// <seealso cref="ValueProvider.OnBeginRecipe"/> public override bool OnBeginRecipe(object currentValue, out object newValue) { IDictionaryService dictService = (IDictionaryService)GetService(typeof(IDictionaryService)); if (dictService != null && dictService.GetValue(argumentName) != null) { DTE dte = (DTE)GetService(typeof(DTE)); CodeClass childClass = (CodeClass)dictService.GetValue(argumentName); CodeClass codeClass = (CodeClass)childClass.Bases.Item(1); string fullName = codeClass.FullName; int leftParam = fullName.IndexOf('<'); int rightParam = fullName.LastIndexOf('>'); if (leftParam != -1 && rightParam != -1 && leftParam < rightParam) { fullName = fullName.Substring(leftParam + 1, rightParam - leftParam); string[] parameters = fullName.Split(','); if (parameter < parameters.Length && parameter >= 0) { string parameterName = parameters[parameter]; try { newValue = CodeModelUtil.GetCodeModel(dte).CodeTypeFromFullName(parameterName); } catch { newValue = null; } if (newValue != null) { return(true); } } } } newValue = currentValue; return(false); }
protected override void DoValidate(string objectToValidate, object currentTarget, string key, ValidationResults validationResults) { if (objectToValidate == null) { this.LogValidationResult(validationResults, this.DefaultMessageTemplate, currentTarget, key); } else { IServiceProviderProviderPageModel pageModel = currentTarget as IServiceProviderProviderPageModel; if (pageModel != null) { IServiceProvider _serviceProvider = pageModel.ServiceProvider; if (_serviceProvider != null) { DTE dte = (DTE)_serviceProvider.GetService(typeof(DTE)); CodeElement el = CodeModelUtil.ConvertFromString(dte, objectToValidate); if (el == null) { this.LogValidationResult(validationResults, this.DefaultMessageTemplate, currentTarget, key); } } } } }