Beispiel #1
0
        internal static IType GetTypeId(XamlParserContext parserContext, ITextLocation lineInformation, XmlNamespace xmlNamespace, string typeName, bool inMarkupExtension)
        {
            if (string.IsNullOrEmpty(typeName))
            {
                parserContext.ReportError(XamlParseErrors.MissingTypeName(lineInformation));
                return((IType)null);
            }
            if (typeName.IndexOf('.') >= 0)
            {
                parserContext.ReportError(XamlParseErrors.InnerTypesNotSupported(lineInformation, typeName));
                return((IType)null);
            }
            IType typeId = XamlTypeHelper.GetTypeId(parserContext.TypeResolver, parserContext.DocumentNamespaces, xmlNamespace, typeName, true, inMarkupExtension);

            if (typeId != null && typeId.IsResolvable)
            {
                if (!parserContext.TypeResolver.InTargetAssembly(typeId) && !TypeHelper.IsSet(MemberAccessTypes.Public, typeId.Access))
                {
                    parserContext.ReportError(XamlParseErrors.InaccessibleType(lineInformation, typeName));
                    return((IType)null);
                }
            }
            else if (xmlNamespace == XmlNamespace.AvalonXmlNamespace || xmlNamespace == XmlNamespace.XamlXmlNamespace)
            {
                parserContext.ReportError(XamlParseErrors.UnrecognizedPlatformTypeName(lineInformation, !parserContext.TypeResolver.IsCapabilitySet(PlatformCapability.IsWpf), typeName));
            }
            else
            {
                parserContext.ReportError(XamlParseErrors.UnrecognizedTypeName(lineInformation, xmlNamespace, typeName));
            }
            return(typeId);
        }
Beispiel #2
0
        public static XamlParseError MismatchedVersionSDKType(ITextLocation lineInformation, IType childType, FrameworkName frameworkName)
        {
            string str           = (string)(frameworkName.Identifier == "Silverlight" ? (object)frameworkName.Identifier : (object)"Windows Presentation Framework") + (object)" " + (string)(object)frameworkName.Version.Major;
            string messageFormat = string.Format((IFormatProvider)CultureInfo.CurrentCulture, StringTable.MismatchedVersionSDKType, (object)childType.Name, (object)childType.RuntimeAssembly.Name, (object)str);

            return(XamlParseErrors.NewParseError(XamlErrorSeverity.Error, XamlErrorCode.MismatchedType, lineInformation, messageFormat));
        }
Beispiel #3
0
 private static string GetRequiredMarkupExtensionArgument(XamlParserContext parserContext, ITextLocation lineInformation, MarkupExtensionDescription description, string propertyName)
 {
     if (description.PositionalArguments.Count == 1 && description.NamedArguments.Count == 0)
     {
         return(description.PositionalArguments[0]);
     }
     if (description.PositionalArguments.Count == 0 && description.NamedArguments.Count == 1 && description.NamedArguments[0].Key == propertyName)
     {
         return(description.NamedArguments[0].Value);
     }
     parserContext.ReportError(XamlParseErrors.InvalidMarkupExtensionArguments(lineInformation, description.Name));
     return((string)null);
 }
Beispiel #4
0
        internal static void ParsePropertyPathParameters(XamlParserContext parserContext, ITextLocation lineInformation, IXmlNamespaceResolver xmlNamespaceResolver, string path, out string propertyPath, out IList <IProperty> pathParameters)
        {
            pathParameters = (IList <IProperty>) new List <IProperty>();
            StringBuilder stringBuilder = new StringBuilder();
            int           startIndex;
            int           num1;
            int           num2;

            for (startIndex = 0; (num1 = path.IndexOf('(', startIndex)) >= 0; startIndex = num2 + 1)
            {
                num2 = path.IndexOf(')', num1 + 1);
                if (num2 < 0)
                {
                    parserContext.ReportError(XamlParseErrors.InvalidPropertyPathSyntax(lineInformation, path));
                    startIndex = path.Length;
                    break;
                }
                string prefixAndTypeName = path.Substring(num1 + 1, num2 - num1 - 1);
                if (prefixAndTypeName.IndexOf('.') >= 0)
                {
                    stringBuilder.Append(path.Substring(startIndex, num1 - startIndex));
                    stringBuilder.Append('(');
                    stringBuilder.Append(pathParameters.Count);
                    stringBuilder.Append(')');
                    IProperty   property = (IProperty)null;
                    XmlnsPrefix prefix;
                    string      typeName;
                    if (XamlTypeHelper.SplitTypeName(parserContext, lineInformation, prefixAndTypeName, out prefix, out typeName))
                    {
                        XmlNamespace xmlNamespace = parserContext.GetXmlNamespace(lineInformation, xmlNamespaceResolver, prefix);
                        MemberType   memberTypes  = MemberType.Property | MemberType.Field;
                        if (parserContext.TypeResolver.IsCapabilitySet(PlatformCapability.IncompleteAttachedPropertiesInMarkupExtensions))
                        {
                            memberTypes |= MemberType.IncompleteAttachedProperty;
                        }
                        IMember member = (IMember)XamlTypeHelper.GetPropertyKey(parserContext, lineInformation, xmlNamespace, typeName, (XmlNamespace)null, (IType)null, memberTypes, MemberType.AttachedProperty, false);
                        if (member != null)
                        {
                            property = MarkupExtensionParser.VerifyMemberIsDependencyProperty(parserContext, lineInformation, member);
                        }
                    }
                    pathParameters.Add(property);
                }
                else
                {
                    stringBuilder.Append(path.Substring(startIndex, num2 - startIndex + 1));
                }
            }
            stringBuilder.Append(path.Substring(startIndex));
            propertyPath = stringBuilder.ToString();
        }
