internal static object GetResource(short id)
        {
            SystemResourceKeyID keyId = (SystemResourceKeyID)id;
            if (_srk == null)
            {
                _srk = new SystemResourceKey(keyId);
            }
            else
            {
                _srk._id = keyId;
            }

            return _srk.Resource;
        }
        /// <summary>
        ///  Return an object that should be set on the targetObject's targetProperty
        ///  for this markup extension.  For a StaticExtension this is a static field
        ///  or property value.
        /// </summary>
        /// <param name="serviceProvider">Object that can provide services for the markup extension.</param>
        /// <returns>
        ///  The object to set on this property.
        /// </returns>
        public override object ProvideValue(IServiceProvider serviceProvider)
        {
            if (Member == null)
            {
                throw new InvalidOperationException(SR.Get(SRID.MarkupExtensionStaticMember));
            }

            object value;

            if (MemberType != null)
            {
                value = SystemResourceKey.GetSystemResourceKey(MemberType.Name + "." + Member);
                if (value != null)
                {
                    return(value);
                }
            }
            else
            {
                value = SystemResourceKey.GetSystemResourceKey(Member);
                if (value != null)
                {
                    return(value);
                }

                // Validate the _member

                int dotIndex = Member.IndexOf('.');
                if (dotIndex < 0)
                {
                    throw new ArgumentException(SR.Get(SRID.MarkupExtensionBadStatic, Member));
                }

                // Pull out the type substring (this will include any XML prefix, e.g. "av:Button")

                string typeString = Member.Substring(0, dotIndex);
                if (typeString == string.Empty)
                {
                    throw new ArgumentException(SR.Get(SRID.MarkupExtensionBadStatic, Member));
                }

                // Get the IXamlTypeResolver from the service provider

                if (serviceProvider == null)
                {
                    throw new ArgumentNullException("serviceProvider");
                }

                IXamlTypeResolver xamlTypeResolver = serviceProvider.GetService(typeof(IXamlTypeResolver)) as IXamlTypeResolver;
                if (xamlTypeResolver == null)
                {
                    throw new ArgumentException(SR.Get(SRID.MarkupExtensionNoContext, GetType().Name, "IXamlTypeResolver"));
                }

                // Use the type resolver to get a Type instance

                MemberType = xamlTypeResolver.Resolve(typeString);

                // Get the member name substring

                Member = Member.Substring(dotIndex + 1, Member.Length - dotIndex - 1);
            }

            value = CommandConverter.GetKnownControlCommand(MemberType, Member);
            if (value != null)
            {
                return(value);
            }

            return(base.ProvideValue(serviceProvider));
        }
Exemple #3
0
        // Token: 0x06006C01 RID: 27649 RVA: 0x001F15A4 File Offset: 0x001EF7A4
        public override object ProvideValue(IServiceProvider serviceProvider)
        {
            if (base.Member == null)
            {
                throw new InvalidOperationException(SR.Get("MarkupExtensionStaticMember"));
            }
            object obj;

            if (base.MemberType != null)
            {
                obj = SystemResourceKey.GetSystemResourceKey(base.MemberType.Name + "." + base.Member);
                if (obj != null)
                {
                    return(obj);
                }
            }
            else
            {
                obj = SystemResourceKey.GetSystemResourceKey(base.Member);
                if (obj != null)
                {
                    return(obj);
                }
                int num = base.Member.IndexOf('.');
                if (num < 0)
                {
                    throw new ArgumentException(SR.Get("MarkupExtensionBadStatic", new object[]
                    {
                        base.Member
                    }));
                }
                string text = base.Member.Substring(0, num);
                if (text == string.Empty)
                {
                    throw new ArgumentException(SR.Get("MarkupExtensionBadStatic", new object[]
                    {
                        base.Member
                    }));
                }
                if (serviceProvider == null)
                {
                    throw new ArgumentNullException("serviceProvider");
                }
                IXamlTypeResolver xamlTypeResolver = serviceProvider.GetService(typeof(IXamlTypeResolver)) as IXamlTypeResolver;
                if (xamlTypeResolver == null)
                {
                    throw new ArgumentException(SR.Get("MarkupExtensionNoContext", new object[]
                    {
                        base.GetType().Name,
                        "IXamlTypeResolver"
                    }));
                }
                base.MemberType = xamlTypeResolver.Resolve(text);
                base.Member     = base.Member.Substring(num + 1, base.Member.Length - num - 1);
            }
            obj = CommandConverter.GetKnownControlCommand(base.MemberType, base.Member);
            if (obj != null)
            {
                return(obj);
            }
            return(base.ProvideValue(serviceProvider));
        }