本文整理汇总了C#中Bam.ToArray方法的典型用法代码示例。如果您正苦于以下问题:C# Bam.ToArray方法的具体用法?C# Bam.ToArray怎么用?C# Bam.ToArray使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Bam
的用法示例。
在下文中一共展示了Bam.ToArray方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: SharedSettings
SharedSettings(
System.Collections.Generic.IEnumerable<Bam.Core.Module> objectFiles,
System.Type convertExtensionClassType,
System.Type conversionInterfaceType,
Bam.Core.TypeArray convertParameterTypes)
{
var sharedInterfaces = SharedInterfaces(objectFiles);
var implementedInterfaces = new Bam.Core.TypeArray(sharedInterfaces);
implementedInterfaces.Add(conversionInterfaceType);
// define a new type, that contains just the shared interfaces between all object files
// (any interface not shared, must be cloned later)
var typeSignature = "IDESharedSettings";
var assemblyName = new System.Reflection.AssemblyName(typeSignature);
var assemblyBuilder = System.AppDomain.CurrentDomain.DefineDynamicAssembly(assemblyName, System.Reflection.Emit.AssemblyBuilderAccess.Run);
var moduleBuilder = assemblyBuilder.DefineDynamicModule("MainModule", true);
var sharedSettingsTypeDefn = moduleBuilder.DefineType(typeSignature,
System.Reflection.TypeAttributes.Public |
System.Reflection.TypeAttributes.Class |
System.Reflection.TypeAttributes.AutoClass |
System.Reflection.TypeAttributes.AnsiClass |
System.Reflection.TypeAttributes.BeforeFieldInit |
System.Reflection.TypeAttributes.AutoLayout,
typeof(C.SettingsBase),
implementedInterfaces.ToArray());
// TODO: is this necessary?
#if false
sharedSettingsTypeDefn.DefineDefaultConstructor(
System.Reflection.MethodAttributes.Public | System.Reflection.MethodAttributes.SpecialName | System.Reflection.MethodAttributes.RTSpecialName);
#endif
// implement 'automatic property' setter and getters for each property in each interface
foreach (var i in sharedInterfaces)
{
var properties = i.GetProperties();
foreach (var prop in properties)
{
var dynamicProperty = sharedSettingsTypeDefn.DefineProperty(prop.Name,
System.Reflection.PropertyAttributes.None,
prop.PropertyType,
System.Type.EmptyTypes);
var field = sharedSettingsTypeDefn.DefineField("m" + prop.Name,
prop.PropertyType,
System.Reflection.FieldAttributes.Private);
var methodAttrs = System.Reflection.MethodAttributes.Public |
System.Reflection.MethodAttributes.HideBySig |
System.Reflection.MethodAttributes.Virtual;
if (prop.IsSpecialName)
{
methodAttrs |= System.Reflection.MethodAttributes.SpecialName;
}
var getter = sharedSettingsTypeDefn.DefineMethod("get_" + prop.Name,
methodAttrs,
prop.PropertyType,
System.Type.EmptyTypes);
var setter = sharedSettingsTypeDefn.DefineMethod("set_" + prop.Name,
methodAttrs,
null,
new[] { prop.PropertyType });
var getIL = getter.GetILGenerator();
getIL.Emit(System.Reflection.Emit.OpCodes.Ldarg_0);
getIL.Emit(System.Reflection.Emit.OpCodes.Ldfld, field);
getIL.Emit(System.Reflection.Emit.OpCodes.Ret);
dynamicProperty.SetGetMethod(getter);
var setIL = setter.GetILGenerator();
setIL.Emit(System.Reflection.Emit.OpCodes.Ldarg_0);
setIL.Emit(System.Reflection.Emit.OpCodes.Ldarg_1);
setIL.Emit(System.Reflection.Emit.OpCodes.Stfld, field);
setIL.Emit(System.Reflection.Emit.OpCodes.Ret);
dynamicProperty.SetSetMethod(setter);
}
}
var projectSettingsConvertMethod = sharedSettingsTypeDefn.DefineMethod("Convert",
System.Reflection.MethodAttributes.Public | System.Reflection.MethodAttributes.Final | System.Reflection.MethodAttributes.HideBySig | System.Reflection.MethodAttributes.NewSlot | System.Reflection.MethodAttributes.Virtual,
null,
convertParameterTypes.ToArray());
var convertIL = projectSettingsConvertMethod.GetILGenerator();
foreach (var i in sharedInterfaces)
{
var extConvertParameterTypes = new Bam.Core.TypeArray(i);
extConvertParameterTypes.AddRange(convertParameterTypes);
var methInfo = convertExtensionClassType.GetMethod("Convert", extConvertParameterTypes.ToArray());
if (null == methInfo)
{
throw new Bam.Core.Exception("Unable to locate the function {0}.{1}(this {2})", convertExtensionClassType.FullName, "Convert", i.Name);
}
// TODO: can this be simplified, using the ldarg opcode? a simple loop would suffice
convertIL.Emit(System.Reflection.Emit.OpCodes.Ldarg_0);
if (extConvertParameterTypes.Count > 1)
{
convertIL.Emit(System.Reflection.Emit.OpCodes.Ldarg_1);
}
if (extConvertParameterTypes.Count > 2)
{
convertIL.Emit(System.Reflection.Emit.OpCodes.Ldarg_2);
}
if (extConvertParameterTypes.Count > 3)
{
//.........这里部分代码省略.........