private void RegisterType(CKlaxScriptTypeInfo typeInfo) { Type type = typeInfo.Type; Types.Add(typeInfo); m_klaxTypeMap.Add(typeInfo.Type, typeInfo); foreach (var method in type.GetMethods()) { KlaxFunctionAttribute klaxFunction = method.GetCustomAttribute <KlaxFunctionAttribute>(); if (klaxFunction != null) { MethodInfo baseMethod = method.GetBaseDefinition(); if (baseMethod.DeclaringType == type) { typeInfo.Functions.Add(CreateFunction(klaxFunction, method)); } } } foreach (var property in type.GetProperties()) { KlaxPropertyAttribute klaxProperty = property.GetCustomAttribute <KlaxPropertyAttribute>(); if (klaxProperty != null) { if (property.DeclaringType == type) { typeInfo.Properties.Add(CreateProperty(klaxProperty, property)); } } } foreach (var field in type.GetFields()) { KlaxPropertyAttribute klaxProperty = field.GetCustomAttribute <KlaxPropertyAttribute>(); if (klaxProperty != null) { if (field.DeclaringType == type) { string name = klaxProperty.DisplayName ?? field.Name; typeInfo.Properties.Add(CreateProperty(field, name, klaxProperty.Category, klaxProperty.IsReadOnly)); } } else { KlaxEventAttribute klaxEvent = field.GetCustomAttribute <KlaxEventAttribute>(); if (klaxEvent != null && field.DeclaringType == type) { typeInfo.Events.Add(CreateEvent(field, klaxEvent)); } } } }
private void RegisterAssembly(Assembly assembly) { KlaxAssembly klaxAssembly = assembly.GetCustomAttribute <KlaxAssembly>(); if (klaxAssembly == null) { return; } foreach (TypeInfo type in assembly.DefinedTypes) { KlaxScriptTypeAttribute klaxType = type.GetCustomAttribute <KlaxScriptTypeAttribute>(); if (klaxType != null) { RegisterType(new CKlaxScriptTypeInfo() { Type = type, Color = klaxType.Color.A == 0 ? DEFAULT_TYPE_COLOR : klaxType.Color, Name = klaxType.Name ?? type.Name }); } else { KlaxLibraryAttribute klaxLibrary = type.GetCustomAttribute <KlaxLibraryAttribute>(); if (klaxLibrary != null) { foreach (MethodInfo method in type.GetMethods(BindingFlags.Public | BindingFlags.Static)) { KlaxFunctionAttribute klaxFunc = method.GetCustomAttribute <KlaxFunctionAttribute>(); if (klaxFunc != null) { LibraryFunctions.Add(CreateFunction(klaxFunc, method)); } } } } } }
private CKlaxScriptFunctionInfo CreateFunction(KlaxFunctionAttribute attribute, MethodInfo method) { ParameterInfo[] parameters = method.GetParameters(); CKlaxScriptFunctionInfo info = new CKlaxScriptFunctionInfo { methodInfo = method, displayName = attribute.DisplayName ?? method.Name, category = attribute.Category, tooltip = attribute.Tooltip, inputParameter = parameters.Where(whereInfo => !whereInfo.IsOut).Select(selectInfo => selectInfo.ParameterType).ToArray(), inputParametersDefaultValue = method.GetParameters().Where(whereInfo => !whereInfo.IsOut).Select(selectInfo => (selectInfo.HasDefaultValue ? selectInfo.DefaultValue : null)).ToArray(), bIsImplicit = attribute.IsImplicit, }; info.inputParameterNames = new string[info.inputParameter.Length]; for (int i = 0, length = info.inputParameter.Length; i < length; i++) { string result = parameters[i].Name; switch (i) { case 0: if (attribute.ParameterName1 != null) { result = attribute.ParameterName1; } break; case 1: if (attribute.ParameterName2 != null) { result = attribute.ParameterName2; } break; case 2: if (attribute.ParameterName3 != null) { result = attribute.ParameterName3; } break; case 3: if (attribute.ParameterName4 != null) { result = attribute.ParameterName4; } break; case 4: if (attribute.ParameterName5 != null) { result = attribute.ParameterName5; } break; case 5: if (attribute.ParameterName6 != null) { result = attribute.ParameterName6; } break; case 6: if (attribute.ParameterName7 != null) { result = attribute.ParameterName7; } break; case 7: if (attribute.ParameterName8 != null) { result = attribute.ParameterName8; } break; case 8: if (attribute.ParameterName9 != null) { result = attribute.ParameterName9; } break; case 9: if (attribute.ParameterName10 != null) { result = attribute.ParameterName10; } break; } info.inputParameterNames[i] = result; } m_klaxFunctionMap.Add(method, info); return(info); }