Beispiel #1
0
 protected override void DoExecute(IMemberElement element)
 {
     if (IsRequired(element))
     {
         element.AddClass(requiredClass);
     }
 }
Beispiel #2
0
 protected override void DoExecute(IMemberElement element)
 {
     if (IsRequired(element))
     {
         element.AddClass(requiredClass);
     }
 }
		public void Execute(IMemberElement element) {
			string name = null;
			if(element.Builder.Attributes.TryGetValue("name", out name) && !string.IsNullOrEmpty(name))
			{
				name = name[0].ToString().ToLower() + name.Substring(1);
				element.Builder.MergeAttribute("name", name, true);
			}
		}
 public void Execute(IMemberElement element)
 {
     var helper = new MemberBehaviorHelper<RequiredAttribute>();
     var attribute = helper.GetAttribute(element);
     if (attribute != null)
     {
         element.SetAttr("class", "req");
     }
 }
        public void Execute(IMemberElement element)
        {
            var attribute = new MemberBehaviorHelper<StringLengthAttribute>().GetAttribute(element);

            if(attribute != null && element is ISupportsMaxLength)
            {
                element.SetAttr(HtmlAttribute.MaxLength, attribute.MaximumLength);
            }
        }
        private static bool elementIsLocal(IMemberElement element)
        {
            LanguageElementType elementType = element.ElementType;

            return((elementType == LanguageElementType.Variable) ||
                   (elementType == LanguageElementType.InitializedVariable) ||
                   (elementType == LanguageElementType.ImplicitVariable) ||
                   (elementType == LanguageElementType.Parameter) ||
                   (elementType == LanguageElementType.Const));
        }
        private static bool elementIsLocal(IMemberElement element)
        {
            LanguageElementType elementType = element.ElementType;

              return (elementType == LanguageElementType.Variable) ||
            (elementType == LanguageElementType.InitializedVariable) ||
            (elementType == LanguageElementType.ImplicitVariable) ||
            (elementType == LanguageElementType.Parameter) ||
            (elementType == LanguageElementType.Const);
        }
Beispiel #8
0
        public void Execute(IMemberElement element)
        {
            var helper = new MemberBehaviorHelper <RequiredAttribute>();

            var attribute = helper.GetAttribute(element);

            if (attribute != null)
            {
                element.SetAttr(HtmlAttribute.Class, "required");
            }
        }
        private static bool elementIsNested(IMemberElement element)
        {
            LanguageElementType elementType = element.ElementType;

              //if we are on a static field (or a constant that is not local), the element type is Variable, so we have to check if its a local variable
              //or not (if it's not, we have to treat the element as a nested element)
              if ((elementType == LanguageElementType.Variable) && (element is IFieldElement) && !(element as IFieldElement).IsLocal)
            return true;

              return (elementType == LanguageElementType.Property) ||
            (elementType == LanguageElementType.Method);
        }
Beispiel #10
0
 protected bool IsAutomaticallyRequired(IMemberElement element)
 {
     if (element.ForMember == null || !element.IsTextElement())
     {
         return false;
     }
     var memberType = element.ForMember.GetPropertyOrFieldType();
     if (memberType == null)
     {
         return false;
     }
     return memberType.IsValueType && !memberType.IsNullableType();
 }
        private static bool elementIsNested(IMemberElement element)
        {
            LanguageElementType elementType = element.ElementType;

            //if we are on a static field (or a constant that is not local), the element type is Variable, so we have to check if its a local variable
            //or not (if it's not, we have to treat the element as a nested element)
            if ((elementType == LanguageElementType.Variable) && (element is IFieldElement) && !(element as IFieldElement).IsLocal)
            {
                return(true);
            }

            return((elementType == LanguageElementType.Property) ||
                   (elementType == LanguageElementType.Method));
        }
Beispiel #12
0
        protected bool IsAutomaticallyRequired(IMemberElement element)
        {
            if (element.ForMember == null || !element.IsTextElement())
            {
                return(false);
            }
            var memberType = element.ForMember.GetPropertyOrFieldType();

            if (memberType == null)
            {
                return(false);
            }
            return(memberType.IsValueType && !memberType.IsNullableType());
        }
        public void Execute(IMemberElement element)
        {
            var helper = new MemberBehaviorHelper<RangeAttribute>();
            var attribute = helper.GetAttribute(element);

            if (attribute == null)
            {
                return;
            }

            if (element is ISupportsMaxLength)
            {
                element.SetAttr(HtmlAttribute.MaxLength, attribute.Maximum);
            }
        }
Beispiel #14
0
        public void Execute(IMemberElement element)
        {
            var helper    = new MemberBehaviorHelper <StringLengthAttribute>();
            var attribute = helper.GetAttribute(element);

            if (attribute == null)
            {
                return;
            }

            if (element is ISupportsMaxLength)
            {
                element.SetAttr(HtmlAttribute.MaxLength, attribute.MaximumLength);
            }
        }