Beispiel #5
0
        public XmlNamespace GetXmlNamespace(ITextLocation lineInformation, IXmlNamespaceResolver xmlNamespaceResolver, XmlnsPrefix prefix)
        {
            XmlNamespace xmlNamespace = xmlNamespaceResolver.GetXmlNamespace(prefix, XmlNamespace.GetNamespaceCanonicalization(this.TypeResolver));

            if (xmlNamespace != null)
            {
                return(xmlNamespace);
            }
            if (prefix == XmlnsPrefix.EmptyPrefix)
            {
                this.ReportError(XamlParseErrors.NoDefaultNamespace(lineInformation));
            }
            else
            {
                this.ReportError(XamlParseErrors.UnrecognizedXmlnsPrefix(lineInformation, prefix));
            }
            return(XmlNamespace.AvalonXmlNamespace);
        }
Beispiel #6
0
        internal static bool SplitMemberName(XamlParserContext parserContext, ITextLocation lineInformation, string typeAndMemberName, out string typeName, out string memberName)
        {
            typeName   = (string)null;
            memberName = (string)null;
            int length = typeAndMemberName.LastIndexOf('.');

            if (length >= 0)
            {
                if (length == 0 || length == typeAndMemberName.Length - 1)
                {
                    parserContext.ReportError(XamlParseErrors.InvalidTypeQualifiedMemberName(lineInformation, typeAndMemberName));
                    return(false);
                }
                typeName   = typeAndMemberName.Substring(0, length);
                memberName = typeAndMemberName.Substring(length + 1);
                return(true);
            }
            memberName = typeAndMemberName;
            return(true);
        }
Beispiel #7
0
        internal static bool SplitTypeName(XamlParserContext parserContext, ITextLocation lineInformation, string prefixAndTypeName, out XmlnsPrefix prefix, out string typeName)
        {
            int length = prefixAndTypeName.IndexOf(':');

            if (length >= 0)
            {
                if (length == 0 || length == prefixAndTypeName.Length - 1)
                {
                    parserContext.ReportError(XamlParseErrors.InvalidPrefixQualifiedTypeName(lineInformation, prefixAndTypeName));
                    prefix   = (XmlnsPrefix)null;
                    typeName = (string)null;
                    return(false);
                }
                prefix   = XmlnsPrefix.ToPrefix(prefixAndTypeName.Substring(0, length));
                typeName = prefixAndTypeName.Substring(length + 1);
                return(true);
            }
            prefix   = XmlnsPrefix.EmptyPrefix;
            typeName = prefixAndTypeName;
            return(true);
        }
Beispiel #8
0
        public static bool GetTypeAndMemberName(XamlParserContext parserContext, ITextLocation lineInformation, IXmlNamespaceResolver xmlNamespaceResolver, string fullMemberName, IType targetTypeId, out IType typeId, out string memberName)
        {
            typeId     = (IType)null;
            memberName = (string)null;
            XmlnsPrefix prefix;
            string      typeName1;

            if (XamlTypeHelper.SplitTypeName(parserContext, lineInformation, fullMemberName, out prefix, out typeName1))
            {
                XmlNamespace xmlNamespace = parserContext.GetXmlNamespace(lineInformation, xmlNamespaceResolver, prefix);
                string       typeName2;
                if (XamlTypeHelper.SplitMemberName(parserContext, lineInformation, typeName1, out typeName2, out memberName))
                {
                    typeId = typeName2 == null ? targetTypeId : XamlTypeHelper.GetTypeId(parserContext, lineInformation, xmlNamespace, typeName2);
                    if (typeId != null)
                    {
                        return(true);
                    }
                    parserContext.ReportError(XamlParseErrors.CannotDetermineMemberTargetType(lineInformation, memberName));
                }
            }
            return(false);
        }
