private void EmitPrototype(ApiPrototype prototype) { var content = prototype.EmitHtml(this); var fileName = "proto-" + GetClassLink(prototype.Name); EmitPage(fileName, prototype.Name, content); }
static void Main(string[] args) { var assembly = Assembly.LoadFile(GetAssemblyPath()); var apiClasses = ApiClass.GetApiClasses(assembly); var prototypes = ApiPrototype.GetApiPrototypes(assembly).Concat(BuiltInTypes.GetBuiltInPrototypes()).ToArray(); var emitter = new PageEmitter(apiClasses, prototypes); emitter.Emit(); }
public static ApiPrototype[] GetApiPrototypes(Assembly assembly) { // load type var apiMethodSignatureAttributeType = assembly.GetType(TypeHelper.API_METHOD_SIGNATURE_ATTRIBUTE_TYPENAME); // gather var results = new List <ApiPrototype>(); var prototypes = assembly.GetTypes() .Where(t => t.GetCustomAttributes(typeof(ScriptPrototypeAttribute), true).Length > 0); foreach (var prototypeType in prototypes) { var typeDef = prototypeType.GetCustomAttribute <ScriptPrototypeAttribute>(); // prototype name var name = typeDef.VariableName; // construct prototype: var prototype = new ApiPrototype() { Name = name }; // get variables var vars = prototypeType.GetFields(BindingFlags.Public | BindingFlags.Instance) .Where(f => f.GetCustomAttribute <ScriptVariableAttribute>() != null).ToArray(); prototype.Variables = vars.Select(v => new ApiPrototypeVariable { Name = v.Name, Type = TypeHelper.GetTypeName(v.FieldType) }).ToArray(); // get methods var methods = prototypeType.GetMethods(BindingFlags.Public | BindingFlags.Static) .Where(m => m.GetCustomAttributes(typeof(ScriptFunctionAttribute), true).Length > 0).ToArray(); prototype.Methods = methods.Select(m => { var methodDef = m.GetCustomAttribute <ScriptFunctionAttribute>(); return(new ApiMethod { Name = methodDef.VariableName, FunctionType = methodDef.FunctionType, IsStatic = methodDef.IsStatic, Signatures = m.GetCustomAttributes(apiMethodSignatureAttributeType, true).Select(s => { var returnTypes = (Type[])apiMethodSignatureAttributeType.GetProperty("ReturnType").GetValue(s); return new ApiMethodSignature { OptionalNum = (int)apiMethodSignatureAttributeType.GetProperty("OptionalNum").GetValue(s), ParamNames = (string[])apiMethodSignatureAttributeType.GetProperty("ParamNames").GetValue(s), ParamTypes = ((Type[])apiMethodSignatureAttributeType.GetProperty("ParamTypes").GetValue(s)) .Select(pt => TypeHelper.GetTypeName(pt)).ToArray(), ReturnTypes = returnTypes.Select(pt => TypeHelper.GetTypeName(pt, returnTypes.Length)).ToArray() }; }).ToArray() }); }).ToArray(); results.Add(prototype); } return(results.ToArray()); }