Esempio n. 1
0
        Type CreateType(ModuleBuilder modBuilder, MetaMethodInfo mmi)
        {
            var mi = mmi.GetMethodInfo();

            if (mi == null)
            {
                // Debug.LogWarning($"Skipping {mmi.niceName}, no longer exists.");
                return(null);
            }
            var className = mmi.className;
            // Debug.Log("Creating Class: " + className);
            var typeBuilder   = modBuilder.DefineType(className, TypeAttributes.Public);
            var classCtorInfo = typeof(UniventGeneratedClassAttribute).GetConstructor(Type.EmptyTypes);
            var caBuilder     = new CustomAttributeBuilder(classCtorInfo, new object[] { });

            typeBuilder.SetCustomAttribute(caBuilder);
            if (mi.ReturnType == typeof(void))
            {
                typeBuilder.AddInterfaceImplementation(typeof(IEncapsulatedAction));
                CreateMethod(mi, typeBuilder);
            }
            else
            {
                var itype = typeof(IEncapsulatedFunction <>).MakeGenericType(mi.ReturnType);
                typeBuilder.AddInterfaceImplementation(itype);
                CreateFunction(mi, typeBuilder, itype);
            }
            return(typeBuilder.CreateType());
        }
Esempio n. 2
0
        public void AddMethod(Type type, MethodInfo mi, bool compile = true)
        {
            var className = ClassRegister.GetClassName(type, mi);

            if (methods.ContainsKey(className))
            {
                return;
            }
            var mmi = new MetaMethodInfo();

            mmi.name               = mi.Name;
            mmi.className          = className;
            mmi.niceName           = ClassRegister.GetNiceName(type, mi);
            mmi.parameterTypeNames = ClassRegister.GetParameterTypeNames(mi);
            mmi.type               = mi.DeclaringType.AssemblyQualifiedName;
            mmi.returnType         = mi.ReturnType.AssemblyQualifiedName;
            methods.Add(className, mmi);
            EditorUtility.SetDirty(this);
            if (compile)
            {
                Compile();
            }
        }