Beispiel #9
0
        private static IProperty VerifyMemberIsDependencyProperty(XamlParserContext parserContext, ITextLocation lineInformation, IMember member)
        {
            IDependencyProperty dependencyProperty = member as IDependencyProperty;

            if (dependencyProperty != null)
            {
                return((IProperty)dependencyProperty);
            }
            if (member.IsResolvable)
            {
                IType     declaringType           = member.DeclaringType;
                Exception initializationException = declaringType.InitializationException;
                if (initializationException != null)
                {
                    parserContext.ReportError(XamlParseErrors.TypeInitializationException(lineInformation, (ITypeId)declaringType, initializationException.Message));
                }
                else
                {
                    parserContext.ReportError(XamlParseErrors.MemberNotDependencyProperty(lineInformation, (IMemberId)member));
                }
            }
            return((IProperty)null);
        }
Beispiel #10
0
        private static IEvent VerifyMemberIsRoutedEvent(XamlParserContext parserContext, ITextLocation lineInformation, IMember member)
        {
            IEvent @event = member as IEvent;

            if (@event != null && @event.IncludesRoutedEvent)
            {
                return(@event);
            }
            if (member.IsResolvable)
            {
                IType     declaringType           = member.DeclaringType;
                Exception initializationException = declaringType.InitializationException;
                if (initializationException != null)
                {
                    parserContext.ReportError(XamlParseErrors.TypeInitializationException(lineInformation, (ITypeId)declaringType, initializationException.Message));
                }
                else
                {
                    parserContext.ReportError(XamlParseErrors.MemberNotRoutedEvent(lineInformation, (IMemberId)member));
                }
            }
            return((IEvent)null);
        }
Beispiel #11
0
 public static XamlParseError InvalidMarkupExtensionArguments(ITextLocation lineInformation, string markupExtensionName)
 {
     return(XamlParseErrors.NewParseError(XamlErrorSeverity.Error, XamlErrorCode.InvalidMarkupExtensionArguments, lineInformation, StringTable.ParserInvalidMarkupExtensionArguments, markupExtensionName));
 }
Beispiel #12
0
 public static XamlParseError UnknownError(ITextLocation lineInformation)
 {
     return(XamlParseErrors.NewParseError(XamlErrorSeverity.Error, XamlErrorCode.UnknownError, lineInformation, StringTable.ParserUnknownError));
 }
Beispiel #13
0
 public static XamlParseError PropertyIsNotWritable(ITextLocation lineInformation, IPropertyId propertyKey)
 {
     return(XamlParseErrors.NewParseError(XamlErrorSeverity.Error, XamlErrorCode.PropertyIsNotWritable, lineInformation, StringTable.ParserPropertyIsNotWritable, propertyKey.Name));
 }
Beispiel #14
0
 public static XamlParseError NestedPropertiesNotSupported(ITextLocation lineInformation, string propertyName)
 {
     return(XamlParseErrors.NewParseError(XamlErrorSeverity.Error, XamlErrorCode.NestedPropertiesNotSupported, lineInformation, StringTable.ParserNestedPropertiesNotSupported, propertyName));
 }
Beispiel #15
0
 public static XamlParseError InaccessibleType(ITextLocation lineInformation, string typeName)
 {
     return(XamlParseErrors.NewParseError(XamlErrorSeverity.Error, XamlErrorCode.InaccessibleType, lineInformation, StringTable.ParserInaccessibleType, typeName));
 }
Beispiel #16
0
 public static XamlParseError UnrecognizedPlatformTypeName(ITextLocation lineInformation, bool isSilverlightProject, string typeName)
 {
     return(XamlParseErrors.NewParseError(XamlErrorSeverity.Error, XamlErrorCode.UnrecognizedTypeName, lineInformation, StringTable.ParserUnrecognizedPlatformTypeName, isSilverlightProject ? StringTable.ParserSilverlightPlatformName : StringTable.ParserWPFPlatformName, typeName));
 }
Beispiel #17
0
 public static XamlParseError InvalidClassName(ITextLocation lineInformation, string typeName)
 {
     return(XamlParseErrors.NewParseError(XamlErrorSeverity.Warning, XamlErrorCode.InvalidClassName, lineInformation, StringTable.ParserInvalidClassName, typeName));
 }
