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


C# CodeTypeDeclaration.TypeReference方法代码示例

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


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

示例1: CreateInterface

        public CodeTypeDeclaration CreateInterface(CodeTypeDeclaration wrapper)
        {
            var iface = new CodeTypeDeclaration ("I" + Name) {
                TypeAttributes = TypeAttributes.Interface | (wrapper != null? TypeAttributes.NestedPublic : TypeAttributes.Public),
                Attributes = MemberAttributes.Public,
                IsInterface = true
            };

            foreach (var arg in TemplateArguments)
                iface.TypeParameters.Add (arg);

            if (wrapper != null)
                iface.BaseTypes.Add (new CodeTypeReference (typeof (ICppClassOverridable<>).Name, wrapper.TypeReference ()));
            else
                iface.BaseTypes.Add (new CodeTypeReference (typeof (ICppClass).Name));

            foreach (var atom in Atoms)
                atom.Visit (iface);

            return iface;
        }
开发者ID:shana,项目名称:cppinterop,代码行数:21,代码来源:Class.cs

示例2: CreateWrapperClass

        public CodeTypeDeclaration CreateWrapperClass()
        {
            var wrapper = new CodeTypeDeclaration (Name) {
                Attributes = MemberAttributes.Public,
                TypeAttributes = TypeAttributes.Public
            };
            foreach (var arg in TemplateArguments)
                wrapper.TypeParameters.Add (arg);

            if (Atoms.Count == 0) {
                wrapper.Comments.Add (new CodeCommentStatement ("FIXME: This type is a stub."));
                string m = CreateBaseImplementation (wrapper);
                wrapper.BaseTypes.Add (m);
                wrapper.Members.Add (new CodeMemberMethod { Name = "Dispose", Attributes = MemberAttributes.Public});

                var ctor = new CodeConstructor {
                    Name = this.Name,
                    Attributes = MemberAttributes.Assembly
                };
                ctor.Parameters.Add (new CodeParameterDeclarationExpression (typeof (CppTypeInfo).Name, "subClass"));

                wrapper.Members.Add (ctor);
                return wrapper;
            }

            var iface = CreateInterface (wrapper);
            wrapper.Members.Add (iface);

            var native = CreateNativeLayout ();
            wrapper.Members.Add (native);

            // FIXME: For now, we'll have the managed wrapper extend from the first public base class
            string managedBase = Bases.Where (b => b.Access == Access.Public).Select (b => b.Name).FirstOrDefault ();
            bool hasOverrides = true;

            if (managedBase == null) {
                hasOverrides = false;
                managedBase = CreateBaseImplementation (wrapper);
            }
            wrapper.BaseTypes.Add (managedBase);

            // add static impl field
            var implField = new CodeMemberField (iface.TypeReference (), "impl") { Attributes = MemberAttributes.Static | MemberAttributes.Private };
            if (StaticCppLibrary != null) {
                CodeTypeReference [] types = new CodeTypeReference [] {
                    iface.TypeReference (),
                    native.TypeReference (),
                    wrapper.TypeReference ()
                };
                var getClassMethod = new CodeMethodReferenceExpression (new CodeTypeReferenceExpression (new CodeTypeReference (StaticCppLibrary, CodeTypeReferenceOptions.GlobalReference)), "GetClass", types);
                implField.InitExpression = new CodeMethodInvokeExpression (getClassMethod, new CodePrimitiveExpression (Name));
            }
            wrapper.Members.Add (implField);

            // always add native subclass ctor
            wrapper.Members.Add (CreateNativeSubclassConstructor (hasOverrides));

            CodeMemberMethod dispose = null;
            foreach (var atom in Atoms) {
                Method method = atom as Method;
                if (method != null && method.IsDestructor) {
                    dispose = (CodeMemberMethod)method.InsideCodeTypeDeclaration (wrapper);
                    atom.Visit (dispose);
                } else
                    atom.Visit (wrapper);
            }

            if (dispose == null) {
                dispose = CreateDestructorlessDispose ();
                wrapper.Members.Add (dispose);
            }

            if (hasOverrides)
                dispose.Attributes |= MemberAttributes.Override;

            return wrapper;
        }
开发者ID:shana,项目名称:cppinterop,代码行数:77,代码来源:Class.cs


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