Ejemplo n.º 1
0
        public static object Default(object T)
        {
            if (T == JsContext.undefined)
            {
                return(null);
            }


            Type   type   = Typeof(T);
            JsType jsType = type.GetJsType();

            if (jsType != null && jsType != null && (jsType.Kind == JsTypeKind.Struct || (jsType.baseTypeName != null && jsType.baseTypeName.indexOf("ValueType") != -1)))
            {
                switch (type.Name)
                {
                case "Boolean":
                    return(false);

                case "Byte":
                case "Int16":
                case "Int32":
                case "Int64":
                case "Double":
                case "Decimal":
                    return(null);

                default:
                    return(Activator.CreateInstance(jsType.As <Type>()));
                }
            }

            //TODO:
            return(null);
        }
Ejemplo n.º 2
0
 private static void CompileEnum(JsType currentType)
 {
     if (currentType.Kind == JsTypeKind.Enum)
     {
         currentType.tryParse = _EnumTryParse;
         foreach (var p in currentType.staticDefinition)
         {
             if (@typeof(currentType.staticDefinition[p]) == "string")
             {
                 var x = NewByFunc(currentType.ctor);
                 x.As <JsObject>()["_Name"]      = p;
                 currentType.staticDefinition[p] = x;
                 currentType.As <JsObject>()[p]  = x;
             }
         }
     }
 }