本文整理汇总了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;
}
示例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;
}