Beispiel #18
0
 public static XamlParseError MultipleRootElements(ITextLocation lineInformation)
 {
     return(XamlParseErrors.NewParseError(XamlErrorSeverity.Error, XamlErrorCode.MultipleRootElements, lineInformation, StringTable.ParserMultipleRootElements));
 }
Beispiel #19
0
 public static XamlParseError NoDefaultNamespace(ITextLocation lineInformation)
 {
     return(XamlParseErrors.NewParseError(XamlErrorSeverity.Error, XamlErrorCode.NoDefaultNamespace, lineInformation, StringTable.ParserNoDefaultNamespace));
 }
Beispiel #20
0
 public static XamlParseError UnexpectedCharacter(ITextLocation lineInformation, char c)
 {
     return(XamlParseErrors.NewParseError(XamlErrorSeverity.Error, XamlErrorCode.UnexpectedCharacter, lineInformation, StringTable.ParserUnexpectedCharacter, c.ToString()));
 }
Beispiel #21
0
 public static XamlParseError DuplicateXmlnsPrefix(ITextLocation lineInformation, XmlnsPrefix prefix)
 {
     return(XamlParseErrors.NewParseError(XamlErrorSeverity.Error, XamlErrorCode.DuplicateXmlnsPrefix, lineInformation, StringTable.ParserDuplicateXmlnsPrefix, prefix.Value));
 }
Beispiel #22
0
 public static XamlParseError InvalidPropertyPathSyntax(ITextLocation lineInformation, string propertyPath)
 {
     return(XamlParseErrors.NewParseError(XamlErrorSeverity.Error, XamlErrorCode.InvalidPropertyPathSyntax, lineInformation, StringTable.ParserInvalidPropertyPathSyntax, propertyPath));
 }
Beispiel #23
0
 public static XamlParseError UnrecognizedTypeName(ITextLocation lineInformation, XmlNamespace xmlNamespace, string typeName)
 {
     return(XamlParseErrors.NewParseError(XamlErrorSeverity.Error, XamlErrorCode.UnrecognizedTypeName, lineInformation, StringTable.ParserUnrecognizedTypeName, xmlNamespace.Value, typeName));
 }
Beispiel #24
0
 public static XamlParseError InvalidClrNamespaceUri(ITextLocation lineInformation, string uriValue)
 {
     return(XamlParseErrors.NewParseError(XamlErrorSeverity.Error, XamlErrorCode.InvalidClrNamespaceUri, lineInformation, StringTable.ParserInvalidClrNamespaceUri, uriValue));
 }
Beispiel #25
0
 public static XamlParseError InnerTypesNotSupported(ITextLocation lineInformation, string typeName)
 {
     return(XamlParseErrors.NewParseError(XamlErrorSeverity.Error, XamlErrorCode.InnerTypesNotSupported, lineInformation, StringTable.ParserInnerTypesNotSupported, typeName));
 }
Beispiel #26
0
 public static XamlParseError InvalidXmlSpace(ITextLocation lineInformation, string value)
 {
     return(XamlParseErrors.NewParseError(XamlErrorSeverity.Error, XamlErrorCode.InvalidXmlSpace, lineInformation, StringTable.ParserInvalidXmlSpace, value));
 }
Beispiel #27
0
 public static XamlParseError UnrecognizedOrInaccessibleMember(ITextLocation lineInformation, string memberName)
 {
     return(XamlParseErrors.NewParseError(XamlErrorSeverity.Error, XamlErrorCode.UnrecognizedOrInaccessibleMember, lineInformation, StringTable.ParserUnrecognizedOrInaccessibleMember, memberName));
 }
Beispiel #28
0
 public static XamlParseError UnexpectedRootType(ITextLocation lineInformation, ITypeId expectedType)
 {
     return(XamlParseErrors.NewParseError(XamlErrorSeverity.Error, XamlErrorCode.UnexpectedRootType, lineInformation, StringTable.ParserUnexpectedRootType, expectedType.Name));
 }
Beispiel #29
0
 public static XamlParseError CannotDetermineMemberTargetType(ITextLocation lineInformation, string memberName)
 {
     return(XamlParseErrors.NewParseError(XamlErrorSeverity.Error, XamlErrorCode.CannotDetermineMemberTargetType, lineInformation, StringTable.ParserCannotDetermineMemberTargetType, memberName));
 }
Beispiel #30
0
 public static XamlParseError CDataNotSupported(ITextLocation lineInformation)
 {
     return(XamlParseErrors.NewParseError(XamlErrorSeverity.Error, XamlErrorCode.CDataNotSupported, lineInformation, StringTable.ParserCDataNotSupported));
 }