Пример #1
0
        public void GetTypeConverter()
        {
            CodeDomProvider provider = GetProvider();
            TypeConverter   tc;

            tc = provider.GetConverter(typeof(MemberAttributes));
            Assert.True(tc.CanConvertFrom(typeof(string)));
            Assert.True(tc.CanConvertTo(typeof(string)));

            tc = provider.GetConverter(typeof(TypeAttributes));
            Assert.True(tc.CanConvertFrom(typeof(string)));
            Assert.True(tc.CanConvertTo(typeof(string)));
        }
Пример #2
0
        internal static void PopulateModifiers(CodeDomProvider codeDomProvider)
        {
            TypeConverter memberAttributesConverter = codeDomProvider.GetConverter(typeof(MemberAttributes));

            if (memberAttributesConverter != null)
            {
                if (memberAttributesConverter.CanConvertTo(typeof(string)))
                {
                    try
                    {
                        _private              = memberAttributesConverter.ConvertToInvariantString(MemberAttributes.Private).ToUpperInvariant();
                        _public               = memberAttributesConverter.ConvertToInvariantString(MemberAttributes.Public).ToUpperInvariant();
                        _protected            = memberAttributesConverter.ConvertToInvariantString(MemberAttributes.Family).ToUpperInvariant();
                        _internal             = memberAttributesConverter.ConvertToInvariantString(MemberAttributes.Assembly).ToUpperInvariant();
                        _protectedInternal    = memberAttributesConverter.ConvertToInvariantString(MemberAttributes.FamilyOrAssembly).ToUpperInvariant();
                        _protectedAndInternal = memberAttributesConverter.ConvertToInvariantString(MemberAttributes.FamilyAndAssembly).ToUpperInvariant();
                    }
                    catch (NotSupportedException)
                    {
                    }
                }
            }

            TypeConverter typeAttributesConverter = codeDomProvider.GetConverter(typeof(TypeAttributes));

            if (typeAttributesConverter != null)
            {
                if (typeAttributesConverter.CanConvertTo(typeof(string)))
                {
                    try
                    {
                        _internalClass = typeAttributesConverter.ConvertToInvariantString(TypeAttributes.NotPublic).ToUpperInvariant();
                        _publicClass   = typeAttributesConverter.ConvertToInvariantString(TypeAttributes.Public).ToUpperInvariant();
                    }
                    catch (NotSupportedException)
                    {
                    }
                }
            }
        }
Пример #3
0
        public override bool Execute()
        {
            try
            {
                try
                {
                    codeDomProvider = CodeDomProvider.CreateProvider(Language);
                }
                catch (ConfigurationErrorsException)
                {
                    LogError(classNameLineNumber, 1, "CodeDom provider for language '" + Language + "' not found.");
                    return(false);
                }

                typeAttributesConverter = codeDomProvider.GetConverter(typeof(TypeAttributes));

                if (!ParseInput())
                {
                    return(false);
                }

                if (lambdas.Count == 0)
                {
                    OutputFileName = null;
                    return(true);
                }

                if (className == null)
                {
                    LogError(classNameLineNumber, 1501, "x:Class not found on root element.");
                    return(false);
                }
                if (!className.Contains("."))
                {
                    LogError(classNameLineNumber, 1502, "x:Class does not include namespace name.");
                    return(false);
                }

                return(GenerateOutput());
            }
            catch (Exception ex)
            {
                LogError(null, 0, 0, ex.Message);
                throw;
            }
        }
Пример #4
0
            /// <devdoc>
            ///     Returns the type converter for the member attributes enum.  We search the context
            ///     for a code dom provider that can provide us more information.
            /// </devdoc>
            private TypeConverter GetConverter(ITypeDescriptorContext context)
            {
                TypeConverter modifierConverter = null;

                if (context != null)
                {
                    CodeDomProvider provider = (CodeDomProvider)context.GetService(typeof(CodeDomProvider));
                    if (provider != null)
                    {
                        modifierConverter = provider.GetConverter(typeof(MemberAttributes));
                    }
                }

                if (modifierConverter == null)
                {
                    modifierConverter = TypeDescriptor.GetConverter(typeof(MemberAttributes));
                }

                return(modifierConverter);
            }