Пример #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);
        }
Пример #2
0
        private static void ExtractRangeLastTokenText(
            ITextLocation <TokenTextPoint> location, string token,
            bool wholeToken, string endMarker, StringBuilder sb)
        {
            if (location.B.At > 0)
            {
                // add token left portion
                sb.Append(token, 0, location.B.Run);

                // if we must get the whole token get also its right portion
                // and add markers if any
                if (wholeToken)
                {
                    if (!string.IsNullOrEmpty(endMarker))
                    {
                        sb.Append(endMarker);
                    }

                    if (location.B.At - 1 + location.B.Run < token.Length)
                    {
                        sb.Append(token,
                                  location.B.At - 1 + location.B.Run,
                                  token.Length - location.B.At - 1 + location.B.Run);
                    }
                }
            }

            // not a partial token, just copy it
            else
            {
                sb.Append(token);
            }
        }
Пример #3
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));
        }
Пример #4
0
        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));
        }
Пример #5
0
 internal XamlParseError(XamlErrorSeverity severity, int errorCode, ITextLocation lineInformation, string messageFormat, params string[] parameters)
 {
     this.severity        = severity;
     this.errorCode       = errorCode;
     this.lineInformation = lineInformation != null ? lineInformation : (ITextLocation) new TextLocation(0, 0);
     this.messageFormat   = messageFormat;
     this.parameters      = new List <string>((IEnumerable <string>)parameters);
 }
Пример #6
0
            public override bool Equals(object obj)
            {
                if (this == obj)
                {
                    return(true);
                }
                ITextLocation textLocation = obj as ITextLocation;

                if (textLocation != null && this.Line == textLocation.Line)
                {
                    return(this.Column == textLocation.Column);
                }
                return(false);
            }
Пример #7
0
        internal static IType GetTypeId(XamlParserContext parserContext, ITextLocation lineInformation, IXmlNamespaceResolver xmlNamespaceResolver, string fullTypeName, bool inMarkupExtension)
        {
            XmlnsPrefix prefix;
            string      typeName;

            if (XamlTypeHelper.SplitTypeName(parserContext, lineInformation, fullTypeName, out prefix, out typeName))
            {
                XmlNamespace xmlNamespace = parserContext.GetXmlNamespace(lineInformation, xmlNamespaceResolver, prefix);
                if (xmlNamespace != null)
                {
                    return(XamlTypeHelper.GetTypeId(parserContext, lineInformation, xmlNamespace, typeName, inMarkupExtension));
                }
            }
            return((IType)null);
        }
Пример #8
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);
        }
Пример #9
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);
        }
Пример #10
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);
        }
Пример #11
0
        internal static IProperty GetPropertyKey(XamlParserContext parserContext, ITextLocation lineInformation, IXmlNamespaceResolver xmlElementReference, string fullPropertyName, XmlNamespace targetTypeNamespace, IType targetTypeId, MemberType memberTypes, MemberType defaultType, bool allowProtectedPropertiesOnTargetType)
        {
            XmlnsPrefix prefix;
            string      typeName;

            if (!XamlTypeHelper.SplitTypeName(parserContext, lineInformation, fullPropertyName, out prefix, out typeName))
            {
                return((IProperty)null);
            }
            XmlNamespace xmlNamespace = (XmlNamespace)null;

            if (prefix != XmlnsPrefix.EmptyPrefix || typeName.IndexOf('.') >= 0)
            {
                xmlNamespace = parserContext.GetXmlNamespace(lineInformation, xmlElementReference, prefix);
                if (xmlNamespace == null)
                {
                    return((IProperty)null);
                }
            }
            return(XamlTypeHelper.GetPropertyKey(parserContext, lineInformation, xmlNamespace, typeName, targetTypeNamespace, targetTypeId, memberTypes, defaultType, allowProtectedPropertiesOnTargetType));
        }
Пример #12
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);
        }
Пример #13
0
 public static XamlParseError NestedPropertiesNotSupported(ITextLocation lineInformation, string propertyName)
 {
     return(XamlParseErrors.NewParseError(XamlErrorSeverity.Error, XamlErrorCode.NestedPropertiesNotSupported, lineInformation, StringTable.ParserNestedPropertiesNotSupported, propertyName));
 }
Пример #14
0
 public static XamlParseError InnerTypesNotSupported(ITextLocation lineInformation, string typeName)
 {
     return(XamlParseErrors.NewParseError(XamlErrorSeverity.Error, XamlErrorCode.InnerTypesNotSupported, lineInformation, StringTable.ParserInnerTypesNotSupported, typeName));
 }
Пример #15
0
 public static XamlParseError InaccessibleType(ITextLocation lineInformation, string typeName)
 {
     return(XamlParseErrors.NewParseError(XamlErrorSeverity.Error, XamlErrorCode.InaccessibleType, lineInformation, StringTable.ParserInaccessibleType, typeName));
 }
