Ejemplo n.º 1
0
    public static GtFunc LoadNativeField(GtParserContext Context, GtType ClassType, String FieldName, Boolean GetSetter)
    {
        //GtParserContext Context = ClassType.Context;
        try
        {
            Type NativeClass = (Type)ClassType.TypeBody;
            FieldInfo NativeField = NativeClass.GetField(FieldName);
            if (NativeField.IsPublic)
            {
                var GtFieldType = GetNativeType(NativeField.GetType());

                var GetterNativeFunc = new GtFunc(GreenTeaConsts.GetterFunc, FieldName, 0, new List<GtType>() { GtFieldType, ClassType });
                GetterNativeFunc.SetNativeMethod(0, NativeField);
                Context.RootNameSpace.SetGetterFunc(ClassType, FieldName, GetterNativeFunc, null);

                var SetterNativeFunc = new GtFunc(GreenTeaConsts.SetterFunc, FieldName, 0, new List<GtType>() { GtStaticTable.VoidType, ClassType, GtFieldType });
                SetterNativeFunc.SetNativeMethod(0, NativeField);
                Context.RootNameSpace.SetSetterFunc(ClassType, FieldName, SetterNativeFunc, null);

                return GetSetter ? SetterNativeFunc : GetterNativeFunc;
            }
        }
        catch (System.Security.SecurityException e)
        {
            LibGreenTea.VerboseException(e);
        }
        catch (MissingFieldException)
        {
        }
        Context.RootNameSpace.SetUndefinedSymbol(GreenTeaUtils.ClassSymbol(ClassType, GreenTeaUtils.GetterSymbol(FieldName)), null);
        Context.RootNameSpace.SetUndefinedSymbol(GreenTeaUtils.ClassSymbol(ClassType, GreenTeaUtils.SetterSymbol(FieldName)), null); // for setter
        return null;
    }
Ejemplo n.º 2
0
 public static void LoadNativeConstructors(GtParserContext Context, GtType ClassType, List<GtFunc> FuncList)
 {
     var NativeClass = (Type)ClassType.TypeBody;
     var GtConstructors = NativeClass.GetConstructors().Where(c => c.IsPublic).Select(c =>
     {
         var TypeList = new List<GtType>() { ClassType };
         TypeList.AddRange(c.GetParameters().Select(p => LibNative.GetNativeType(p.ParameterType)));
         var Func = new GtFunc(GreenTeaConsts.ConstructorFunc, ClassType.ShortName, 0, TypeList);
         Func.SetNativeMethod(0, c);
         Context.RootNameSpace.AppendConstructor(ClassType, Func, null);
         return Func;
     }).ToList();
     FuncList.AddRange(GtConstructors);
     if (GtConstructors.Count == 0)
     {
         Context.RootNameSpace.SetUndefinedSymbol(GreenTeaUtils.ClassSymbol(ClassType, GreenTeaUtils.ConstructorSymbol()), null);
     }
 }