public DocumentPropertyContentReference(IPlatformMetadata platformMetadata, IDocumentNodeReference parent, IProperty property) { this.parent = parent; this.property = property; if (!platformMetadata.GetIsTypeItsOwnNameScope((ITypeId)this.property.PropertyType)) { return; } this.nameScope = new DocumentNodeNameScope(); }
public DocumentCompositeNodeReference(IDocumentNodeReference parent, DocumentCompositeNode node) { if (parent == null) { throw new ArgumentNullException("parent"); } if (node == null) { throw new ArgumentNullException("node"); } this.parent = parent; this.node = node; if (!node.TypeResolver.PlatformMetadata.GetIsTypeItsOwnNameScope((ITypeId)this.node.Type)) { return; } this.nameScope = new DocumentNodeNameScope(); }
private static DocumentNode ParseMarkupExtension(XamlParserContext parserContext, ITextLocation lineInformation, IDocumentNodeReference nodeReference, IXmlNamespaceResolver xmlNamespaceResolver, IType typeId, MarkupExtensionDescription description) { int count = description.PositionalArguments.Count; DocumentCompositeNode node = parserContext.DocumentContext.CreateNode((ITypeId)typeId); IDocumentNodeReference documentNodeReference = (IDocumentNodeReference) new DocumentCompositeNodeReference(nodeReference, node); IConstructor constructor1 = (IConstructor)null; if (typeId.IsResolvable) { IList <IConstructor> constructors = typeId.GetConstructors(); if (constructors.Count > 0) { int num = 0; foreach (IConstructor constructor2 in (IEnumerable <IConstructor>)constructors) { if (constructor2.Parameters.Count == count) { if (num == 0) { constructor1 = constructor2; } ++num; } } if (num == 0) { parserContext.ReportError(XamlParseErrors.IncorrectNumberOfConstructorArguments(lineInformation, (ITypeId)typeId)); } else if (num <= 1) { ; } } else { parserContext.ReportError(XamlParseErrors.NoAccessibleConstructor(lineInformation, (ITypeId)typeId)); } } DocumentNode[] documentNodeArray = constructor1 != null ? new DocumentNode[constructor1.Parameters.Count] : (DocumentNode[])null; IConstructorArgumentProperties argumentProperties = typeId.GetConstructorArgumentProperties(); if (count > 0) { for (int index = 0; index < count; ++index) { string str = description.PositionalArguments[index]; bool flag = constructor1 != null && index < constructor1.Parameters.Count; IType type = parserContext.TypeResolver.ResolveType(parserContext.TypeResolver.PlatformMetadata.KnownTypes.Object); if (flag) { IParameter parameter = constructor1.Parameters[index]; type = parserContext.TypeResolver.ResolveType((ITypeId)parameter.ParameterType); IProperty property = argumentProperties[parameter.Name]; if (property != null && !property.PropertyType.IsAssignableFrom((ITypeId)type)) { flag = false; parserContext.ReportError(XamlParseErrors.ConstructorArgumentDeclaredTypeDoesNotMatchProperty(lineInformation, (IPropertyId)property)); } } TypeConverter typeConverter = type.TypeConverter; DocumentNode propertyValue = MarkupExtensionParser.GetPropertyValue(parserContext, lineInformation, documentNodeReference, xmlNamespaceResolver, typeConverter, type, str, true); if (flag && propertyValue != null) { documentNodeArray[index] = XamlParser.CanAssignTo(parserContext, lineInformation, type, propertyValue) ? propertyValue : (DocumentNode)null; } } } node.SetConstructor(constructor1, (IList <DocumentNode>)documentNodeArray); int num1 = 0; foreach (KeyValuePair <string, string> keyValuePair in (IEnumerable <KeyValuePair <string, string> >)description.NamedArguments) { string key = keyValuePair.Key; MemberType memberTypes = MemberType.LocalProperty | MemberType.AttachedProperty | MemberType.Field; if (parserContext.TypeResolver.IsCapabilitySet(PlatformCapability.IncompleteAttachedPropertiesInMarkupExtensions)) { memberTypes |= MemberType.IncompleteAttachedProperty; } IProperty propertyKey = XamlTypeHelper.GetPropertyKey(parserContext, lineInformation, xmlNamespaceResolver, key, (XmlNamespace)null, typeId, memberTypes, MemberType.LocalProperty, false); if (propertyKey != null) { DocumentNode propertyValue = MarkupExtensionParser.GetPropertyValue(parserContext, lineInformation, documentNodeReference, xmlNamespaceResolver, propertyKey, keyValuePair.Value, true); if (propertyValue != null && XamlParser.SetProperty(parserContext, lineInformation, new DocumentCompositeNodeReference(documentNodeReference, node), (XamlSourceContext)null, (IPropertyId)propertyKey, propertyValue)) { propertyValue.ContainerSourceContext = (INodeSourceContext) new MarkupExtensionParser.MinimalSourceContext(num1++); } } } return((DocumentNode)node); }
public static DocumentNode CreateNodeFromTextValue(XamlParserContext parserContext, ITextLocation lineInformation, IDocumentNodeReference nodeReference, IXmlNamespaceResolver xmlNamespaceResolver, TypeConverter typeConverter, ITypeId valueTypeId, string value) { if (parserContext.PlatformMetadata.KnownTypes.DependencyProperty.IsAssignableFrom(valueTypeId)) { MemberType memberTypes = MemberType.Property | MemberType.Field; if (parserContext.TypeResolver.IsCapabilitySet(PlatformCapability.IncompleteAttachedPropertiesInMarkupExtensions)) { memberTypes |= MemberType.IncompleteAttachedProperty; } MemberType defaultType = value.IndexOf('.') >= 0 ? MemberType.AttachedProperty : MemberType.LocalProperty; IProperty propertyKey = XamlTypeHelper.GetPropertyKey(parserContext, lineInformation, xmlNamespaceResolver, value, (XmlNamespace)null, nodeReference.TargetType, memberTypes, defaultType, false); if (propertyKey == null) { return((DocumentNode)null); } MarkupExtensionParser.VerifyMemberIsDependencyProperty(parserContext, lineInformation, (IMember)propertyKey); return((DocumentNode)parserContext.DocumentContext.CreateNode(valueTypeId, (IDocumentNodeValue) new DocumentNodeMemberValue((IMember)propertyKey))); } if (parserContext.PlatformMetadata.KnownTypes.ICommand.IsAssignableFrom(valueTypeId)) { bool flag = typeConverter != null && !parserContext.PlatformMetadata.KnownTypes.CommandConverter.Equals((object)parserContext.TypeResolver.GetType(typeConverter.GetType())); if (value.IndexOf('.') < 0 || flag) { return((DocumentNode)parserContext.DocumentContext.CreateNode(valueTypeId, (IDocumentNodeValue) new DocumentNodeStringValue(value))); } IType typeId; string memberName; if (MarkupExtensionParser.GetTypeAndMemberName(parserContext, lineInformation, xmlNamespaceResolver, value, (IType)null, out typeId, out memberName)) { MemberAccessTypes allowableMemberAccess = TypeHelper.GetAllowableMemberAccess(parserContext.TypeResolver, typeId); IMember member = (IMember)typeId.GetMember(MemberType.LocalProperty | MemberType.Field, memberName, allowableMemberAccess) ?? XamlTypeHelper.AddMemberIfPossible(parserContext.PlatformMetadata, typeId, MemberType.LocalProperty, memberName); if (member != null) { return((DocumentNode)parserContext.DocumentContext.CreateNode(valueTypeId, (IDocumentNodeValue) new DocumentNodeMemberValue(member))); } parserContext.ReportError(XamlParseErrors.UnrecognizedOrInaccessibleMember(lineInformation, memberName)); } return((DocumentNode)null); } if (parserContext.PlatformMetadata.KnownTypes.RoutedEvent.IsAssignableFrom(valueTypeId)) { IType typeId; string memberName; if (!MarkupExtensionParser.GetTypeAndMemberName(parserContext, lineInformation, xmlNamespaceResolver, value, nodeReference.TargetType, out typeId, out memberName)) { return((DocumentNode)null); } MemberAccessTypes allowableMemberAccess = TypeHelper.GetAllowableMemberAccess(parserContext.TypeResolver, typeId); IMember member = (IMember)typeId.GetMember(MemberType.Event, memberName, allowableMemberAccess); if (member != null) { MarkupExtensionParser.VerifyMemberIsRoutedEvent(parserContext, lineInformation, member); } else { member = XamlTypeHelper.AddMemberIfPossible(parserContext.PlatformMetadata, typeId, MemberType.RoutedEvent, memberName); } if (member != null) { return((DocumentNode)parserContext.DocumentContext.CreateNode(valueTypeId, (IDocumentNodeValue) new DocumentNodeMemberValue(member))); } parserContext.ReportError(XamlParseErrors.UnrecognizedOrInaccessibleMember(lineInformation, memberName)); return((DocumentNode)null); } if (parserContext.PlatformMetadata.KnownTypes.Delegate.IsAssignableFrom(valueTypeId)) { string memberName = value; if (parserContext.RootClassAttributes == null && parserContext.TypeResolver.IsCapabilitySet(PlatformCapability.IsWpf)) { parserContext.ReportError(XamlParseErrors.CannotDetermineMemberTargetType(lineInformation, memberName)); } return((DocumentNode)parserContext.DocumentContext.CreateNode(valueTypeId, (IDocumentNodeValue) new DocumentNodeStringValue(memberName))); } if (parserContext.PlatformMetadata.KnownTypes.PropertyPath.IsAssignableFrom(valueTypeId)) { return(MarkupExtensionParser.ParsePropertyPath(parserContext, lineInformation, xmlNamespaceResolver, value)); } if (parserContext.PlatformMetadata.KnownTypes.Uri.IsAssignableFrom(valueTypeId)) { return((DocumentNode)parserContext.DocumentContext.CreateNode(valueTypeId, (IDocumentNodeValue) new DocumentNodeStringValue(value))); } if (parserContext.PlatformMetadata.KnownTypes.Type.IsAssignableFrom(valueTypeId)) { IType typeId = XamlTypeHelper.GetTypeId(parserContext, lineInformation, xmlNamespaceResolver, value, false); if (typeId != null) { return((DocumentNode)parserContext.DocumentContext.CreateNode(valueTypeId, (IDocumentNodeValue) new DocumentNodeMemberValue((IMember)typeId))); } return((DocumentNode)null); } if (valueTypeId.Equals((object)parserContext.TypeResolver.PlatformMetadata.KnownTypes.Object)) { valueTypeId = (ITypeId)parserContext.TypeResolver.ResolveType(parserContext.TypeResolver.PlatformMetadata.KnownTypes.String); } if (valueTypeId.IsResolvable && valueTypeId != parserContext.TypeResolver.ResolveType(parserContext.TypeResolver.PlatformMetadata.KnownTypes.String) && (typeConverter == null || !typeConverter.CanConvertFrom(typeof(string)))) { parserContext.ReportError(XamlParseErrors.CannotConvertFromString(lineInformation, valueTypeId)); } return((DocumentNode)parserContext.DocumentContext.CreateNode(valueTypeId, (IDocumentNodeValue) new DocumentNodeStringValue(value))); }
public static DocumentNode GetPropertyValue(XamlParserContext parserContext, ITextLocation lineInformation, IDocumentNodeReference nodeReference, IXmlNamespaceResolver xmlNamespaceResolver, TypeConverter typeConverter, IType valueTypeId, string value, bool removeEscapeCharacters) { bool flag = false; if (value.StartsWith("{", StringComparison.Ordinal)) { if (value.StartsWith("{}", StringComparison.Ordinal)) { value = value.Substring(2); } else { flag = true; } } if (removeEscapeCharacters) { value = MarkupExtensionParser.ReplaceEscapedCharacters(value); } if (flag) { return(MarkupExtensionParser.ParseMarkupExtension(parserContext, lineInformation, nodeReference, xmlNamespaceResolver, valueTypeId, value)); } return(MarkupExtensionParser.CreateNodeFromTextValue(parserContext, lineInformation, nodeReference, xmlNamespaceResolver, typeConverter, (ITypeId)valueTypeId, value)); }
public static DocumentNode GetPropertyValue(XamlParserContext parserContext, ITextLocation lineInformation, IDocumentNodeReference nodeReference, IXmlNamespaceResolver xmlNamespaceResolver, IProperty propertyKey, string value, bool removeEscapeCharacters) { TypeConverter typeConverter = propertyKey.TypeConverter ?? propertyKey.PropertyType.TypeConverter; return(MarkupExtensionParser.GetPropertyValue(parserContext, lineInformation, nodeReference, xmlNamespaceResolver, typeConverter, propertyKey.PropertyType, value, removeEscapeCharacters)); }
public static DocumentNode GetPropertyValue(XamlParserContext parserContext, ITextLocation lineInformation, IDocumentNodeReference nodeReference, IXmlNamespaceResolver xmlNamespaceResolver, IProperty propertyKey, string value) { return(MarkupExtensionParser.GetPropertyValue(parserContext, lineInformation, nodeReference, xmlNamespaceResolver, propertyKey, value, false)); }
public static DocumentNode ParseMarkupExtension(XamlParserContext parserContext, ITextLocation lineInformation, IDocumentNodeReference nodeReference, IXmlNamespaceResolver xmlNamespaceResolver, IType valueType, string text) { MarkupExtensionDescription description = MarkupExtensionParser.Tokenize(parserContext, lineInformation, text); if (description != null) { IType typeId1 = XamlTypeHelper.GetTypeId(parserContext, lineInformation, xmlNamespaceResolver, description.Name, true); if (typeId1 != null) { if (parserContext.PlatformMetadata.KnownTypes.NullExtension.Equals((object)typeId1)) { if (description.PositionalArguments.Count > 0 || description.NamedArguments.Count > 0) { parserContext.ReportError(XamlParseErrors.InvalidMarkupExtensionArguments(lineInformation, description.Name)); } if (valueType.SupportsNullValues) { return((DocumentNode)parserContext.DocumentContext.CreateNode((ITypeId)valueType, (IDocumentNodeValue)null)); } parserContext.ReportError(XamlParseErrors.TypeIsNotNullable(lineInformation, (ITypeId)valueType)); return((DocumentNode)null); } if (parserContext.PlatformMetadata.KnownTypes.TypeExtension.IsAssignableFrom((ITypeId)typeId1)) { string extensionArgument = MarkupExtensionParser.GetRequiredMarkupExtensionArgument(parserContext, lineInformation, description, parserContext.PlatformMetadata.KnownProperties.TypeExtensionTypeName.Name); if (extensionArgument != null) { IType typeId2 = XamlTypeHelper.GetTypeId(parserContext, lineInformation, xmlNamespaceResolver, extensionArgument, true); if (typeId2 != null) { return((DocumentNode)parserContext.DocumentContext.CreateNode(parserContext.PlatformMetadata.KnownTypes.Type, (IDocumentNodeValue) new DocumentNodeMemberValue((IMember)typeId2))); } } } else if (parserContext.PlatformMetadata.KnownTypes.StaticExtension.IsAssignableFrom((ITypeId)typeId1)) { string extensionArgument = MarkupExtensionParser.GetRequiredMarkupExtensionArgument(parserContext, lineInformation, description, parserContext.PlatformMetadata.KnownProperties.StaticExtensionMember.Name); if (extensionArgument != null) { IType typeId2; string memberName; if (MarkupExtensionParser.GetTypeAndMemberName(parserContext, lineInformation, xmlNamespaceResolver, extensionArgument, (IType)null, out typeId2, out memberName)) { MemberAccessTypes allowableMemberAccess = TypeHelper.GetAllowableMemberAccess(parserContext.TypeResolver, typeId2); MemberType memberTypes = MemberType.LocalProperty | MemberType.Field; if (parserContext.TypeResolver.IsCapabilitySet(PlatformCapability.IncompleteAttachedPropertiesInMarkupExtensions)) { memberTypes |= MemberType.IncompleteAttachedProperty; } IMember memberId = (IMember)typeId2.GetMember(memberTypes, memberName, allowableMemberAccess) ?? XamlTypeHelper.AddMemberIfPossible(parserContext.PlatformMetadata, typeId2, MemberType.LocalProperty, memberName); if (memberId != null) { return((DocumentNode)DocumentNodeHelper.NewStaticNode(parserContext.DocumentContext, memberId)); } parserContext.ReportError(XamlParseErrors.UnrecognizedOrInaccessibleMember(lineInformation, memberName)); } return((DocumentNode)null); } } else { if (!parserContext.TypeResolver.PlatformMetadata.KnownTypes.Binding.Equals((object)typeId1) || description.PositionalArguments.Count != 1) { return(MarkupExtensionParser.ParseMarkupExtension(parserContext, lineInformation, nodeReference, xmlNamespaceResolver, typeId1, description)); } description.NamedArguments.Insert(0, new KeyValuePair <string, string>(parserContext.TypeResolver.PlatformMetadata.KnownProperties.BindingPath.Name, description.PositionalArguments[0])); description.PositionalArguments.Clear(); return(MarkupExtensionParser.ParseMarkupExtension(parserContext, lineInformation, nodeReference, xmlNamespaceResolver, typeId1, description)); } } } return((DocumentNode)null); }