Beispiel #15
0
        private static bool IsFieldOrPropertyOrVariable(CategorizedToken token)
        {
            if (CodeRush.Source.DeclaresLocal(token.Value))
            {
                // local variable or parameter
                return(true);
            }
            IMemberElement member = CodeRush.Source.GetMember(CodeRush.Source.ActiveClassInterfaceStructOrModule, token.Value);

            if (member != null && (member is Property || member is Variable || member is Event))
            {
                // is declared property or field or event
                return(true);
            }
            return(false);
        }
    public void Execute(IMemberElement element)
    {
        var attribute = element.GetAttribute <ValidationAttribute>();

        if (attribute == null)
        {
            return;
        }

        var formContext   = _viewPage.ViewContext.FormContext;
        var fieldMetadata = formContext.GetValidationMetadataForField(UiNameHelper.BuildNameFrom(element.ForMember), true);

        var modelMetadata = ModelMetadata.FromStringExpression(element.ForMember.Member.Name, _viewPage.ViewData);
        var validators    = ModelValidatorProviders.Providers.GetValidators(modelMetadata, _viewPage.ViewContext);

        validators.SelectMany(v => v.GetClientValidationRules()).ForEach(fieldMetadata.ValidationRules.Add);

        fieldMetadata.ValidationMessageId = element.ForMember.Member.Name + "_Label";
    }
 protected override void DoExecute(IMemberElement element)
 {
     if (element.ForMember == null)
     {
         return;
     }
     if (!element.IsTextElement())
     {
         return;
     }
     var memberType = element.ForMember.GetPropertyOrFieldType();
     if (memberType.IsNumber())
     {
         element.AddClass(numberClass);
     }
     else if (memberType == typeof(DateTime) || memberType == typeof(DateTime?))
     {
         element.AddClass(dateClass);
     }
 }
        static string GetNewName(IMemberElement element)
        {
            if (element == null)
                return null;

            string name = element.Name;

            if (String.IsNullOrEmpty(name))
                return null;

            name = name.TrimStart('_');

            if (name == String.Empty)
                return name;

            bool allUpper = true;
            foreach (char chr in name)
                if (char.IsLower(chr))
                {
                    allUpper = false;
                    break;
                }

            if (allUpper)
                name = name.ToLower();

            string firstLetter = name.Substring(0, 1);

            FirstLetterStyle firstLetterStyle;
            if (element is IFieldElement && element.Visibility != MemberVisibility.Public)
                firstLetterStyle = FirstLetterStyle.Lower;
            else
                firstLetterStyle = FirstLetterStyle.Upper;

            if (firstLetterStyle == FirstLetterStyle.Lower)
                firstLetter = firstLetter.ToLower();
            else
                firstLetter = firstLetter.ToUpper();

            return String.Format("{0}{1}", firstLetter, name.Remove(0, 1));
        }
Beispiel #19
0
        protected override void DoExecute(IMemberElement element)
        {
            if (element.ForMember == null)
            {
                return;
            }
            if (!element.IsTextElement())
            {
                return;
            }
            var memberType = element.ForMember.GetPropertyOrFieldType();

            if (memberType.IsNumber())
            {
                element.AddClass(numberClass);
            }
            else if (memberType == typeof(DateTime) || memberType == typeof(DateTime?))
            {
                element.AddClass(dateClass);
            }
        }
