本文整理汇总了C#中ITypeDefinition.GetSourceProject方法的典型用法代码示例。如果您正苦于以下问题:C# ITypeDefinition.GetSourceProject方法的具体用法?C# ITypeDefinition.GetSourceProject怎么用?C# ITypeDefinition.GetSourceProject使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ITypeDefinition
的用法示例。
在下文中一共展示了ITypeDefinition.GetSourceProject方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: AddAttribute
public static void AddAttribute (ITypeDefinition cls, string name, params object[] parameters)
{
bool isOpen;
string fileName = cls.Region.FileName;
var buffer = TextFileProvider.Instance.GetTextEditorData (fileName, out isOpen);
var attr = new CodeAttributeDeclaration (name);
foreach (var parameter in parameters) {
attr.Arguments.Add (new CodeAttributeArgument (new CodePrimitiveExpression (parameter)));
}
var type = new CodeTypeDeclaration ("temp");
type.CustomAttributes.Add (attr);
var provider = ((DotNetProject)cls.GetSourceProject ()).LanguageBinding.GetCodeDomProvider ();
var sw = new StringWriter ();
provider.GenerateCodeFromType (type, sw, new CodeGeneratorOptions ());
string code = sw.ToString ();
int start = code.IndexOf ('[');
int end = code.LastIndexOf (']');
code = code.Substring (start, end - start + 1) + Environment.NewLine;
int pos = buffer.LocationToOffset (cls.Region.BeginLine, cls.Region.BeginColumn);
code = buffer.GetLineIndent (cls.Region.BeginLine) + code;
buffer.Insert (pos, code);
if (!isOpen) {
File.WriteAllText (fileName, buffer.Text);
buffer.Dispose ();
}
}
示例2: ConvertType
NSObjectTypeInfo ConvertType (TypeSystemService.ProjectContentWrapper dom, ITypeDefinition type)
{
string objcName = null;
bool isModel = false;
bool registeredInDesigner = true;
foreach (var att in type.Attributes) {
var attType = att.AttributeType;
if (attType.Equals (dom.Compilation.LookupType (typeNamespace, registerAttType))) {
if (type.GetProjectContent () != null) {
registeredInDesigner &=
MonoDevelop.DesignerSupport.CodeBehind.IsDesignerFile (att.Region.FileName);
}
//type registered with an explicit type name are up to the user to provide a valid name
var posArgs = att.PositionalArguments;
if (posArgs.Count == 1 || posArgs.Count == 2)
objcName = posArgs[0].ConstantValue as string;
//non-nested types in the root namespace have names accessible from obj-c
else if (string.IsNullOrEmpty (type.Namespace) && type.Name.IndexOf ('.') < 0)
objcName = type.Name;
}
if (attType.Equals (dom.Compilation.LookupType (typeNamespace, modelAttType))) {
isModel = true;
}
}
if (string.IsNullOrEmpty (objcName))
return null;
string baseType = type.DirectBaseTypes.First ().FullName;
if (baseType == "System.Object")
baseType = null;
var info = new NSObjectTypeInfo (objcName, type.FullName, null, baseType, isModel,
type.GetSourceProject () != null, registeredInDesigner);
if (info.IsUserType) {
UpdateTypeMembers (dom, info, type);
info.DefinedIn = type.Parts.Select (p => (string) p.Region.FileName).ToArray ();
}
return info;
}