コード例 #1
0
ファイル: XamlNamespace.cs プロジェクト: zx597855313/wpf
        private XamlType TryGetXamlType(string typeName, Type[] typeArgs)
        {
            // Can't get an array of open generic and then call MakeGenericType on it.
            // So we need to process subscripts on generics ourselves.
            string subscript;

            typeName = GenericTypeNameScanner.StripSubscript(typeName, out subscript);
            typeName = MangleGenericTypeName(typeName, typeArgs.Length);

            // Get the open generic
            Type     openType     = null;
            XamlType openXamlType = TryGetXamlType(typeName);

            if (openXamlType != null)
            {
                openType = openXamlType.UnderlyingType;
            }
            if (openType == null)
            {
                return(null);
            }

            // Close it
            Type closedType = openType.MakeGenericType(typeArgs);

            if (!string.IsNullOrEmpty(subscript))
            {
                closedType = MakeArrayType(closedType, subscript);
                if (closedType == null)
                {
                    return(null); // invalid subscript
                }
            }
            return(SchemaContext.GetXamlType(closedType));
        }
コード例 #2
0
        private XamlType TryGetXamlType(string typeName, Type[] typeArgs)
        {
            string str;

            typeName = GenericTypeNameScanner.StripSubscript(typeName, out str);
            typeName = MangleGenericTypeName(typeName, typeArgs.Length);
            Type     underlyingType = null;
            XamlType type2          = this.TryGetXamlType(typeName);

            if (type2 != null)
            {
                underlyingType = type2.UnderlyingType;
            }
            if (underlyingType == null)
            {
                return(null);
            }
            Type elementType = underlyingType.MakeGenericType(typeArgs);

            if (!string.IsNullOrEmpty(str))
            {
                elementType = MakeArrayType(elementType, str);
                if (elementType == null)
                {
                    return(null);
                }
            }
            return(this.SchemaContext.GetXamlType(elementType));
        }
コード例 #3
0
ファイル: XamlTypeName.cs プロジェクト: larrynung/wpf
        internal void ConvertToStringInternal(StringBuilder result, Func <string, string> prefixGenerator)
        {
            if (Namespace == null)
            {
                throw new InvalidOperationException(SR.Get(SRID.XamlTypeNameNamespaceIsNull));
            }
            if (string.IsNullOrEmpty(Name))
            {
                throw new InvalidOperationException(SR.Get(SRID.XamlTypeNameNameIsNullOrEmpty));
            }
            if (prefixGenerator == null)
            {
                result.Append("{");
                result.Append(Namespace);
                result.Append("}");
            }
            else
            {
                string prefix = prefixGenerator.Invoke(Namespace);
                if (prefix == null)
                {
                    throw new InvalidOperationException(SR.Get(SRID.XamlTypeNameCannotGetPrefix, Namespace));
                }
                if (prefix != string.Empty)
                {
                    result.Append(prefix);
                    result.Append(":");
                }
            }
            if (HasTypeArgs)
            {
                // The subscript goes after the type args
                string subscript;
                string name = GenericTypeNameScanner.StripSubscript(Name, out subscript);
                result.Append(name);

                result.Append("(");
                ConvertListToStringInternal(result, TypeArguments, prefixGenerator);
                result.Append(")");

                result.Append(subscript);
            }
            else
            {
                result.Append(Name);
            }
        }
コード例 #4
0
 internal void ConvertToStringInternal(StringBuilder result, Func <string, string> prefixGenerator)
 {
     if (this.Namespace == null)
     {
         throw new InvalidOperationException(System.Xaml.SR.Get("XamlTypeNameNamespaceIsNull"));
     }
     if (string.IsNullOrEmpty(this.Name))
     {
         throw new InvalidOperationException(System.Xaml.SR.Get("XamlTypeNameNameIsNullOrEmpty"));
     }
     if (prefixGenerator == null)
     {
         result.Append("{");
         result.Append(this.Namespace);
         result.Append("}");
     }
     else
     {
         string str = prefixGenerator(this.Namespace);
         if (str == null)
         {
             throw new InvalidOperationException(System.Xaml.SR.Get("XamlTypeNameCannotGetPrefix", new object[] { this.Namespace }));
         }
         if (str != string.Empty)
         {
             result.Append(str);
             result.Append(":");
         }
     }
     if (this.HasTypeArgs)
     {
         string str2;
         string str3 = GenericTypeNameScanner.StripSubscript(this.Name, out str2);
         result.Append(str3);
         result.Append("(");
         ConvertListToStringInternal(result, this.TypeArguments, prefixGenerator);
         result.Append(")");
         result.Append(str2);
     }
     else
     {
         result.Append(this.Name);
     }
 }