示例#1
0
        public static TheClass Get(CsNode pNode, FactoryExpressionCreator pCreator)
        {
            if (pNode == null)
            {
                return(null);
            }

            CsExpression csExpression = pNode as CsExpression;

            if (csExpression != null && csExpression.ec != expression_classification.ec_nothing)
            {
                return(Get((CsEntity)csExpression.entity, pCreator));
            }

            while (pNode != null)
            {
                if (pNode is CsTypeRef || pNode is CsClass || pNode is CsInterface)
                {
                    break;
                }

                pNode = pNode.parent;
            }

            CsClass klass = pNode as CsClass;

            if (klass != null)
            {
                if (!_classes.ContainsKey(klass))
                {
                    _classes[klass] = new TheClass(klass, pCreator);
                }

                return(_classes[klass]);
            }

            CsTypeRef csTypeRef = pNode as CsTypeRef;

            if (csTypeRef != null)
            {
                return(csTypeRef.entity_typeref == null ? null : Get((CsEntityClass)(csTypeRef.entity_typeref.u), pCreator));
            }

            CsInterface csInterface = pNode as CsInterface;

            if (csInterface != null)
            {
                if (!_interfaces.ContainsKey(csInterface))
                {
                    _interfaces[csInterface] = new TheClass(csInterface, pCreator);
                }

                return(_interfaces[csInterface]);
            }

            throw new Exception();
        }
示例#2
0
        public static string GetType(CsTypeRef pDirective)
        {
            switch (pDirective.entity_typeref.type)
            {
            case cs_entity_type.et_array:
                return(GetTokenType(pDirective.predefined_type) + "[]");

            case cs_entity_type.et_genericinst:
                string baseName = GetType(pDirective.type_name);

                return(baseName.Equals("var", StringComparison.Ordinal)
                                                ? GetType(((CsEntityInstanceSpecifier)pDirective.entity_typeref.u).type)
                                                : baseName);

            default:
                return(pDirective.predefined_type == CsTokenType.tkEOF
                                                ? GetType(pDirective.type_name)
                                                : GetTokenType(pDirective.predefined_type));
            }
        }
示例#3
0
        public static string GetType(CsNamespaceOrTypeName pDirective)
        {
            string g = "";

            //generics
            if (pDirective.type_argument_list != null && pDirective.type_argument_list.list.Count != 0)
            {
                g += "<";
                foreach (CsTypeRef typeRef in pDirective.type_argument_list.list)
                {
                    g += GetType(typeRef);
                    g += ", ";
                }

                g = g.TrimEnd(_paramTrim) + ">";
            }
            string ret = "";

            if (pDirective.namespace_or_type_name == null)
            {
                if (pDirective.parent is CsTypeRef)
                {
                    CsTypeRef parent = ((CsTypeRef)pDirective.parent);

                    if (parent.entity_typeref.u is CsEntityClass)
                    {
                        if (IsClassDefinedAsObject(((CsEntityClass)parent.entity_typeref.u).attributes))
                        {
                            return("object");
                        }

                        return(((CsEntityClass)parent.entity_typeref.u).name);
                    }

                    if (parent.entity_typeref.type == cs_entity_type.et_generic_param)
                    {
                        return("<" + pDirective.identifier.identifier + ">");
                        //return "*";
                    }

                    if (parent.entity_typeref.u is CsEntityInstanceSpecifier)
                    {
                        //if (IsClassDefinedAsObject(((CsEntityInstanceSpecifier)parent.entity_typeref.u)))
                        //return "Object";
                    }
                }
                else if (pDirective.parent is CsUsingNamespaceDirective)
                {
                    CsUsingNamespaceDirective parent = (CsUsingNamespaceDirective)pDirective.parent;
                    if (parent.namespace_or_type_entity != null)
                    {
                        ret = "." + parent.namespace_or_type_entity.name;
                        CsEntityNamespace p = parent.namespace_or_type_entity.parent as CsEntityNamespace;
                        while (p != null)
                        {
                            ret = "." + p.name + ret;
                            p   = p.parent as CsEntityNamespace;
                        }

                        ret = ret.TrimStart('.');
                        return(ret + g);
                    }
                }
            }


            ret = GetType(pDirective.namespace_or_type_name);
            if (!string.IsNullOrEmpty(ret))
            {
                ret += ".";
            }

            return(ret + pDirective.identifier.identifier + g);
        }
示例#4
0
		public static string GetType(CsTypeRef pDirective) {
			switch (pDirective.entity_typeref.type) {
				case cs_entity_type.et_array:
					return GetTokenType(pDirective.predefined_type) + "[]";

				case cs_entity_type.et_genericinst:
					string baseName = GetType(pDirective.type_name);

					return baseName.Equals("var", StringComparison.Ordinal)
					       	? GetType(((CsEntityInstanceSpecifier)pDirective.entity_typeref.u).type)
					       	: baseName;

				default:
					return pDirective.predefined_type == CsTokenType.tkEOF
					       	? GetType(pDirective.type_name)
					       	: GetTokenType(pDirective.predefined_type);
			}
		}