本文整理汇总了C#中Stetic.GetObjectBindInfo方法的典型用法代码示例。如果您正苦于以下问题:C# Stetic.GetObjectBindInfo方法的具体用法?C# Stetic.GetObjectBindInfo怎么用?C# Stetic.GetObjectBindInfo使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Stetic
的用法示例。
在下文中一共展示了Stetic.GetObjectBindInfo方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: GenerateSteticCodeStructure
static string GenerateSteticCodeStructure (DotNetProject project, Stetic.ProjectItemInfo item, Stetic.Component component, Stetic.ComponentNameEventArgs args, bool saveToFile, bool overwrite)
{
// Generate a class which contains fields for all bound widgets of the component
string name = item != null ? item.Name : component.Name;
string fileName = GetBuildCodeFileName (project, name);
string ns = "";
int i = name.LastIndexOf ('.');
if (i != -1) {
ns = name.Substring (0, i);
name = name.Substring (i + 1);
}
if (saveToFile && !overwrite && File.Exists (fileName))
return fileName;
if (item != null)
component = item.Component;
CodeCompileUnit cu = new CodeCompileUnit ();
if (project.UsePartialTypes) {
CodeNamespace cns = new CodeNamespace (ns);
cu.Namespaces.Add (cns);
CodeTypeDeclaration type = new CodeTypeDeclaration (name);
type.IsPartial = true;
type.Attributes = MemberAttributes.Public;
type.TypeAttributes = System.Reflection.TypeAttributes.Public;
cns.Types.Add (type);
foreach (Stetic.ObjectBindInfo binfo in component.GetObjectBindInfo ()) {
// When a component is being renamed, we have to generate the
// corresponding field using the old name, since it will be renamed
// later using refactory
string nname = args != null && args.NewName == binfo.Name ? args.OldName : binfo.Name;
type.Members.Add (
new CodeMemberField (
binfo.TypeName,
nname
)
);
}
} else {
if (!saveToFile)
return fileName;
CodeNamespace cns = new CodeNamespace ();
cns.Comments.Add (new CodeCommentStatement ("Generated code for component " + component.Name));
cu.Namespaces.Add (cns);
}
CodeDomProvider provider = project.LanguageBinding.GetCodeDomProvider ();
if (provider == null)
throw new UserException ("Code generation not supported for language: " + project.LanguageName);
TextWriter fileStream;
if (saveToFile)
fileStream = new StreamWriter (fileName);
else
fileStream = new StringWriter ();
try {
var pol = project.Policies.Get<TextStylePolicy> ();
var options = new CodeGeneratorOptions () {
IndentString = pol.TabsToSpaces? new string (' ', pol.TabWidth) : "\t",
BlankLinesBetweenMembers = true,
};
provider.GenerateCodeFromCompileUnit (cu, fileStream, options);
} finally {
fileStream.Close ();
}
if (ProjectDomService.HasDom (project)) {
// Only update the parser database if the project is actually loaded in the IDE.
if (saveToFile) {
ProjectDomService.Parse (project, fileName);
FileService.NotifyFileChanged (fileName);
} else
ProjectDomService.Parse (project, fileName, ((StringWriter)fileStream).ToString ());
}
return fileName;
}