当前位置: 首页>>代码示例>>C#>>正文


C# type_node.get_instance方法代码示例

本文整理汇总了C#中PascalABCCompiler.TreeRealization.type_node.get_instance方法的典型用法代码示例。如果您正苦于以下问题:C# type_node.get_instance方法的具体用法?C# type_node.get_instance怎么用?C# type_node.get_instance使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在PascalABCCompiler.TreeRealization.type_node的用法示例。


在下文中一共展示了type_node.get_instance方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: FindIEnumerableElementType

        public bool FindIEnumerableElementType(SyntaxTree.foreach_stmt _foreach_stmt, type_node tn, ref type_node elem_type)
        {
            var IEnstring = "System.Collections.IEnumerable";
            compiled_type_node ctn = compiled_type_node.get_type_node(NetHelper.NetHelper.FindType(IEnstring));
            if (tn is compiled_type_node || tn is compiled_generic_instance_type_node) // Если этот тип зашит в .NET
            // IEnumerable<integer>, Range(1,10), Dictionary<string,integer>: tn = compiled_type_node
            // IEnumerable<T>: tn = compiled_generic_instance_type_node
            // FibGen = class(IEnumerable,IEnumerator): tn = common_type_node, en = compiled_type_node
            // array of Person: tn = common_type_node
            {
                System.Type ct;
                if (tn is compiled_type_node)
                    ct = (tn as compiled_type_node).compiled_type;
                else
                {
                    var orig = (tn as compiled_generic_instance_type_node).original_generic as compiled_type_node;
                    var pars = tn.instance_params;
                    ct = orig.compiled_type;
                }
                    
                Type r;
                var IEnTstring = "System.Collections.Generic.IEnumerable`1";
                if (ct.ToString().StartsWith(IEnTstring))
                    r = ct;
                else
                    r = ct.GetInterface(IEnTstring);
                if (r != null)
                {
                    Type arg1 = r.GetGenericArguments().First(); // тип параметра IEnumerable
                    var str = arg1.GetGenericArguments().Count();
                    if (tn is compiled_type_node)
                    {
                        elem_type = compiled_type_node.get_type_node(arg1);
                    }
                    else
                    {
                        if (arg1.GetGenericArguments().Count()>0)
                        {
                            elem_type = compiled_type_node.get_type_node(arg1.GetGenericTypeDefinition());
                            elem_type = elem_type.get_instance(tn.instance_params); // SSM 19/07/15 - работает!!!
                        }
                        else
                        {
                            var ip = tn.instance_params;
                            //var Tname = ip[0].name;
                            //elem_type = convert_strong(new SyntaxTree.named_type_reference(Tname, _foreach_stmt.in_what.source_context));
                            elem_type = ip[0];
                        }
                            
                        //elem_type.instance_params = tn.instance_params;
                        //var ip = tn.instance_params;
                        //var Tname = new string(tn.name.SkipWhile(c => c != '<').Skip(1).TakeWhile(c => c != ',' && c != '>').ToArray());
                        //var Tname = ip[0].name;
                        //var Tname = "System.Collections.Generic.KeyValuePair'2"; // <integer,TClass>
                        //elem_type = convert_strong(new SyntaxTree.named_type_reference(Tname, _foreach_stmt.in_what.source_context));
                    }
                    return true;
                }
                else
                {
                    if (tn.element_type != null) // значит, это массив любой размерности - 02.02.16 SSM - еще может быть множество set of T - 22.02.16 SSM
                    {
                        elem_type = tn.element_type;
                        return true;
                    }

                    var ttt = tn.ImplementingInterfaces;
                    foreach (SemanticTree.ITypeNode itn in tn.ImplementingInterfaces)
                    {
                        if (itn == ctn)
                        {
                            elem_type = SystemLibrary.SystemLibrary.object_type;
                            return true;
                        }
                    }
                }
            }
            /*else if (tn is compiled_generic_instance_type_node)
            {
                var g = tn as compiled_generic_instance_type_node;
                var og = g.original_generic;
                var tt = og.ImplementingInterfaces;
                if (_foreach_stmt.type_name != null && _foreach_stmt.type_name.GetType()!=typeof(SyntaxTree.no_type_foreach))
                    elem_type = convert_strong(_foreach_stmt.type_name);
                else
                {
                    var fn = tn.full_name;
                }
                return true;
            }  */
            else // если мы самостоятельно определяем этот тип - можно реализовать в PascalABC.NET только IEnumerable. // Сейчас уже можно!!!!!
            // Попытка реализовать IEnumerable<T> натыкается на необходимость определять GetEnumerator, возвращающий IEnumerator и IEnumerator<T>
            {
                if (tn == null || tn is null_type_node || tn.ImplementingInterfaces == null)
                    return false;

                if (tn.element_type != null) // еще может быть множество set of T - 22.02.16 SSM
                {
                    elem_type = tn.element_type;
                    return true;
//.........这里部分代码省略.........
开发者ID:PascalABC-CompilerLaboratory,项目名称:pascalabcnet,代码行数:101,代码来源:syntax_tree_visitor.cs


注:本文中的PascalABCCompiler.TreeRealization.type_node.get_instance方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。