public override object ConvertFrom(ITypeDescriptorContext typeDescriptorContext, CultureInfo cultureInfo, object value) { string s = value as string; if (null == s) { throw new ArgumentException("XAML can only convert from Strings"); } AmbientTC atc = new AmbientTC(); IXamlSchemaContextProvider xscProvider = (IXamlSchemaContextProvider)typeDescriptorContext.GetService(typeof(IXamlSchemaContextProvider)); IAmbientProvider iAmbient = (IAmbientProvider)typeDescriptorContext.GetService(typeof(IAmbientProvider)); XamlType ambientSP = xscProvider.SchemaContext.GetXamlType(typeof(FooAmbient)); XamlMember textProp = ambientSP.GetMember("AmbientTC"); AmbientPropertyValue ambientPropVal = iAmbient.GetFirstAmbientValue(null, textProp); if (ambientPropVal == null) { atc.Text = s; } else { atc.Text = s + "-" + (ambientPropVal.Value as string); } return(atc); }
public override object ProvideValue(IServiceProvider serviceProvider) { IXamlSchemaContextProvider service = serviceProvider.GetService(typeof(IXamlSchemaContextProvider)) as IXamlSchemaContextProvider; IAmbientProvider provider = serviceProvider.GetService(typeof(IAmbientProvider)) as IAmbientProvider; Debug.Assert(provider != null, "The provider should not be null!"); XamlSchemaContext schemaContext = service.SchemaContext; XamlType[] types = new XamlType [] { schemaContext.GetXamlType(typeof(ResourcesDict)) }; // ResourceDict is marked as Ambient, so the instance current being deserialized should be in this list. List <AmbientPropertyValue> list = provider.GetAllAmbientValues(null, false, types) as List <AmbientPropertyValue>; if (list.Count != 1) { throw new Exception("expected ambient property count == 1 but " + list.Count); } AmbientPropertyValue value = list [0]; ResourcesDict dict = value.Value as ResourcesDict; // For this example, we know that dict should not be null and that it is the only value in list. object result = dict [this.Key]; return(result); }
public override object ConvertFrom(ITypeDescriptorContext typeDescriptorContext, CultureInfo cultureInfo, object value) { String s = value as string; if (null == s) { throw new ArgumentException("XAML can only convert from Strings"); } ColorElement2 e = new ColorElement2(); IXamlSchemaContextProvider schemaContextProvider = (IXamlSchemaContextProvider)typeDescriptorContext.GetService(typeof(IXamlSchemaContextProvider)); IAmbientProvider iAmbient = (IAmbientProvider)typeDescriptorContext.GetService(typeof(IAmbientProvider)); XamlType ambientLabel = schemaContextProvider.SchemaContext.GetXamlType(typeof(DerivedFromHasAmbientLabel)); XamlMember label = ambientLabel.GetMember("Num"); AmbientPropertyValue apVal = iAmbient.GetFirstAmbientValue(null, label); if (apVal == null) { e.ColorName = s; } else { e.ColorName = s + "-" + apVal.Value.ToString(); } return(e); }
public override object ConvertFrom(ITypeDescriptorContext typeDescriptorContext, CultureInfo cultureInfo, object value) { String s = value as string; if (String.IsNullOrEmpty(s)) { throw new ArgumentException("XAML can only convert from Strings"); } int dashIdx = s.IndexOf('-'); string color = s; string colorType = String.Empty; if (dashIdx > 1) { color = s.Substring(0, dashIdx); colorType = s.Substring(dashIdx + 1); } ColorElement e = null; if (colorType == "Duel") { e = new ColorElementDuel(); e.ColorName = color; return(e); } else { e = new ColorElement(); } IXamlSchemaContextProvider schemaContextProvider = (IXamlSchemaContextProvider)typeDescriptorContext.GetService(typeof(IXamlSchemaContextProvider)); IAmbientProvider iAmbient = (IAmbientProvider)typeDescriptorContext.GetService(typeof(IAmbientProvider)); XamlType ambientLabel = schemaContextProvider.SchemaContext.GetXamlType(typeof(HasAmbientLabel)); XamlMember label = ambientLabel.GetMember("Label"); AmbientPropertyValue apVal = iAmbient.GetFirstAmbientValue(null, label); if (apVal == null) { e.ColorName = color; } else { e.ColorName = color + "-" + apVal.Value.ToString(); } return(e); }
// Setters and triggers may have a sourceName which we need to resolve // This only works in templates and it works by looking up the mapping between // name and type in the template. We use ambient lookup to find the Template property // and then query it for the type. private static Type GetTypeFromName(XamlSchemaContext schemaContext, IAmbientProvider ambientProvider, string target) { XamlType frameworkTemplateXType = schemaContext.GetXamlType(typeof(FrameworkTemplate)); XamlMember templateProperty = frameworkTemplateXType.GetMember("Template"); AmbientPropertyValue ambientValue = ambientProvider.GetFirstAmbientValue(new XamlType[] { frameworkTemplateXType }, templateProperty); TemplateContent templateHolder = ambientValue.Value as System.Windows.TemplateContent; if (templateHolder != null) { return(templateHolder.GetTypeForName(target).UnderlyingType); } return(null); }
// Token: 0x0600210D RID: 8461 RVA: 0x00098390 File Offset: 0x00096590 private static Type GetTypeFromName(XamlSchemaContext schemaContext, IAmbientProvider ambientProvider, string target) { XamlType xamlType = schemaContext.GetXamlType(typeof(FrameworkTemplate)); XamlMember member = xamlType.GetMember("Template"); AmbientPropertyValue firstAmbientValue = ambientProvider.GetFirstAmbientValue(new XamlType[] { xamlType }, new XamlMember[] { member }); TemplateContent templateContent = firstAmbientValue.Value as TemplateContent; if (templateContent != null) { return(templateContent.GetTypeForName(target).UnderlyingType); } return(null); }
private List <AmbientPropertyValue> FindAmbientValues(IEnumerable <XamlType> ceilingTypesEnumerable, bool searchLiveStackOnly, IEnumerable <XamlType> types, XamlMember[] properties, bool stopAfterFirst) { ArrayHelper.ForAll <XamlMember>(properties, CheckAmbient); List <XamlType> ceilingTypes = ArrayHelper.ToList <XamlType>(ceilingTypesEnumerable); List <AmbientPropertyValue> retList = new List <AmbientPropertyValue>(); // Start the search for ambient properties and types starting with the parent frame. ObjectWriterFrame frame = _stack.PreviousFrame; ObjectWriterFrame lowerFrame = _stack.CurrentFrame; while (frame.Depth >= 1) { if (searchLiveStackOnly && frame.Depth <= SavedDepth) { break; } object inst = frame.Instance; if (types != null) { foreach (XamlType type in types) { if (frame.XamlType != null && frame.XamlType.CanAssignTo(type)) { if (inst != null) { AmbientPropertyValue apValue = new AmbientPropertyValue(null, inst); retList.Add(apValue); } } } } if (properties != null) { foreach (XamlMember prop in properties) { bool returnAmbientValue = false; object value = null; if (frame.XamlType != null && frame.XamlType.CanAssignTo(prop.DeclaringType)) { if (inst != null) { // If we are searching from inside the target Ambient property, // (like StaticResource inside a ResourceDictionary) // and the object is bottom-up, then it won't be assigned to // the object but will only exist on the parse stack. // If it is top-down it will be attached to the instance already // and the normal path will serve. if (prop == frame.Member && lowerFrame.Instance != null && lowerFrame.XamlType != null && !lowerFrame.XamlType.IsUsableDuringInitialization) { // One last thing to check: If the object we are inside is a ME // then we are inside a call to ProvideValue and we don't want to // return a reference to ourselves to ourselves. if (!(lowerFrame.Instance is XAML3.MarkupExtension)) { returnAmbientValue = true; value = lowerFrame.Instance; } } else { // The Ambient Property is either Fully build or not set. // FIRST: Ask the object (via IQueryAmbient interface) if it has a value for this property. // This is usefull to prevent needless creation of empty lazy properties. var ambientCtrl = inst as XAML3.IQueryAmbient; // If there is no ambientControl or if ambientControl says YES, then get the property value. if (ambientCtrl == null || ambientCtrl.IsAmbientPropertyAvailable(prop.Name)) { returnAmbientValue = true; value = _runtime.GetValue(inst, prop); } } } if (returnAmbientValue) { AmbientPropertyValue apValue = new AmbientPropertyValue(prop, value); retList.Add(apValue); } } } } if (stopAfterFirst && retList.Count > 0) { break; } if (ceilingTypes != null) { if (ceilingTypes.Contains(frame.XamlType)) { break; } } lowerFrame = frame; frame = (ObjectWriterFrame)frame.Previous; Debug.Assert(frame != null); } return(retList); }
// Token: 0x0600210C RID: 8460 RVA: 0x00097FBC File Offset: 0x000961BC internal static DependencyProperty ResolveProperty(IServiceProvider serviceProvider, string targetName, object source) { Type type = null; string text = null; DependencyProperty dependencyProperty = source as DependencyProperty; if (dependencyProperty != null) { return(dependencyProperty); } byte[] array; if ((array = (source as byte[])) != null) { Baml2006SchemaContext baml2006SchemaContext = (serviceProvider.GetService(typeof(IXamlSchemaContextProvider)) as IXamlSchemaContextProvider).SchemaContext as Baml2006SchemaContext; if (array.Length == 2) { short propertyId = (short)((int)array[0] | (int)array[1] << 8); return(baml2006SchemaContext.GetDependencyProperty(propertyId)); } using (BinaryReader binaryReader = new BinaryReader(new MemoryStream(array))) { type = baml2006SchemaContext.GetXamlType(binaryReader.ReadInt16()).UnderlyingType; text = binaryReader.ReadString(); goto IL_142; } } string text2; if ((text2 = (source as string)) == null) { throw new NotSupportedException(SR.Get("ParserCannotConvertPropertyValue", new object[] { "Property", typeof(DependencyProperty).FullName })); } text2 = text2.Trim(); if (text2.Contains(".")) { int num = text2.LastIndexOf('.'); string qualifiedTypeName = text2.Substring(0, num); text = text2.Substring(num + 1); IXamlTypeResolver xamlTypeResolver = serviceProvider.GetService(typeof(IXamlTypeResolver)) as IXamlTypeResolver; type = xamlTypeResolver.Resolve(qualifiedTypeName); } else { int num2 = text2.LastIndexOf(':'); text = text2.Substring(num2 + 1); } IL_142: if (type == null && targetName != null) { IAmbientProvider ambientProvider = serviceProvider.GetService(typeof(IAmbientProvider)) as IAmbientProvider; XamlSchemaContext schemaContext = (serviceProvider.GetService(typeof(IXamlSchemaContextProvider)) as IXamlSchemaContextProvider).SchemaContext; type = DependencyPropertyConverter.GetTypeFromName(schemaContext, ambientProvider, targetName); } if (type == null) { IXamlSchemaContextProvider xamlSchemaContextProvider = serviceProvider.GetService(typeof(IXamlSchemaContextProvider)) as IXamlSchemaContextProvider; if (xamlSchemaContextProvider == null) { throw new NotSupportedException(SR.Get("ParserCannotConvertPropertyValue", new object[] { "Property", typeof(DependencyProperty).FullName })); } XamlSchemaContext schemaContext2 = xamlSchemaContextProvider.SchemaContext; XamlType xamlType = schemaContext2.GetXamlType(typeof(Style)); XamlType xamlType2 = schemaContext2.GetXamlType(typeof(FrameworkTemplate)); XamlType xamlType3 = schemaContext2.GetXamlType(typeof(DataTemplate)); XamlType xamlType4 = schemaContext2.GetXamlType(typeof(ControlTemplate)); List <XamlType> list = new List <XamlType>(); list.Add(xamlType); list.Add(xamlType2); list.Add(xamlType3); list.Add(xamlType4); XamlMember member = xamlType.GetMember("TargetType"); XamlMember member2 = xamlType2.GetMember("Template"); XamlMember member3 = xamlType4.GetMember("TargetType"); IAmbientProvider ambientProvider2 = serviceProvider.GetService(typeof(IAmbientProvider)) as IAmbientProvider; if (ambientProvider2 == null) { throw new NotSupportedException(SR.Get("ParserCannotConvertPropertyValue", new object[] { "Property", typeof(DependencyProperty).FullName })); } AmbientPropertyValue firstAmbientValue = ambientProvider2.GetFirstAmbientValue(list, new XamlMember[] { member, member2, member3 }); if (firstAmbientValue != null) { if (firstAmbientValue.Value is Type) { type = (Type)firstAmbientValue.Value; } else { if (!(firstAmbientValue.Value is TemplateContent)) { throw new NotSupportedException(SR.Get("ParserCannotConvertPropertyValue", new object[] { "Property", typeof(DependencyProperty).FullName })); } TemplateContent templateContent = firstAmbientValue.Value as TemplateContent; type = templateContent.OwnerTemplate.TargetTypeInternal; } } } if (type != null && text != null) { return(DependencyProperty.FromName(text, type)); } throw new NotSupportedException(SR.Get("ParserCannotConvertPropertyValue", new object[] { "Property", typeof(DependencyProperty).FullName })); }
// Token: 0x06000865 RID: 2149 RVA: 0x0001B4E8 File Offset: 0x000196E8 private ResourceDictionary FindTheResourceDictionary(IServiceProvider serviceProvider, bool isDeferredContentSearch) { IXamlSchemaContextProvider xamlSchemaContextProvider = serviceProvider.GetService(typeof(IXamlSchemaContextProvider)) as IXamlSchemaContextProvider; if (xamlSchemaContextProvider == null) { throw new InvalidOperationException(SR.Get("MarkupExtensionNoContext", new object[] { base.GetType().Name, "IXamlSchemaContextProvider" })); } IAmbientProvider ambientProvider = serviceProvider.GetService(typeof(IAmbientProvider)) as IAmbientProvider; if (ambientProvider == null) { throw new InvalidOperationException(SR.Get("MarkupExtensionNoContext", new object[] { base.GetType().Name, "IAmbientProvider" })); } XamlSchemaContext schemaContext = xamlSchemaContextProvider.SchemaContext; XamlType xamlType = schemaContext.GetXamlType(typeof(FrameworkElement)); XamlType xamlType2 = schemaContext.GetXamlType(typeof(Style)); XamlType xamlType3 = schemaContext.GetXamlType(typeof(FrameworkTemplate)); XamlType xamlType4 = schemaContext.GetXamlType(typeof(Application)); XamlType xamlType5 = schemaContext.GetXamlType(typeof(FrameworkContentElement)); XamlMember member = xamlType5.GetMember("Resources"); XamlMember member2 = xamlType.GetMember("Resources"); XamlMember member3 = xamlType2.GetMember("Resources"); XamlMember member4 = xamlType2.GetMember("BasedOn"); XamlMember member5 = xamlType3.GetMember("Resources"); XamlMember member6 = xamlType4.GetMember("Resources"); XamlType[] types = new XamlType[] { schemaContext.GetXamlType(typeof(ResourceDictionary)) }; IEnumerable <AmbientPropertyValue> allAmbientValues = ambientProvider.GetAllAmbientValues(null, isDeferredContentSearch, types, new XamlMember[] { member, member2, member3, member4, member5, member6 }); List <AmbientPropertyValue> list = allAmbientValues as List <AmbientPropertyValue>; for (int i = 0; i < list.Count; i++) { AmbientPropertyValue ambientPropertyValue = list[i]; if (ambientPropertyValue.Value is ResourceDictionary) { ResourceDictionary resourceDictionary = (ResourceDictionary)ambientPropertyValue.Value; if (resourceDictionary.Contains(this.ResourceKey)) { return(resourceDictionary); } } if (ambientPropertyValue.Value is Style) { Style style = (Style)ambientPropertyValue.Value; ResourceDictionary resourceDictionary2 = style.FindResourceDictionary(this.ResourceKey); if (resourceDictionary2 != null) { return(resourceDictionary2); } } } return(null); }
internal static DependencyProperty ResolveProperty(IServiceProvider serviceProvider, string targetName, object source) { Type type = null; string property = null; DependencyProperty dProperty = source as DependencyProperty; byte[] bytes; String value; if (dProperty != null) { return(dProperty); } // If it's a byte[] we got it from BAML. Let's resolve it using the schema context else if ((bytes = source as byte[]) != null) { Baml2006SchemaContext schemaContext = (serviceProvider.GetService(typeof(IXamlSchemaContextProvider)) as IXamlSchemaContextProvider).SchemaContext as Baml2006SchemaContext; // Array with length of 2 means its an ID for a // DependencyProperty in the Baml2006SchemaContext if (bytes.Length == 2) { short propId = (short)(bytes[0] | (bytes[1] << 8)); return(schemaContext.GetDependencyProperty(propId)); } else { // Otherwise it's a string with a TypeId encoded in front using (BinaryReader reader = new BinaryReader(new MemoryStream(bytes))) { type = schemaContext.GetXamlType(reader.ReadInt16()).UnderlyingType; property = reader.ReadString(); } } } else if ((value = source as string) != null) { value = value.Trim(); // If it contains a . it means that it is a full name with type and property. if (value.Contains(".")) { // Prefixes could have .'s so we take the last one and do a type resolve against that int lastIndex = value.LastIndexOf('.'); string typeName = value.Substring(0, lastIndex); property = value.Substring(lastIndex + 1); IXamlTypeResolver resolver = serviceProvider.GetService(typeof(IXamlTypeResolver)) as IXamlTypeResolver; type = resolver.Resolve(typeName); } else { // Only have the property name // Strip prefixes if there are any, v3 essentially discards the prefix in this case int lastIndex = value.LastIndexOf(':'); property = value.Substring(lastIndex + 1); } } else { throw new NotSupportedException(SR.Get(SRID.ParserCannotConvertPropertyValue, "Property", typeof(DependencyProperty).FullName)); } // We got additional info from either Trigger.SourceName or Setter.TargetName if (type == null && targetName != null) { IAmbientProvider ambientProvider = serviceProvider.GetService(typeof(IAmbientProvider)) as System.Xaml.IAmbientProvider; XamlSchemaContext schemaContext = (serviceProvider.GetService(typeof(IXamlSchemaContextProvider)) as IXamlSchemaContextProvider).SchemaContext; type = GetTypeFromName(schemaContext, ambientProvider, targetName); } // Still don't have a Type so we need to loop up the chain and grab either Style.TargetType, // DataTemplate.DataType, or ControlTemplate.TargetType if (type == null) { IXamlSchemaContextProvider ixscp = (serviceProvider.GetService(typeof(IXamlSchemaContextProvider)) as IXamlSchemaContextProvider); if (ixscp == null) { throw new NotSupportedException(SR.Get(SRID.ParserCannotConvertPropertyValue, "Property", typeof(DependencyProperty).FullName)); } XamlSchemaContext schemaContext = ixscp.SchemaContext; XamlType styleXType = schemaContext.GetXamlType(typeof(Style)); XamlType frameworkTemplateXType = schemaContext.GetXamlType(typeof(FrameworkTemplate)); XamlType dataTemplateXType = schemaContext.GetXamlType(typeof(DataTemplate)); XamlType controlTemplateXType = schemaContext.GetXamlType(typeof(ControlTemplate)); List <XamlType> ceilingTypes = new List <XamlType>(); ceilingTypes.Add(styleXType); ceilingTypes.Add(frameworkTemplateXType); ceilingTypes.Add(dataTemplateXType); ceilingTypes.Add(controlTemplateXType); // We don't look for DataTemplate's DataType since we want to use the TargetTypeInternal instead XamlMember styleTargetType = styleXType.GetMember("TargetType"); XamlMember templateProperty = frameworkTemplateXType.GetMember("Template"); XamlMember controlTemplateTargetType = controlTemplateXType.GetMember("TargetType"); IAmbientProvider ambientProvider = serviceProvider.GetService(typeof(IAmbientProvider)) as System.Xaml.IAmbientProvider; if (ambientProvider == null) { throw new NotSupportedException(SR.Get(SRID.ParserCannotConvertPropertyValue, "Property", typeof(DependencyProperty).FullName)); } AmbientPropertyValue firstAmbientValue = ambientProvider.GetFirstAmbientValue(ceilingTypes, styleTargetType, templateProperty, controlTemplateTargetType); if (firstAmbientValue != null) { if (firstAmbientValue.Value is Type) { type = (Type)firstAmbientValue.Value; } else if (firstAmbientValue.Value is TemplateContent) { TemplateContent tempContent = firstAmbientValue.Value as TemplateContent; type = tempContent.OwnerTemplate.TargetTypeInternal; } else { throw new NotSupportedException(SR.Get(SRID.ParserCannotConvertPropertyValue, "Property", typeof(DependencyProperty).FullName)); } } } if (type != null && property != null) { return(DependencyProperty.FromName(property, type)); } throw new NotSupportedException(SR.Get(SRID.ParserCannotConvertPropertyValue, "Property", typeof(DependencyProperty).FullName)); }
private ResourceDictionary FindTheResourceDictionary(IServiceProvider serviceProvider, bool isDeferredContentSearch) { var schemaContextProvider = serviceProvider.GetService(typeof(IXamlSchemaContextProvider)) as IXamlSchemaContextProvider; if (schemaContextProvider == null) { throw new InvalidOperationException(SR.Get(SRID.MarkupExtensionNoContext, GetType().Name, "IXamlSchemaContextProvider")); } var ambientProvider = serviceProvider.GetService(typeof(IAmbientProvider)) as IAmbientProvider; if (ambientProvider == null) { throw new InvalidOperationException(SR.Get(SRID.MarkupExtensionNoContext, GetType().Name, "IAmbientProvider")); } XamlSchemaContext schemaContext = schemaContextProvider.SchemaContext; // This seems like a lot of work to do on every Provide Value // but that types and properties are cached in the schema. // XamlType feXType = schemaContext.GetXamlType(typeof(FrameworkElement)); XamlType styleXType = schemaContext.GetXamlType(typeof(Style)); XamlType templateXType = schemaContext.GetXamlType(typeof(FrameworkTemplate)); XamlType appXType = schemaContext.GetXamlType(typeof(Application)); XamlType fceXType = schemaContext.GetXamlType(typeof(FrameworkContentElement)); XamlMember fceResourcesProperty = fceXType.GetMember("Resources"); XamlMember feResourcesProperty = feXType.GetMember("Resources"); XamlMember styleResourcesProperty = styleXType.GetMember("Resources"); XamlMember styleBasedOnProperty = styleXType.GetMember("BasedOn"); XamlMember templateResourcesProperty = templateXType.GetMember("Resources"); XamlMember appResourcesProperty = appXType.GetMember("Resources"); XamlType[] types = new XamlType[1] { schemaContext.GetXamlType(typeof(ResourceDictionary)) }; IEnumerable <AmbientPropertyValue> ambientValues = null; ambientValues = ambientProvider.GetAllAmbientValues(null, // ceilingTypes isDeferredContentSearch, types, fceResourcesProperty, feResourcesProperty, styleResourcesProperty, styleBasedOnProperty, templateResourcesProperty, appResourcesProperty); List <AmbientPropertyValue> ambientList; ambientList = ambientValues as List <AmbientPropertyValue>; Debug.Assert(ambientList != null, "IAmbientProvider.GetAllAmbientValues no longer returns List<>, please copy the list"); for (int i = 0; i < ambientList.Count; i++) { AmbientPropertyValue ambientValue = ambientList[i]; if (ambientValue.Value is ResourceDictionary) { var resourceDictionary = (ResourceDictionary)ambientValue.Value; if (resourceDictionary.Contains(ResourceKey)) { return(resourceDictionary); } } if (ambientValue.Value is Style) { var style = (Style)ambientValue.Value; var resourceDictionary = style.FindResourceDictionary(ResourceKey); if (resourceDictionary != null) { return(resourceDictionary); } } } return(null); }
private List <AmbientPropertyValue> FindAmbientValues(IEnumerable <XamlType> ceilingTypesEnumerable, bool searchLiveStackOnly, IEnumerable <XamlType> types, XamlMember[] properties, bool stopAfterFirst) { ArrayHelper.ForAll <XamlMember>(properties, new Action <XamlMember>(ObjectWriterContext.CheckAmbient)); List <XamlType> list = ArrayHelper.ToList <XamlType>(ceilingTypesEnumerable); List <AmbientPropertyValue> list2 = new List <AmbientPropertyValue>(); ObjectWriterFrame previousFrame = this._stack.PreviousFrame; ObjectWriterFrame currentFrame = this._stack.CurrentFrame; while (previousFrame.Depth >= 1) { if (searchLiveStackOnly && (previousFrame.Depth <= this.SavedDepth)) { return(list2); } object instance = previousFrame.Instance; if (types != null) { foreach (XamlType type in types) { if (((previousFrame.XamlType != null) && previousFrame.XamlType.CanAssignTo(type)) && (instance != null)) { AmbientPropertyValue item = new AmbientPropertyValue(null, instance); list2.Add(item); } } } if (properties != null) { foreach (XamlMember member in properties) { bool flag = false; object obj3 = null; if ((previousFrame.XamlType != null) && previousFrame.XamlType.CanAssignTo(member.DeclaringType)) { if (instance != null) { if (((member == previousFrame.Member) && (currentFrame.Instance != null)) && ((currentFrame.XamlType != null) && !currentFrame.XamlType.IsUsableDuringInitialization)) { if (!typeof(MarkupExtension).IsAssignableFrom(currentFrame.Instance.GetType())) { flag = true; obj3 = currentFrame.Instance; } } else { IQueryAmbient ambient = instance as IQueryAmbient; if ((ambient == null) || ambient.IsAmbientPropertyAvailable(member.Name)) { flag = true; obj3 = this._runtime.GetValue(instance, member); } } } if (flag) { AmbientPropertyValue value3 = new AmbientPropertyValue(member, obj3); list2.Add(value3); } } } } if (stopAfterFirst && (list2.Count > 0)) { return(list2); } if ((list != null) && list.Contains(previousFrame.XamlType)) { return(list2); } currentFrame = previousFrame; previousFrame = (ObjectWriterFrame)previousFrame.Previous; } return(list2); }
/// <summary> /// Convert a string like "Button.Click" into the corresponding RoutedEvent /// </summary> public override object ConvertFrom(ITypeDescriptorContext typeDescriptorContext, CultureInfo cultureInfo, object source) { string routedEventName = source as string; RoutedEvent routedEvent = null; if (routedEventName != null) { routedEventName = routedEventName.Trim(); IServiceProvider serviceProvider = typeDescriptorContext as IServiceProvider; if (serviceProvider != null) { IXamlTypeResolver resolver = serviceProvider.GetService(typeof(IXamlTypeResolver)) as IXamlTypeResolver; Type type = null; if (resolver != null) { // Verify that there's at least one period. (A simple // but not foolproof check for "[class].[event]") int lastIndex = routedEventName.IndexOf('.'); if (lastIndex != -1) { string typeName = routedEventName.Substring(0, lastIndex); routedEventName = routedEventName.Substring(lastIndex + 1); type = resolver.Resolve(typeName); } } if (type == null) { IXamlSchemaContextProvider schemaContextProvider = (typeDescriptorContext. GetService(typeof(IXamlSchemaContextProvider)) as IXamlSchemaContextProvider); IAmbientProvider iapp = serviceProvider.GetService(typeof(IAmbientProvider)) as IAmbientProvider; if (schemaContextProvider != null && iapp != null) { XamlSchemaContext schemaContext = schemaContextProvider.SchemaContext; XamlType styleXType = schemaContext.GetXamlType(typeof(Style)); List <XamlType> ceilingTypes = new List <XamlType>(); ceilingTypes.Add(styleXType); XamlMember styleTargetType = styleXType.GetMember("TargetType"); AmbientPropertyValue firstAmbientValue = iapp.GetFirstAmbientValue(ceilingTypes, styleTargetType); if (firstAmbientValue != null) { type = firstAmbientValue.Value as Type; } if (type == null) { type = typeof(FrameworkElement); } } } if (type != null) { Type currentType = type; // Force load the Statics by walking up the hierarchy and running class constructors while (null != currentType) { MS.Internal.WindowsBase.SecurityHelper.RunClassConstructor(currentType); currentType = currentType.BaseType; } routedEvent = EventManager.GetRoutedEventFromName(routedEventName, type); } } } if (routedEvent == null) { // Falling through here means we are unable to perform the conversion. throw GetConvertFromException(source); } return(routedEvent); }
/// <summary>Attempts to convert the specified object to a <see cref="T:System.Windows.RoutedEvent" /> object, using the specified context.</summary> /// <param name="typeDescriptorContext">A format context that provides information about the environment from which this converter is being invoked.</param> /// <param name="cultureInfo">Culture specific information.</param> /// <param name="source">The object to convert.</param> /// <returns>The conversion result.</returns> /// <exception cref="T:System.NotSupportedException"> /// <paramref name="source" /> is not a string or cannot be converted.</exception> // Token: 0x0600223F RID: 8767 RVA: 0x000AA6D4 File Offset: 0x000A88D4 public override object ConvertFrom(ITypeDescriptorContext typeDescriptorContext, CultureInfo cultureInfo, object source) { string text = source as string; RoutedEvent routedEvent = null; if (text != null) { text = text.Trim(); if (typeDescriptorContext != null) { IXamlTypeResolver xamlTypeResolver = typeDescriptorContext.GetService(typeof(IXamlTypeResolver)) as IXamlTypeResolver; Type type = null; if (xamlTypeResolver != null) { int num = text.IndexOf('.'); if (num != -1) { string qualifiedTypeName = text.Substring(0, num); text = text.Substring(num + 1); type = xamlTypeResolver.Resolve(qualifiedTypeName); } } if (type == null) { IXamlSchemaContextProvider xamlSchemaContextProvider = typeDescriptorContext.GetService(typeof(IXamlSchemaContextProvider)) as IXamlSchemaContextProvider; IAmbientProvider ambientProvider = typeDescriptorContext.GetService(typeof(IAmbientProvider)) as IAmbientProvider; if (xamlSchemaContextProvider != null && ambientProvider != null) { XamlSchemaContext schemaContext = xamlSchemaContextProvider.SchemaContext; XamlType xamlType = schemaContext.GetXamlType(typeof(Style)); List <XamlType> list = new List <XamlType>(); list.Add(xamlType); XamlMember member = xamlType.GetMember("TargetType"); AmbientPropertyValue firstAmbientValue = ambientProvider.GetFirstAmbientValue(list, new XamlMember[] { member }); if (firstAmbientValue != null) { type = (firstAmbientValue.Value as Type); } if (type == null) { type = typeof(FrameworkElement); } } } if (type != null) { Type type2 = type; while (null != type2) { SecurityHelper.RunClassConstructor(type2); type2 = type2.BaseType; } routedEvent = EventManager.GetRoutedEventFromName(text, type); } } } if (routedEvent == null) { throw base.GetConvertFromException(source); } return(routedEvent); }