Пример #16
0
 public static XamlParseError UnrecognizedTypeName(ITextLocation lineInformation, XmlNamespace xmlNamespace, string typeName)
 {
     return(XamlParseErrors.NewParseError(XamlErrorSeverity.Error, XamlErrorCode.UnrecognizedTypeName, lineInformation, StringTable.ParserUnrecognizedTypeName, xmlNamespace.Value, typeName));
 }
Пример #17
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));
 }
Пример #18
0
 public static XamlParseError DuplicateXmlnsPrefix(ITextLocation lineInformation, XmlnsPrefix prefix)
 {
     return(XamlParseErrors.NewParseError(XamlErrorSeverity.Error, XamlErrorCode.DuplicateXmlnsPrefix, lineInformation, StringTable.ParserDuplicateXmlnsPrefix, prefix.Value));
 }
Пример #19
0
 public static XamlParseError InvalidXmlSpace(ITextLocation lineInformation, string value)
 {
     return(XamlParseErrors.NewParseError(XamlErrorSeverity.Error, XamlErrorCode.InvalidXmlSpace, lineInformation, StringTable.ParserInvalidXmlSpace, value));
 }
Пример #20
0
 public static XamlParseError NoDefaultNamespace(ITextLocation lineInformation)
 {
     return(XamlParseErrors.NewParseError(XamlErrorSeverity.Error, XamlErrorCode.NoDefaultNamespace, lineInformation, StringTable.ParserNoDefaultNamespace));
 }
Пример #21
0
 public static XamlParseError InvalidPropertyPathSyntax(ITextLocation lineInformation, string propertyPath)
 {
     return(XamlParseErrors.NewParseError(XamlErrorSeverity.Error, XamlErrorCode.InvalidPropertyPathSyntax, lineInformation, StringTable.ParserInvalidPropertyPathSyntax, propertyPath));
 }
Пример #22
0
 public static XamlParseError CannotDetermineMemberTargetType(ITextLocation lineInformation, string memberName)
 {
     return(XamlParseErrors.NewParseError(XamlErrorSeverity.Error, XamlErrorCode.CannotDetermineMemberTargetType, lineInformation, StringTable.ParserCannotDetermineMemberTargetType, memberName));
 }
Пример #23
0
 public static XamlParseError CDataNotSupported(ITextLocation lineInformation)
 {
     return(XamlParseErrors.NewParseError(XamlErrorSeverity.Error, XamlErrorCode.CDataNotSupported, lineInformation, StringTable.ParserCDataNotSupported));
 }
Пример #24
0
 public static XamlParseError UnexpectedRootType(ITextLocation lineInformation, ITypeId expectedType)
 {
     return(XamlParseErrors.NewParseError(XamlErrorSeverity.Error, XamlErrorCode.UnexpectedRootType, lineInformation, StringTable.ParserUnexpectedRootType, expectedType.Name));
 }
Пример #25
0
 public static XamlParseError UnrecognizedOrInaccessibleMember(ITextLocation lineInformation, string memberName)
 {
     return(XamlParseErrors.NewParseError(XamlErrorSeverity.Error, XamlErrorCode.UnrecognizedOrInaccessibleMember, lineInformation, StringTable.ParserUnrecognizedOrInaccessibleMember, memberName));
 }
Пример #26
0
 public static XamlParseError InvalidClassName(ITextLocation lineInformation, string typeName)
 {
     return(XamlParseErrors.NewParseError(XamlErrorSeverity.Warning, XamlErrorCode.InvalidClassName, lineInformation, StringTable.ParserInvalidClassName, typeName));
 }
Пример #27
0
 public static XamlParseError PropertyIsNotWritable(ITextLocation lineInformation, IPropertyId propertyKey)
 {
     return(XamlParseErrors.NewParseError(XamlErrorSeverity.Error, XamlErrorCode.PropertyIsNotWritable, lineInformation, StringTable.ParserPropertyIsNotWritable, propertyKey.Name));
 }
Пример #28
0
 public static XamlParseError InvalidClrNamespaceUri(ITextLocation lineInformation, string uriValue)
 {
     return(XamlParseErrors.NewParseError(XamlErrorSeverity.Error, XamlErrorCode.InvalidClrNamespaceUri, lineInformation, StringTable.ParserInvalidClrNamespaceUri, uriValue));
 }
Пример #29
0
 public static XamlParseError UnknownError(ITextLocation lineInformation)
 {
     return(XamlParseErrors.NewParseError(XamlErrorSeverity.Error, XamlErrorCode.UnknownError, lineInformation, StringTable.ParserUnknownError));
 }
Пример #30
0
 public static XamlParseError MultipleRootElements(ITextLocation lineInformation)
 {
     return(XamlParseErrors.NewParseError(XamlErrorSeverity.Error, XamlErrorCode.MultipleRootElements, lineInformation, StringTable.ParserMultipleRootElements));
 }