コード例 #1
0
        /// <summary>
        /// Find or Create Class for Name and Using-List
        /// </summary>
        /// <param name="inProject"></param>
        /// <param name="inClassName"></param>
        /// <param name="inPossibleNamespaces"></param>
        /// <returns></returns>
        public static ClassContainer GetClassOrUnknownForType(this ProjectInformation inProject, string inClassName, List <string> inPossibleNamespaces)
        {
            if (string.IsNullOrEmpty(inClassName))
            {
                return(null);
            }
            var tmpClass = inProject.ClassForNameAndNamespaces(inClassName, inPossibleNamespaces);

            if (tmpClass != null)
            {
                return(tmpClass);
            }
            if (inProject.GetAliasType(inClassName) != null)
            {
                return(inProject.GetAliasType(inClassName));
            }
            var tmpUnknown = inProject.UnknownClassForNameAndNamespaces(inClassName, inPossibleNamespaces);

            if (tmpUnknown == null)
            {
                tmpUnknown = new UnknownTypeClass(inClassName)
                {
                    PossibleNamespace = inPossibleNamespaces
                };
                inProject.AddUnknownClass(tmpUnknown);
            }
            return(tmpUnknown);
        }
コード例 #2
0
        /// <summary>
        /// Find or Create Class for Name and Using-List
        /// </summary>
        /// <param name="inProject"></param>
        /// <param name="inClassName"></param>
        /// <param name="inPossibleNamespaces"></param>
        /// <returns></returns>
        public static ClassContainer GetClassOrUnknownForType(this ProjectInformation inProject, string inClassName, ClassContainer inParentClass)
        {
            if (string.IsNullOrEmpty(inClassName))
            {
                return(null);
            }
            var tmpClass = inProject.ClassForNameAndNamespaces(inClassName, inParentClass.FullUsingList);

            if (tmpClass != null)
            {
                return(tmpClass);
            }
            if (inProject.GetAliasType(inClassName) != null)
            {
                return(inProject.GetAliasType(inClassName));
            }
            if (inParentClass.Type == null)
            {
                return(null);
            }
            var tmpGenericType = inParentClass.Type.GenericTypes.FirstOrDefault(inItem => inItem.Name == inClassName);

            if (tmpGenericType != null)
            {
                return(new ClassContainer
                {
                    Type = tmpGenericType,
                    Parent = inProject
                });
            }

            var tmpParentClass = inParentClass;

            while (tmpParentClass != null)
            {
                var tmpField = tmpParentClass.FieldList.FirstOrDefault(inItem => inItem.Name == inClassName);
                if (tmpField != null)
                {
                    return(new ClassContainer
                    {
                        Type = tmpField.Type,
                        Parent = inProject
                    });
                }
                tmpParentClass = tmpParentClass.GetParentClass();
            }

            var tmpUnknown = inProject.UnknownClassForNameAndNamespaces(inClassName, inParentClass.FullUsingList);

            if (tmpUnknown == null)
            {
                tmpUnknown = new UnknownTypeClass(inClassName)
                {
                    PossibleNamespace = inParentClass.FullUsingList,
                    Parent            = inProject
                };
                inProject.AddUnknownClass(tmpUnknown);
            }
            return(tmpUnknown);
        }