public override void WriteUnknownAttribute(XamlUnknownAttributeNode xamlUnknownAttributeNode) { bool localAttrib = false; string localTagFullName = string.Empty; string localAttribName = xamlUnknownAttributeNode.Name; NamespaceMapEntry[] namespaceMaps = null; MemberInfo miKnownEvent = null; if (xamlUnknownAttributeNode.OwnerTypeFullName.Length > 0) { // These are attributes on a local tag ... localTagFullName = xamlUnknownAttributeNode.OwnerTypeFullName; localAttrib = true; } else { // These are attributes on a non-local tag ... namespaceMaps = XamlTypeMapper.GetNamespaceMapEntries(xamlUnknownAttributeNode.XmlNamespace); localAttrib = namespaceMaps != null && namespaceMaps.Length == 1 && namespaceMaps[0].LocalAssembly; } if (localAttrib && !_pass2) { // ... and if there are any periods in the attribute name, then ... int lastIndex = localAttribName.LastIndexOf(MarkupCompiler.DOTCHAR); if (-1 != lastIndex) { // ... these might be attached props or events defined by a locally defined component, // but being set on this non-local tag. TypeAndSerializer typeAndSerializer = null; string ownerTagName = localAttribName.Substring(0, lastIndex); if (namespaceMaps != null) { if (namespaceMaps.Length == 1 && namespaceMaps[0].LocalAssembly) { // local prop on a known tag localTagFullName = namespaceMaps[0].ClrNamespace + MarkupCompiler.DOT + ownerTagName; } } else { typeAndSerializer = XamlTypeMapper.GetTypeOnly(xamlUnknownAttributeNode.XmlNamespace, ownerTagName); if (typeAndSerializer != null) { // known local attribute on a local tag Type ownerTagType = typeAndSerializer.ObjectType; localTagFullName = ownerTagType.FullName; localAttribName = localAttribName.Substring(lastIndex + 1); // See if attached event first miKnownEvent = ownerTagType.GetMethod(MarkupCompiler.ADD + localAttribName + MarkupCompiler.HANDLER, BindingFlags.Public | BindingFlags.Static | BindingFlags.FlattenHierarchy); if (miKnownEvent == null) { // Not an attached event, so try for a clr event. miKnownEvent = ownerTagType.GetEvent(localAttribName, BindingFlags.Instance | BindingFlags.Public | BindingFlags.FlattenHierarchy); } if (miKnownEvent != null) { if (_events == null) { _events = new ArrayList(); } _events.Add(new MarkupCompiler.MarkupEventInfo(xamlUnknownAttributeNode.Value, localAttribName, miKnownEvent, xamlUnknownAttributeNode.LineNumber)); WriteConnectionId(); } } else { namespaceMaps = XamlTypeMapper.GetNamespaceMapEntries(xamlUnknownAttributeNode.XmlNamespace); if (namespaceMaps != null && namespaceMaps.Length == 1 && namespaceMaps[0].LocalAssembly) { // local prop on local tag localTagFullName = namespaceMaps[0].ClrNamespace + MarkupCompiler.DOT + ownerTagName; } else { // unknown prop on local tag -- Error! localTagFullName = string.Empty; } } } if (typeAndSerializer == null) { localAttribName = localAttribName.Substring(lastIndex + 1); } } // else if it is an unknown non-attached prop on a non-local tag -- instant error! } if (localTagFullName.Length > 0 && !_pass2) { if (xamlUnknownAttributeNode.AttributeUsage == BamlAttributeUsage.RuntimeName) { string attributeValue = xamlUnknownAttributeNode.Value; Debug.Assert(_name == null && _nameField == null, "Name has already been set"); _nameField = _compiler.AddNameField(attributeValue, xamlUnknownAttributeNode.LineNumber, xamlUnknownAttributeNode.LinePosition); _name = attributeValue; if (_nameField != null) { WriteConnectionId(); } } else if (localAttribName.Equals(STARTUPURI) && _compiler.IsCompilingEntryPointClass) { // if Application.StartuoUri property then don't bamlize, but gen code since // this is better for perf as Application is not a DO. PropertyInfo pi = KnownTypes.Types[(int)KnownElements.Application].GetProperty(localAttribName); _compiler.AddApplicationProperty(pi, xamlUnknownAttributeNode.Value, xamlUnknownAttributeNode.LineNumber); return; } else if (miKnownEvent == null) { // This may or may not be a local event, but there is no way to know in Pass1. // So we prepare for the worst case sceanrio and assume it may be one so that // the Xaml compiler can generate the CreateDelegate code. _compiler.HasLocalEvent = true; } } else { base.WriteUnknownAttribute(xamlUnknownAttributeNode); } _compiler.IsBamlNeeded = true; }
// Token: 0x060007C1 RID: 1985 RVA: 0x000188E8 File Offset: 0x00016AE8 private Type GetTypeFromName(string name, object context) { ParserContext parserContext = context as ParserContext; if (parserContext == null) { if (context is IServiceProvider) { IXamlTypeResolver xamlTypeResolver = (context as IServiceProvider).GetService(typeof(IXamlTypeResolver)) as IXamlTypeResolver; if (xamlTypeResolver != null) { return(xamlTypeResolver.Resolve(name)); } } IValueSerializerContext valueSerializerContext = context as IValueSerializerContext; if (valueSerializerContext != null) { ValueSerializer serializerFor = ValueSerializer.GetSerializerFor(typeof(Type), valueSerializerContext); if (serializerFor != null) { return(serializerFor.ConvertFromString(name, valueSerializerContext) as Type); } } DependencyObject dependencyObject = context as DependencyObject; if (dependencyObject == null) { if (FrameworkCompatibilityPreferences.TargetsDesktop_V4_0) { return(null); } dependencyObject = new DependencyObject(); } WpfSharedBamlSchemaContext bamlSharedSchemaContext = XamlReader.BamlSharedSchemaContext; return(bamlSharedSchemaContext.ResolvePrefixedNameWithAdditionalWpfSemantics(name, dependencyObject)); } int num = name.IndexOf(':'); string text; if (num == -1) { text = string.Empty; } else { text = name.Substring(0, num).TrimEnd(new char[0]); name = name.Substring(num + 1).TrimStart(new char[0]); } string text2 = parserContext.XmlnsDictionary[text]; if (text2 == null) { throw new ArgumentException(SR.Get("ParserPrefixNSProperty", new object[] { text, name })); } TypeAndSerializer typeOnly = parserContext.XamlTypeMapper.GetTypeOnly(text2, name); if (typeOnly == null) { return(null); } return(typeOnly.ObjectType); }
// Return the type named by the given name Type GetTypeFromName(string name, object context) { // use the parser context, if available. This allows early resolution. // bchapman 5/8/2009 - I believe with System.Xaml there is never an old parserContext here. // But cannot be sure. ParserContext parserContext = context as ParserContext; if (parserContext != null) { // Find the namespace prefix string nsPrefix; int nsIndex = name.IndexOf(':'); if (nsIndex == -1) { nsPrefix = string.Empty; } else { // Found a namespace prefix separator, so create replacement _pathString. // String processing - split "foons" from "BarClass.BazProp" nsPrefix = name.Substring(0, nsIndex).TrimEnd(); name = name.Substring(nsIndex + 1).TrimStart(); } // Find the namespace URI, even if its the default one string namespaceURI = parserContext.XmlnsDictionary[nsPrefix]; if (namespaceURI == null) { throw new ArgumentException(SR.Get(SRID.ParserPrefixNSProperty, nsPrefix, name)); } TypeAndSerializer typeAndSerializer = parserContext.XamlTypeMapper.GetTypeOnly(namespaceURI, name); return((typeAndSerializer != null) ? typeAndSerializer.ObjectType : null); } else { if (context is IServiceProvider) { IXamlTypeResolver xtr = (context as IServiceProvider).GetService(typeof(IXamlTypeResolver)) as IXamlTypeResolver; if (xtr != null) { return(xtr.Resolve(name)); } } IValueSerializerContext serializerContext = context as IValueSerializerContext; if (serializerContext != null) { ValueSerializer typeSerializer = ValueSerializer.GetSerializerFor(typeof(Type), serializerContext); if (typeSerializer != null) { return(typeSerializer.ConvertFromString(name, serializerContext) as Type); } } } // if there's no parser or serializer context, use the tree context DependencyObject hostElement = context as DependencyObject; if (hostElement == null) { if (FrameworkCompatibilityPreferences.TargetsDesktop_V4_0) { // WPF "OneTime" Data binding can work inconsistently when running // a .NET 4 application on .NET 4.5 compared to running it on .NET 4 // app targets 4.0, so return null, for compat return(null); } else { hostElement = new DependencyObject(); // at least pick up the default namespaces } } var wpfSharedSchemaContext = XamlReader.BamlSharedSchemaContext; Type type = wpfSharedSchemaContext.ResolvePrefixedNameWithAdditionalWpfSemantics(name, hostElement); return(type); }