static private CreateTypeArray ( ISeq seq ) : System.Type[] | ||
seq | ISeq | |
Результат | System.Type[] |
internal static Type[] CreateTypeArray(ISeq seq)
{
List<Type> types = new List<Type>();
for (ISeq s = seq == null ? null : seq.seq(); s != null; s = s.next())
{
Object o = s.first();
Type oAsType = o as Type;
if (oAsType != null )
types.Add(oAsType);
else if (o is ISeq)
{
object first = RT.first(o);
Symbol firstAsSymbol = first as Symbol;
if (firstAsSymbol == null || !firstAsSymbol.Equals(HostExpr.ByRefSym))
throw new ArgumentException("First element of parameter definition is not by-ref");
Type secondAsType = RT.second(o) as Type;
if (secondAsType == null)
throw new ArgumentException("by-ref must be paired with a type");
types.Add(secondAsType.MakeByRefType());
}
else
throw new ArgumentException("Bad parameter definition");
}
if ( types.Count == 0 )
return Type.EmptyTypes;
return types.ToArray<Type>();
}
GenClass::CreateTypeArray ( |
public static Type GenerateInterface(string iName, IPersistentMap attributes, Seqable extends, ISeq methods) { iName = iName.Replace('-', '_'); GenContext context; if (Compiler.IsCompiling) { //string path = (string)Compiler.COMPILE_PATH.deref(); //if (path == null) // throw new Exception("*compile-path* not set"); //context = new GenContext(iName, ".dll", path, CompilerMode.File); context = (GenContext)Compiler.CompilerContextVar.deref(); } else { // TODO: In CLR4, should create a collectible type? context = GenContext.CreateWithExternalAssembly(iName + "_" + RT.nextID(), ".dll", false); } for (ISeq s = RT.seq(extends); s != null; s = s.next()) { object f = s.first(); string name = f as String ?? ((Named)f).getName(); if (name.Contains("-")) { throw new ArgumentException("Interface methods must not contain '-'"); } } Type[] interfaceTypes = GenClass.CreateTypeArray(extends?.seq()); TypeBuilder proxyTB = context.ModuleBuilder.DefineType( iName, TypeAttributes.Interface | TypeAttributes.Public | TypeAttributes.Abstract, null, interfaceTypes); // Should we associate source file info? // See Java committ 8d6fdb, 2015.07.17, related to CLJ-1645 // TODO: part of check on debug info SetCustomAttributes(proxyTB, attributes); DefineMethods(proxyTB, methods); Type t = proxyTB.CreateType(); //if ( Compiler.IsCompiling ) // context.SaveAssembly(); Compiler.RegisterDuplicateType(t); return(t); }