本文整理汇总了C#中System.Type.Missing字段的典型用法代码示例。如果您正苦于以下问题:C# Type.Missing字段的具体用法?C# Type.Missing怎么用?C# Type.Missing使用的例子?那么恭喜您, 这里精选的字段代码示例或许可以为您提供帮助。您也可以进一步了解该字段所在类System.Type
的用法示例。
在下文中一共展示了Type.Missing字段的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Main
//引入命名空间
using System;
using System.Reflection;
using System.CodeDom.Compiler;
class Example
{
public static void Main()
{
// VB source for example. Not all versions of CS and CPP compilers
// support optional arguments.
string codeLines =
"Imports System\n\n" +
"Public Class OptionalArg\n" +
" Public Sub MyMethod(ByVal a As Integer, _\n" +
" Optional ByVal b As Double = 1.2, _\n" +
" Optional ByVal c As Integer = 1)\n\n" +
" Console.WriteLine(\"a = \" & a & \" b = \" & b & \" c = \" & c)\n" +
" End Sub\n" +
"End Class\n";
// Generate a OptionalArg instance from the source above.
object o = GenerateObjectFromSource("OptionalArg", codeLines, "VisualBasic");
Type t;
t = o.GetType();
BindingFlags bf = BindingFlags.Public | BindingFlags.Instance |
BindingFlags.InvokeMethod | BindingFlags.OptionalParamBinding;
t.InvokeMember("MyMethod", bf, null, o, new object[] {10, 55.3, 12});
t.InvokeMember("MyMethod", bf, null, o, new object[] {10, 1.3, Type.Missing});
t.InvokeMember("MyMethod", bf, null, o, new object[] {10, Type.Missing, Type.Missing});
}
private static object GenerateObjectFromSource(string objectName,
string sourceLines, string providerName)
{
object genObject = null;
CodeDomProvider codeProvider = CodeDomProvider.CreateProvider(providerName);
CompilerParameters cp = new CompilerParameters();
cp.GenerateExecutable = false;
cp.GenerateInMemory = true;
CompilerResults results =
codeProvider.CompileAssemblyFromSource(cp, sourceLines);
if (results.Errors.Count == 0)
{
genObject = results.CompiledAssembly.CreateInstance(objectName);
}
return genObject;
}
}