Esempio n. 1
0
        ///-------------------------------------------------------------------------------------------------------------
        /// <summary>
        ///	 Virtual method to allow language specific determination
        /// </summary>
        ///-------------------------------------------------------------------------------------------------------------
        public /*protected, but public for FSharp.Project.dll*/ virtual bool ShouldDeclareField(string name, string typeName)
        {
            // Don't add field if already defined in codebehind or exposed from base class
            bool declareField = true;

            if (_codeFields != null && _codeFields.ContainsKey(name))
            {
                FieldData fieldData = _codeFields[name];
                if (fieldData != null)
                {
                    if (fieldData.Depth == 0)
                    {
                        // For immediate class we don't re-declare regardless
                        // of access modifiers.  If the field is not visible to the run-time
                        // it will not be set and code against it will fail.
                        declareField = false;
                    }
                    else if (fieldData.IsProtected || fieldData.IsPublic)
                    {
                        // For bases we do not re-declare if already accessible
                        // (internal, private are not accesible to page assembly)
                        declareField = false;
                    }
                }
            }

            return(declareField);
        }
Esempio n. 2
0
        ///-------------------------------------------------------------------------------------------------------------
        /// <summary>
        ///
        /// </summary>
        ///-------------------------------------------------------------------------------------------------------------
        void IVsCodeBehindCodeGenerator.EnsureControlDeclaration(string name, string typeName)
        {
            if (ShouldDeclareField(name, typeName))
            {
                typeName = GetDeclarationTypeName(name, typeName);

                CodeMemberField field = new CodeMemberField(typeName, name);

                // Check if someone made the declaration public in the designer file
                bool isPublic = false;
                if (_designerFields != null && _designerFields.ContainsKey(name))
                {
                    FieldData fieldData = _designerFields[name];
                    if (fieldData != null)
                    {
                        isPublic = fieldData.IsPublic;
                    }
                }

                // Set access to public or protected
                field.Attributes &= ~MemberAttributes.AccessMask;
                if (isPublic)
                {
                    field.Attributes |= MemberAttributes.Public;
                }
                else
                {
                    field.Attributes |= MemberAttributes.Family;
                }

                SetAdditionalFieldData(field);

                _ctd.Members.Add(field);
            }
        }