Beispiel #20
0
 protected virtual bool IsRequired(IMemberElement element)
 {
     return(IsAutomaticallyRequired(element));
 }
 public T GetAttribute(IMemberElement element)
 {
     return(GetAttribute(element.ForMember));
 }
 public void InvokeMethod(MethodInfo method, IMemberElement element, params object[] parameters)
 {
     method.Invoke(element, parameters);
 }
 public MethodInfo GetMethod(IMemberElement element, string methodName)
 {
     return(element.ForMember == null
                                 ? null
                                 : element.GetType().GetMethod(methodName));
 }
 protected void Establish_context(Expression<Func<FakeModel, object>> member)
 {
     behavior = new RequiredCssClassBehavior<RequiredAttribute>();
     element = new TextBox(member.GetNameFor(), member.GetMemberExpression(), null);
 }
 protected void Establish_context(Expression<Func<FakeModel, object>> member, string requiredClass)
 {
     behavior = requiredClass == null ? new RequiredCssClassBehavior() : new RequiredCssClassBehavior(requiredClass);
     element = new TextBox(member.GetNameFor(), member.GetMemberExpression(), null);
 }
        private void navigateToDefinition(LanguageElement element)
        {
            try
            {
                if (elementParentIsObjectCreationExpression(element))
                {
                    element = element.Parent;
                }

                IElement declaration = GetElementDeclaration(element);

                IMemberElement memberElement = null;

                if (declaration != null)
                {
                    if (isImplicitVariableDeclarationType(declaration))
                    {
                        memberElement = ((ObjectCreationExpression)((ImplicitVariable)declaration).Expression).ObjectType.GetDeclaration() as IMemberElement;
                    }
                    else if (declaration.ElementType == LanguageElementType.ObjectCreationExpression) //new SomeClass(...)
                    {
                        IObjectCreationExpression creationExp = declaration as IObjectCreationExpression;
                        memberElement = getObjectCreationExpression_MemberElement(creationExp);
                        if (memberElement == null)
                        {
                            memberElement = creationExp.ObjectType.GetDeclaration() as IMemberElement; //if can't find ctor, try at least to find the class
                        }
                    }
                    else
                    {
                        memberElement = declaration as IMemberElement;
                    }
                }

                if (memberElement == null)
                {
                    defaultGoToDefinition();
                    return;
                }

                IMemberElement nestedElement = null;
                if (elementIsNested(memberElement))
                {
                    nestedElement = memberElement;
                    memberElement = nestedElement.ParentType;
                }

                if (memberElement != null)
                {
                    IElement e = null;

                    if (elementIsLocal(memberElement))
                    {
                        e = memberElement;
                    }
                    else
                    {
                        foreach (ProjectElement p in CodeRush.Source.ActiveSolution.AllProjects)
                        {
                            e = p.FindElementByFullName(memberElement.FullName, true);
                            if (e != null)
                            {
                                break;
                            }
                        }
                    }

                    if (e != null)
                    {
                        SourceFile sourceFile = (e.FirstFile as SourceFile);
                        TextPoint  point      = e.NameRanges[0].Start;

                        if (nestedElement != null)
                        {
                            bool found = false;

                            var methodElement = nestedElement as IMethodElement;

                            foreach (IElement currElement in e.AllChildren)
                            {
                                if ((currElement.ElementType == nestedElement.ElementType) &&
                                    (currElement.FullName.Equals(nestedElement.FullName)))
                                {
                                    var currMethodElement = currElement as IMethodElement;

                                    if ((methodElement != null) && (currMethodElement != null))
                                    {
                                        found = checkIfParametersAreTheSame(methodElement, currMethodElement);
                                        if (found)
                                        {
                                            point = currElement.NameRanges[0].Start;
                                        }
                                    }
                                    else
                                    {
                                        point = currElement.NameRanges[0].Start;
                                        found = true;
                                    }

                                    if (found)
                                    {
                                        break;
                                    }
                                }
                            }

                            if (!found)
                            {
                                if ((methodElement != null) && (methodElement.IsConstructor))
                                {
                                    //must be default constructor (with no args), so jump to class instead
                                    point = e.NameRanges[0].Start;
                                }
                                else
                                {
                                    point = e.FindChildByName(nestedElement.Name).NameRanges[0].Start;
                                }
                            }
                        }

                        if (dropMarker)
                        {
                            CodeRush.Markers.Drop(MarkerStyle.System);
                        }

                        CodeRush.File.Activate(sourceFile.FilePath);

                        CodeRush.Caret.MoveTo(point);

                        if (showBeacon)
                        {
                            locatorBeacon1.Start(CodeRush.Documents.ActiveTextView, point.Line, point.Offset);
                        }
                    }
                    else
                    {
                        defaultGoToDefinition();
                    }
                }
            }
            catch (Exception ex)
            {
                ShowException(ex);
            }
        }
 protected void Establish_context(Expression <Func <FakeModel, object> > member, string requiredClass)
 {
     behavior = requiredClass == null ? new RequiredCssClassBehavior() : new RequiredCssClassBehavior(requiredClass);
     element  = new TextBox(member.GetNameFor(), member.GetMemberExpression(), null);
 }
Beispiel #28
0
 public void Execute(IMemberElement element)
 {
     ExecuteBase(element);
 }
 /// <summary>
 /// Gets the attibute, if esists, of the specified type for the specified element.
 /// </summary>
 /// <typeparam name="T">The type of attribute to get.</typeparam>
 /// <param name="element">The element.</param>
 /// <returns>The attribute or null if not exists.</returns>
 public static T GetAttribute <T>(this IMemberElement element) where T : Attribute
 {
     return(element.ForMember.GetAttribute <T>());
 }
 protected void Establish_context(Expression <Func <FakeModel, object> > member)
 {
     behavior = new RequiredCssClassBehavior <RequiredAttribute>();
     element  = new TextBox(member.GetNameFor(), member.GetMemberExpression(), null);
 }
Beispiel #31
0
 protected virtual bool IsRequired(IMemberElement element)
 {
     return IsAutomaticallyRequired(element);
 }
 protected void Establish_context(Expression <Func <FakeModel, object> > member, string dateClass, string numberClass)
 {
     behavior = new TypeCssClassBehavior(numberClass, dateClass);
     element  = new TextBox(member.GetNameFor(), member.GetMemberExpression(), null);
 }
Beispiel #33
0
 public void Execute(IMemberElement elment)
 {
     ExecuteInvoked();
 }
 protected void Establish_context(Expression<Func<FakeModel, object>> member, string dateClass, string numberClass)
 {
     behavior = new TypeCssClassBehavior(numberClass, dateClass);
     element = new TextBox(member.GetNameFor(), member.GetMemberExpression(), null);
 }