本文整理汇总了C#中DelegateCollection类的典型用法代码示例。如果您正苦于以下问题:C# DelegateCollection类的具体用法?C# DelegateCollection怎么用?C# DelegateCollection使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
DelegateCollection类属于命名空间,在下文中一共展示了DelegateCollection类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: WriteBindings
void WriteBindings(DelegateCollection delegates, FunctionCollection wrappers, EnumCollection enums)
{
Console.WriteLine("Writing bindings to {0}", Settings.OutputPath);
if (!Directory.Exists(Settings.OutputPath))
Directory.CreateDirectory(Settings.OutputPath);
// Hack: Fix 3dfx extension category so it doesn't start with a digit
if (wrappers.ContainsKey("3dfx"))
{
var three_dee_fx = wrappers["3dfx"];
wrappers.Remove("3dfx");
wrappers.Add(DigitPrefix + "3dfx", three_dee_fx);
}
using (var sw = sw_h)
{
WriteLicense(sw);
sw.WriteLine("package {0}.{1};", Settings.OutputNamespace, Settings.GLClass);
sw.WriteLine();
sw.WriteLine("import java.nio.*;");
sw.WriteLine();
WriteDefinitions(sw, enums, wrappers, Type.CSTypes);
sw.Flush();
sw.Close();
}
string output_header = Path.Combine(Settings.OutputPath, OutputFileHeader);
Move(sw_h.File, output_header);
}
示例2: ReadDelegates
public void ReadDelegates(string file, DelegateCollection delegates, string apiname, string apiversions)
{
var specs = new XPathDocument(file);
// The pre-GL4.4 spec format does not distinguish between
// different apinames (it is assumed that different APIs
// are stored in distinct signature.xml files).
// To maintain compatibility, we detect the version of the
// signatures.xml file and ignore apiname if it is version 1.
var specversion = GetSpecVersion(specs);
if (specversion == "1")
{
apiname = null;
}
foreach (var apiversion in apiversions.Split('|'))
{
string xpath_add, xpath_delete;
GetSignaturePaths(apiname, apiversion, out xpath_add, out xpath_delete);
foreach (XPathNavigator nav in specs.CreateNavigator().Select(xpath_delete))
{
foreach (XPathNavigator node in nav.SelectChildren("function", String.Empty))
delegates.Remove(node.GetAttribute("name", String.Empty));
}
foreach (XPathNavigator nav in specs.CreateNavigator().Select(xpath_add))
{
delegates.AddRange(ReadDelegates(nav, apiversion));
}
}
}
示例3: Generator
public Generator(Settings settings, string dirName)
{
if (settings == null)
throw new ArgumentNullException("settings");
if (dirName == null)
dirName = "GL2";
Settings = settings.Clone();
glTypemap = "GL2/gl.tm";
csTypemap = Settings.LanguageTypeMapFile;
enumSpec = Path.Combine(dirName, "signatures.xml");
enumSpecExt = String.Empty;
glSpec = Path.Combine(dirName, "signatures.xml");
glSpecExt = String.Empty;
Settings.OverridesFile = Path.Combine(dirName, "overrides.xml");
Settings.ImportsClass = "Core";
Settings.DelegatesClass = "Delegates";
Settings.OutputClass = "GL";
Delegates = new DelegateCollection();
Enums = new EnumCollection();
Wrappers = new FunctionCollection();
SpecReader = new XmlSpecReader(Settings);
}
示例4: Process
public FunctionCollection Process(DelegateCollection delegates, EnumCollection enums)
{
Console.WriteLine("Processing delegates.");
var nav = new XPathDocument(Overrides).CreateNavigator();
foreach (var d in delegates.Values)
{
var function_override = GetFuncOverride(nav, d);
if (function_override != null) {
string obsolete = function_override.GetAttribute ("obsolete", "");
if (!string.IsNullOrEmpty (obsolete))
d.Obsolete = obsolete;
}
TranslateReturnType(nav, d, enums);
TranslateParameters(nav, d, enums);
}
Console.WriteLine("Generating wrappers.");
var wrappers = CreateWrappers(delegates, enums);
Console.WriteLine("Creating CLS compliant overloads.");
wrappers = CreateCLSCompliantWrappers(wrappers, enums);
Console.WriteLine("Removing non-CLS compliant duplicates.");
return MarkCLSCompliance(wrappers);
}
示例5: Process
public FunctionCollection Process(EnumProcessor enum_processor, DelegateCollection delegates, EnumCollection enums,
string apiname, string apiversion)
{
Console.WriteLine("Processing delegates.");
var nav = new XPathDocument(Overrides).CreateNavigator();
foreach (var version in apiversion.Split('|'))
{
// Translate each delegate:
// 1st using the <replace> elements in overrides.xml
// 2nd using the hardcoded rules in FuncProcessor (e.g. char* -> string)
foreach (var signatures in delegates.Values)
{
foreach (var d in signatures)
{
TranslateExtension(d);
TranslateReturnType(enum_processor, nav, d, enums, apiname, version);
TranslateParameters(enum_processor, nav, d, enums, apiname, version);
TranslateAttributes(nav, d, enums, apiname, version);
}
}
// Create overloads for backwards compatibility,
// by resolving <overload> elements
var overload_list = new List<Delegate>();
foreach (var d in delegates.Values.Select(v => v.First()))
{
var overload_element = GetFuncOverload(nav, d, apiname, apiversion);
if (overload_element != null)
{
var overload = new Delegate(d);
ApplyParameterReplacement(overload, overload_element);
ApplyReturnTypeReplacement(overload, overload_element);
overload_list.Add(overload);
}
}
foreach (var overload in overload_list)
{
delegates.Add(overload);
}
}
Console.WriteLine("Generating convenience overloads.");
delegates.AddRange(CreateConvenienceOverloads(delegates));
Console.WriteLine("Generating wrappers.");
var wrappers = CreateWrappers(delegates, enums);
Console.WriteLine("Generating CLS compliant overloads.");
wrappers = CreateCLSCompliantWrappers(wrappers, enums);
Console.WriteLine("Removing non-CLS compliant duplicates.");
wrappers = MarkCLSCompliance(wrappers);
Console.WriteLine("Removing overloaded delegates.");
RemoveOverloadedDelegates(delegates, wrappers);
return wrappers;
}
示例6: WriteBindings
void WriteBindings(DelegateCollection delegates, FunctionCollection wrappers, EnumCollection enums)
{
Console.WriteLine("Writing bindings to {0}", Settings.OutputPath);
if (!Directory.Exists(Settings.OutputPath))
Directory.CreateDirectory(Settings.OutputPath);
// Hack: Fix 3dfx extension category so it doesn't start with a digit
if (wrappers.ContainsKey("3dfx"))
{
var three_dee_fx = wrappers["3dfx"];
wrappers.Remove("3dfx");
wrappers.Add(DigitPrefix + "3dfx", three_dee_fx);
}
Settings.DefaultOutputNamespace = "OpenTK";
// Enums
using (var sw = sw_h_enums)
{
WriteEnums(sw, enums);
sw.Flush();
sw.Close();
}
// Core definitions
using (var sw = sw_h)
{
WriteDefinitions(sw, enums, wrappers, Type.CSTypes, false);
sw.Flush();
sw.Close();
}
// Compatibility definitions
using (var sw = sw_h_compat)
{
WriteDefinitions(sw, enums, wrappers, Type.CSTypes, true);
sw.Flush();
sw.Close();
}
// Core & compatibility declarations
using (var sw = sw_cpp)
{
WriteDeclarations(sw, wrappers, Type.CSTypes);
sw.Flush();
sw.Close();
}
string output_header = Path.Combine(Settings.OutputPath, OutputFileHeader);
string output_cpp = Path.Combine(Settings.OutputPath, OutputFileCpp);
string output_header_compat = Path.Combine(Settings.OutputPath, OutputFileHeaderCompat);
string output_header_enums = Path.Combine(Settings.OutputPath, OutputFileHeaderEnums);
Move(sw_h.File, output_header);
Move(sw_cpp.File, output_cpp);
Move(sw_h_compat.File, output_header_compat);
Move(sw_h_enums.File, output_header_enums);
}
示例7: ReadDelegates
private DelegateCollection ReadDelegates(XPathNavigator specs)
{
DelegateCollection delegates = new DelegateCollection();
foreach (XPathNavigator node in specs.SelectChildren("function", String.Empty))
{
var name = node.GetAttribute("name", String.Empty);
// Check whether we are adding to an existing delegate or creating a new one.
Delegate d = null;
if (delegates.ContainsKey(name))
{
d = delegates[name];
}
else
{
d = new Delegate();
d.Name = name;
d.Version = node.GetAttribute("version", String.Empty);
d.Category = node.GetAttribute("category", String.Empty);
d.DeprecatedVersion = node.GetAttribute("deprecated", String.Empty);
d.Deprecated = !String.IsNullOrEmpty(d.DeprecatedVersion);
d.Obsolete = node.GetAttribute("obsolete", String.Empty);
}
foreach (XPathNavigator param in node.SelectChildren(XPathNodeType.Element))
{
switch (param.Name)
{
case "returns":
d.ReturnType.CurrentType = param.GetAttribute("type", String.Empty);
break;
case "param":
Parameter p = new Parameter();
p.CurrentType = param.GetAttribute("type", String.Empty);
p.Name = param.GetAttribute("name", String.Empty);
string element_count = param.GetAttribute("elementcount", String.Empty);
if (String.IsNullOrEmpty(element_count))
element_count = param.GetAttribute("count", String.Empty);
if (!String.IsNullOrEmpty(element_count))
p.ElementCount = Int32.Parse(element_count);
p.Flow = Parameter.GetFlowDirection(param.GetAttribute("flow", String.Empty));
d.Parameters.Add(p);
break;
}
}
delegates.Add(d);
}
return delegates;
}
示例8: ReadDelegates
public void ReadDelegates(string file, DelegateCollection delegates)
{
var specs = new XPathDocument(file);
foreach (XPathNavigator nav in specs.CreateNavigator().Select("/signatures/delete"))
{
foreach (XPathNavigator node in nav.SelectChildren("function", String.Empty))
delegates.Remove(node.GetAttribute("name", String.Empty));
}
foreach (XPathNavigator nav in specs.CreateNavigator().Select("/signatures/add"))
{
Utilities.Merge(delegates, ReadDelegates(nav));
}
}
示例9: Process
public FunctionCollection Process(DelegateCollection delegates, EnumCollection enums)
{
Console.WriteLine("Processing delegates.");
var nav = new XPathDocument(Overrides).CreateNavigator();
foreach (var d in delegates.Values)
{
TranslateReturnType(nav, d, enums);
TranslateParameters(nav, d, enums);
}
Console.WriteLine("Generating wrappers.");
var wrappers = CreateWrappers(delegates, enums);
Console.WriteLine("Creating CLS compliant overloads.");
wrappers = CreateCLSCompliantWrappers(wrappers, enums);
Console.WriteLine("Removing non-CLS compliant duplicates.");
return MarkCLSCompliance(wrappers);
}
示例10: Generator
public Generator()
{
if (Settings.Compatibility == Settings.Legacy.Tao)
{
Settings.OutputNamespace = "Tao.OpenGl";
Settings.OutputClass = "Gl";
}
else
{
// Defaults
}
Settings.ImportsFile = "GLCore.cs";
Settings.DelegatesFile = "GLDelegates.cs";
Settings.EnumsFile = "GLEnums.cs";
Settings.WrappersFile = "GL.cs";
Delegates = new DelegateCollection();
Enums = new EnumCollection();
Wrappers = new FunctionCollection();
}
示例11: CreateWrappers
FunctionCollection CreateWrappers(DelegateCollection delegates, EnumCollection enums)
{
var wrappers = new FunctionCollection();
foreach (var d in delegates.Values.SelectMany(v => v))
{
wrappers.AddRange(CreateNormalWrappers(d, enums));
}
if ((Settings.Compatibility & Settings.Legacy.KeepUntypedEnums) != 0)
{
// Generate an "All" overload for every function that takes strongly-typed enums
var overloads = new List<Function>();
foreach (var list in wrappers.Values)
{
overloads.AddRange(list.Where(f => f.Parameters.Any(p => p.IsEnum)).Select(f =>
{
var fnew = new Function(f);
fnew.Obsolete = "Use strongly-typed overload instead";
// Note that we can only overload parameters, not the return type
foreach (var p in fnew.Parameters)
{
if (p.IsEnum)
{
p.CurrentType = Settings.CompleteEnumName;
}
}
return fnew;
}));
}
wrappers.AddRange(overloads);
}
return wrappers;
}
示例12: WriteImports
public virtual void WriteImports(BindStreamWriter sw, DelegateCollection delegates)
{
Trace.WriteLine(String.Format("Writing imports to:\t{0}.{1}.{2}", Settings.OutputNamespace, Settings.OutputClass, Settings.ImportsClass));
sw.WriteLine("#pragma warning disable 3019"); // CLSCompliant attribute
sw.WriteLine("#pragma warning disable 1591"); // Missing doc comments
sw.WriteLine();
sw.WriteLine("partial class {0}", Settings.OutputClass);
sw.WriteLine("{");
sw.Indent();
sw.WriteLine();
sw.WriteLine("internal static partial class {0}", Settings.ImportsClass);
sw.WriteLine("{");
sw.Indent();
//sw.WriteLine("static {0}() {1} {2}", Settings.ImportsClass, "{", "}"); // Disable BeforeFieldInit
sw.WriteLine();
foreach (Delegate d in delegates.Values)
{
sw.WriteLine("[System.Security.SuppressUnmanagedCodeSecurity()]");
sw.WriteLine(
"[System.Runtime.InteropServices.DllImport({0}.Library, EntryPoint = \"{1}{2}\"{3})]",
Settings.OutputClass,
Settings.FunctionPrefix,
d.Name,
d.Name.EndsWith("W") || d.Name.EndsWith("A") ? ", CharSet = CharSet.Auto" : ", ExactSpelling = true"
);
sw.WriteLine("internal extern static {0};", d.DeclarationString());
}
sw.Unindent();
sw.WriteLine("}");
sw.Unindent();
sw.WriteLine("}");
}
示例13: WriteDelegates
public virtual void WriteDelegates(BindStreamWriter sw, DelegateCollection delegates)
{
Trace.WriteLine(String.Format("Writing delegates to:\t{0}.{1}.{2}", Settings.OutputNamespace, Settings.OutputClass, Settings.DelegatesClass));
sw.WriteLine("#pragma warning disable 3019"); // CLSCompliant attribute
sw.WriteLine("#pragma warning disable 1591"); // Missing doc comments
sw.WriteLine();
sw.WriteLine("partial class {0}", Settings.OutputClass);
sw.WriteLine("{");
sw.Indent();
sw.WriteLine("internal static partial class {0}", Settings.DelegatesClass);
sw.WriteLine("{");
sw.Indent();
foreach (Delegate d in delegates.Values)
{
sw.WriteLine("[System.Security.SuppressUnmanagedCodeSecurity()]");
sw.WriteLine("internal {0};", d.ToString());
sw.WriteLine("internal {0}static {1} {2}{1};", // = null
d.Unsafe ? "unsafe " : "",
d.Name,
Settings.FunctionPrefix);
}
sw.Unindent();
sw.WriteLine("}");
sw.Unindent();
sw.WriteLine("}");
}
示例14: WriteBindings
public void WriteBindings(DelegateCollection delegates, FunctionCollection functions, EnumCollection enums)
{
Console.WriteLine("Writing bindings to {0}", Settings.OutputPath);
if (!Directory.Exists(Settings.OutputPath))
Directory.CreateDirectory(Settings.OutputPath);
string temp_enums_file = Path.GetTempFileName();
string temp_delegates_file = Path.GetTempFileName();
string temp_core_file = Path.GetTempFileName();
string temp_wrappers_file = Path.GetTempFileName();
// Enums
using (BindStreamWriter sw = new BindStreamWriter(temp_enums_file))
{
WriteLicense(sw);
sw.WriteLine("using System;");
sw.WriteLine();
if ((Settings.Compatibility & Settings.Legacy.NestedEnums) != Settings.Legacy.None)
{
sw.WriteLine("namespace {0}", Settings.OutputNamespace);
sw.WriteLine("{");
sw.Indent();
sw.WriteLine("static partial class {0}", Settings.OutputClass);
}
else
sw.WriteLine("namespace {0}", Settings.EnumsOutput);
sw.WriteLine("{");
sw.Indent();
WriteEnums(sw, Enum.GLEnums);
sw.Unindent();
if ((Settings.Compatibility & Settings.Legacy.NestedEnums) != Settings.Legacy.None)
{
sw.WriteLine("}");
sw.Unindent();
}
sw.WriteLine("}");
}
// Delegates
using (BindStreamWriter sw = new BindStreamWriter(temp_delegates_file))
{
WriteLicense(sw);
sw.WriteLine("namespace {0}", Settings.OutputNamespace);
sw.WriteLine("{");
sw.Indent();
sw.WriteLine("using System;");
sw.WriteLine("using System.Text;");
sw.WriteLine("using System.Runtime.InteropServices;");
sw.WriteLine("#pragma warning disable 0649");
WriteDelegates(sw, Delegate.Delegates);
sw.Unindent();
sw.WriteLine("}");
}
// Core
using (BindStreamWriter sw = new BindStreamWriter(temp_core_file))
{
WriteLicense(sw);
sw.WriteLine("namespace {0}", Settings.OutputNamespace);
sw.WriteLine("{");
sw.Indent();
//specWriter.WriteTypes(sw, Bind.Structures.Type.CSTypes);
sw.WriteLine("using System;");
sw.WriteLine("using System.Text;");
sw.WriteLine("using System.Runtime.InteropServices;");
WriteImports(sw, Delegate.Delegates);
sw.Unindent();
sw.WriteLine("}");
}
// Wrappers
using (BindStreamWriter sw = new BindStreamWriter(temp_wrappers_file))
{
WriteLicense(sw);
sw.WriteLine("namespace {0}", Settings.OutputNamespace);
sw.WriteLine("{");
sw.Indent();
sw.WriteLine("using System;");
sw.WriteLine("using System.Text;");
sw.WriteLine("using System.Runtime.InteropServices;");
WriteWrappers(sw, Function.Wrappers, Type.CSTypes);
sw.Unindent();
sw.WriteLine("}");
}
string output_enums = Path.Combine(Settings.OutputPath, enumsFile);
//.........这里部分代码省略.........
示例15: ReadDelegates
public virtual DelegateCollection ReadDelegates(StreamReader specFile)
{
Console.WriteLine("Reading function specs.");
DelegateCollection delegates = new DelegateCollection();
XPathDocument function_overrides = new XPathDocument(Path.Combine(Settings.InputPath, functionOverridesFile));
do
{
string line = NextValidLine(specFile);
if (String.IsNullOrEmpty(line))
break;
while (line.Contains("(") && !specFile.EndOfStream)
{
// Get next OpenGL function
Delegate d = new Delegate();
// Get function name:
d.Name = line.Split(Utilities.Separators, StringSplitOptions.RemoveEmptyEntries)[0];
do
{
// Get function parameters and return value
line = specFile.ReadLine();
List<string> words = new List<string>(
line.Replace('\t', ' ').Split(Utilities.Separators, StringSplitOptions.RemoveEmptyEntries)
);
if (words.Count == 0)
break;
// Identify line:
switch (words[0])
{
case "return": // Line denotes return value
d.ReturnType.CurrentType = words[1];
break;
case "param": // Line denotes parameter
Parameter p = new Parameter();
p.Name = Utilities.Keywords.Contains(words[1]) ? "@" + words[1] : words[1];
p.CurrentType = words[2];
p.Pointer += words[4].Contains("array") ? 1 : 0;
p.Pointer += words[4].Contains("reference") ? 1 : 0;
if (p.Pointer != 0 && words.Count > 5 && words[5].Contains("[1]"))
p.ElementCount = 1;
p.Flow = words[3] == "in" ? FlowDirection.In : FlowDirection.Out;
d.Parameters.Add(p);
break;
// GetTexParameterIivEXT and GetTexParameterIuivEXT define two(!) versions (why?)
case "version": // Line denotes function version (i.e. 1.0, 1.2, 1.5)
d.Version = words[1];
break;
case "category":
d.Category = words[1];
break;
}
}
while (!specFile.EndOfStream);
d.Translate(function_overrides);
delegates.Add(d);
}
}
while (!specFile.EndOfStream);
return delegates;
}