public string GetTypeName(TypeProxy type)
        {
            if (type == null)
            {
                throw new ArgumentNullException("type");
            }

            var contract = GetContract(type);

            if (contract != null)
            {
                if (!String.IsNullOrEmpty(contract.Name))
                {
                    return(contract.Name);
                }
            }

            var tt = ConfigurationForType(type);

            if ((tt != null) && (tt.EffectiveSwiftName != null))
            {
                return(tt.EffectiveSwiftName);
            }

            return(TypeType.MakeSwiftSafeName(type.Name));
        }
示例#2
0
        public void Write(TypeProxy type, SwiftType swiftType)
        {
            if (type == null)
            {
                throw new ArgumentNullException("type");
            }

            if (swiftType == null)
            {
                throw new ArgumentNullException("swiftType");
            }

            var composite = swiftType as SwiftComposite;

            if (composite == null)
            {
                ErrorHandler.Error("Attempting to write non-composite Swift type for .NET type {0}", type.FullName);
                return;
            }

            var writer = GetWriter(type);

            try
            {
                _currentWriter = writer;

                _currentWriter.WriteLine();

                composite.WriteDefinition(this);
            }
            finally
            {
                _currentWriter = null;
            }
        }
示例#3
0
        private SwiftType TranslateGenericParameter(TypeProxy parameterType)
        {
            var swiftType = new SwiftPlaceholder(parameterType.Name);

            _swiftTypes.Add(parameterType, swiftType);

            return(swiftType);
        }
示例#4
0
    public override Type VisitTypeProxy(TypeProxy node) {
      //Contract.Requires(node != null);
      Contract.Ensures(Contract.Result<Type>() != null);
      if (node.ProxyFor != null)
        return base.VisitTypeProxy(node);

      return Instantiate(node, Type.Int);
    }
示例#5
0
        private void ReadType(TypeProxy type, bool forceGoodType = false)
        {
            if (!type.IsEnum && !type.IsClass && !type.IsValueType)
            {
                return;
            }

            if (!forceGoodType && !_typeFilter.IsGoodType(type))
            {
                return;
            }

            var  name      = type.Name;
            var  swiftName = _typeFilter.GetTypeName(type);
            bool ignore    = false;

            if (type.IsEnum)
            {
                EnumType configuredEnum;

                if (_configuredEnums.TryGetValue(name, out configuredEnum))
                {
                    //ignore = configuredEnum.ignoreSpecified && configuredEnum.ignore;

                    //if (!String.IsNullOrEmpty(configuredEnum.rename))
                    //	swiftName = configuredEnum.rename;
                }
            }
            else if (type.IsClass || type.IsValueType)
            {
                ClassType configuredClass;

                if (_configuredClasses.TryGetValue(name, out configuredClass))
                {
                    //ignore = configuredClass.ignoreSpecified && configuredClass.ignore;

                    //if (!String.IsNullOrEmpty(configuredClass.rename))
                    //	swiftName = configuredClass.rename;
                }
            }

            if (!ignore /*&& !_swiftNames.ContainsKey(type)*/)
            {
                //if (_swiftTypes.ContainsKey(swiftName))
                //{
                //	var duplicateTypes = new List<Type> { type }.Union(_swiftNames.Where(kvp => kvp.Value == swiftName).Select(kvp => kvp.Key));

                //	Fatal(DUPLICATE_TYPE_NAME,
                //		"Swift name '{0}' is used by .NET types '{1}'.", swiftName, String.Join("', '", duplicateTypes));
                //}

                //_swiftNames.Add(type, swiftName);
                //_swiftTypes.Add(swiftName, null);

                _types.Add(type);
                _translator.CacheSwiftName(type, swiftName);
            }
        }
 public override Type VisitTypeProxy(TypeProxy node)
 {
     if (node.ProxyFor == null)
     {
         throw new NotImplementedException();
     }
     ReturnResult(Translate(node.ProxyFor));
     return(node);
 }
示例#7
0
        public bool IsGoodType(TypeProxy type)
        {
            if (type == null)
            {
                throw new ArgumentNullException("type");
            }

            return(true);
        }
示例#8
0
        public string GetTypeSummary(TypeProxy type)
        {
            if (type == null)
            {
                throw new ArgumentNullException("type");
            }

            return(GetSummary(type, GetTypeXPath(type)));
        }
示例#9
0
        /// <summary>
        /// 创建当前类型的新实例序列。
        /// </summary>
        /// <param name="type">要创建实例序列的类型。</param>
        /// <param name="count">要创建的实例序列中包含的元素的数量。</param>
        /// <param name="args">创建实例需要的参数。</param>
        /// <returns>返回创建的新实例序列。</returns>
        public static IEnumerable <object> CreateInstances(this Type type, int count, params object[] args)
        {
            if (type == null)
            {
                throw new ArgumentNullException("type");
            }
            var proxy = TypeProxy.GetProxy(type);

            return(proxy.CreateInstances(count, args));
        }
示例#10
0
        /// <summary>
        /// 获取当前类型上指定的静态属性或字段的值。
        /// </summary>
        /// <param name="type">要获取的属性或字段的值的类型。</param>
        /// <param name="name">属性或字段的名称。</param>
        /// <param name="ignoreCase">指定是否忽略属性或字段名称的大小写。</param>
        /// <returns>返回该属性或字段的值。</returns>
        public static object GetValue(this Type type, string name, bool ignoreCase = false)
        {
            if (type == null)
            {
                throw new ArgumentNullException("type");
            }
            var proxy = TypeProxy.GetProxy(type);

            return(proxy.GetValue(null, name, ignoreCase));
        }
示例#11
0
        /// <summary>
        /// 创建当前类型的新实例。
        /// </summary>
        /// <param name="type">要创建实例的类型。</param>
        /// <param name="args">创建实例需要的参数。</param>
        /// <returns>返回创建的新实例。</returns>
        public static object CreateInstance(this Type type, params object[] args)
        {
            if (type == null)
            {
                throw new ArgumentNullException("type");
            }
            var proxy = TypeProxy.GetProxy(type);

            return(proxy.CreateInstance(args));
        }
示例#12
0
        /// <summary>
        /// 设置当前类型上指定的静态属性或字段的值。
        /// </summary>
        /// <param name="type">要设置的属性或字段的值的类型。</param>
        /// <param name="name">属性或字段的名称。</param>
        /// <param name="value">要设置的值。</param>
        /// <param name="ignoreCase">指定是否忽略属性或字段名称的大小写。</param>
        /// <returns>返回该属性或字段的值。</returns>
        public static void SetValue(this Type type, string name, object value, bool ignoreCase = false)
        {
            if (type == null)
            {
                throw new ArgumentNullException("type");
            }
            var proxy = TypeProxy.GetProxy(type);

            proxy.SetValue(null, name, value);
        }
示例#13
0
        /// <summary>
        /// 调用当前类型上指定的静态方法。
        /// </summary>
        /// <param name="type">要调用方法的类型。</param>
        /// <param name="name">方法的名称。</param>
        /// <param name="ignoreCase">指定是否忽略方法名称的大小写。</param>
        /// <param name="args">调用方法时传入的参数。</param>
        /// <returns>返回被调用方法的返回值。</returns>
        public static object Invoke(this Type type, string name, bool ignoreCase, params object[] args)
        {
            if (type == null)
            {
                throw new ArgumentNullException("type");
            }
            var proxy = TypeProxy.GetProxy(type);

            return(proxy.Invoke(null, name, ignoreCase, args));
        }
示例#14
0
        public override Type VisitTypeProxy(TypeProxy node)
        {
            //Contract.Requires(node != null);
            Contract.Ensures(Contract.Result <Type>() != null);
            if (node.ProxyFor != null)
            {
                return(base.VisitTypeProxy(node));
            }

            return(Instantiate(node, Type.Int));
        }
示例#15
0
        private partial bool TryResolveTypeNameAndMark(string typeName, out TypeProxy type)
        {
            // TODO: Implement type name resolution to type symbol

            // Important corner cases:
            //   IL2105 (see it's occurences in the tests) - non-assembly qualified type name which doesn't resolve warns
            //     - will need to figure out what analyzer should do around this.

            type = default;
            return(false);
        }
示例#16
0
        private TypeProxy MakeGenericType(Type templateType, TypeProxy argType)
        {
            if (argType == null)
            {
                throw new ArgumentNullException("argType");
            }

            var templateTypeProxy = new TypeProxy(this.Utils, templateType);

            return(templateTypeProxy.MakeGenericType(argType));
        }
示例#17
0
 public static int ConstIdx(CompiledModule cm, TypeProxy v)
 {
     for (int i = 0; i < cm.constants.Count; ++i)
     {
         var cn = cm.constants[i];
         if (cn.type == ConstType.TPROXY && cn.tproxy.name == v.name)
         {
             return(i);
         }
     }
     throw new Exception("Constant not found: " + v);
 }
示例#18
0
        /// <summary>
        /// создать новый http клиент
        /// </summary>
        /// <returns></returns>
        private HttpClient CreateClient()
        {
            HttpClientHandler httpClientHandler;
            //сначала определем тип прокси
            TypeProxy typeProxy = Service.Storage.Source.GetValue <TypeProxy>("ProxyType");


            if (typeProxy != TypeProxy.Default)
            {
                //определим настройки для прокси
                WebProxy proxy = new WebProxy();

                string proxyHost = Service.Storage.Source.GetValue("ProxyHost").ToString();
                int    proxyPort = Service.Storage.Source.GetValue <int>("ProxyPort");
                proxy.Address               = new Uri($"http://{proxyHost.Trim()}:{proxyPort.ToString()}");
                proxy.BypassProxyOnLocal    = false;
                proxy.UseDefaultCredentials = false;

                /*Credentials = new NetworkCredential(
                 * userName: proxyUserName,
                 * password: proxyPassword)*/

                httpClientHandler = new HttpClientHandler {
                    Proxy = proxy
                };
            }
            else
            {
                httpClientHandler = new HttpClientHandler();
                httpClientHandler.DefaultProxyCredentials = CredentialCache.DefaultCredentials;
            }



            // Omit this part if you don't need to authenticate with the web server:

            /*     if (needServerAuthentication)
             *  {
             *      httpClientHandler.PreAuthenticate = true;
             *      httpClientHandler.UseDefaultCredentials = false;
             *
             *      // *** These creds are given to the web server, not the proxy server ***
             *      httpClientHandler.Credentials = new NetworkCredential(
             *          userName: serverUserName,
             *          password: serverPassword);
             *  }*/

            // Finally, create the HTTP client object
            return(new HttpClient(handler: httpClientHandler, disposeHandler: true)
            {
                Timeout = TimeSpan.FromSeconds(10)
            });
        }
示例#19
0
 public virtual Type VisitTypeProxy(TypeProxy node)
 {
     Contract.Requires(node != null);
     Contract.Ensures(Contract.Result <Type>() != null);
     // if the type proxy is instantiated with some more
     // specific type, we visit the instantiation
     if (node.ProxyFor != null)
     {
         return(cce.NonNull((Type /*!*/)this.Visit(node.ProxyFor)));
     }
     return(this.VisitType(node));
 }
示例#20
0
        private SwiftType TranslateEnum(TypeProxy enumType)
        {
            string name;

            if (!_swiftTypesToNames.TryGetValue(enumType, out name))
            {
                ErrorHandler.Error("Skipping undefined enum '{0}'.", enumType.FullName);

                return(null);
            }

            var swiftEnum = new SwiftEnum(name)
            {
                BriefComment = _documentation.GetTypeSummary(enumType),
            };

            var baseType = enumType.GetEnumUnderlyingType();

            if (baseType != _appDomain.ObjectType)
            {
                var baseSwiftType = TranslateType(baseType);

                if (baseType == null)
                {
                    ErrorHandler.Error("Skipping enum '{0}' because of undefined base class '{1}'.", enumType.FullName, baseType.FullName);

                    return(null);
                }

                swiftEnum.BaseType = baseSwiftType;
            }

            _swiftTypes.Add(enumType, swiftEnum);

            foreach (var value in enumType.GetEnumValues())
            {
                var member          = value.GetMember();
                var swiftValueName  = _filter.GetEnumName(value);
                var underlyingValue = _filter.GetUnderlyingEnumValue(value);

                var swiftValue = new SwiftEnumValue(swiftValueName, underlyingValue)
                {
                    BriefComment = _documentation.GetFieldSummary(member),
                };

                swiftEnum.AddValue(swiftValue);
            }

            return(swiftEnum);
        }
示例#21
0
    public static Type ToType(Type t)
    {
        TypeProxy proxy = t as TypeProxy;

        if (proxy != null && proxy.T == null)
        {
            return(defaultPolyType); //- pick arbitrary type
        }
        if (proxy != null)
        {
            return(ToType(proxy.T));
        }
        return(t);
    }
示例#22
0
    public static Type ToType(Type t)
    {
        TypeProxy proxy = t as TypeProxy;

        if (proxy != null && proxy.T == null)
        {
            Util.Assert(false);      // Dafny appears to be doing sane type resolution now
            return(defaultPolyType); //- pick arbitrary type
        }
        if (proxy != null)
        {
            return(ToType(proxy.T));
        }
        return(t);
    }
示例#23
0
        public static T Deserialize <T>(TypeProxy data)
        {
            string fixedJson;

            if (EnvironmentHelper.RunOnCLR())
            {
                fixedJson = data.SerializedData.Replace("%CORE%", EnvironmentHelper.GetNetCoreVersion());
            }
            else
            {
                fixedJson = data.SerializedData.Replace("%CORE%", "mscorlib");
            }

            return(JsonConvert.DeserializeObject <T>(fixedJson, BridgeSerializerSettings.GetSerializerSettings()));
        }
示例#24
0
        public override void Process(HttpRequest request, HttpResponse response, HttpApplication application)
        {
            object processor = null;

            if (routeMap.TryGetValue(request.Path, out processor))
            {
                if (processor is string)
                {
                    processor = new LoadedScript(processor.ToString());
                    routeMap[request.Path] = processor;
                }
                if (processor is NiL.JS.Core.BaseTypes.Function)
                {
                    (processor as NiL.JS.Core.BaseTypes.Function).Invoke(new NiL.JS.Core.BaseTypes.Array(new object[] { request, response, application }));
                    return;
                }
                else if (processor is LoadedScript)
                {
                    var sc = (processor as LoadedScript).Script;
                    sc.Context.InitField("application").Assign(TypeProxy.Proxy(application));
                    sc.Context.InitField("request").Assign(TypeProxy.Proxy(request));
                    sc.Context.InitField("response").Assign(TypeProxy.Proxy(response));
                    sc.Invoke();
                    return;
                }
            }

            if (defaultScript == null)
            {
                try
                {
                    defaultScript = new LoadedScript(defaultPath);
                }
                catch
                {
                    response.BinaryWrite(System.Text.Encoding.Default.GetBytes(new Http.ErrorPage(Http.ResponseCode.SERVICE_UNAVAILABLE, "Service unavailable.").ToString()));
                    response.StatusCode = (int)Http.ResponseCode.SERVICE_UNAVAILABLE;
                }
            }
            lock (defaultScript)
            {
                var script = defaultScript.Script;
                script.Context.InitField("application").Assign(TypeProxy.Proxy(application));
                script.Context.InitField("request").Assign(TypeProxy.Proxy(request));
                script.Context.InitField("response").Assign(TypeProxy.Proxy(response));
                script.Invoke();
            }
        }
        private TypeType ConfigurationForType(TypeProxy type)
        {
            TypeType tt;

            if (_typesByFullname.TryGetValue(type.FullName, out tt))
            {
                return(tt);
            }

            if (_typesByName.TryGetValue(type.Name, out tt))
            {
                return(tt);
            }

            return(null);
        }
示例#26
0
        private static JSObject loadTemplate(Context context, JSObject args)
        {
            string templateName = args.GetField("0").ToString();
            var    sect         = (WebConfigurationManager.GetSection("templates") as Html.TemplateElementCollection)[templateName];

            templateName = sect.Path ?? templateName;
            templateName = validatePath(templateName);
            string templateText = "";
            var    file         = new FileStream(templateName, FileMode.Open, FileAccess.Read);

            templateText = new StreamReader(file).ReadToEnd();
            file.Close();
            var template = NiL.WBE.Html.HtmlPage.Parse(templateText);

            return(TypeProxy.Proxy(template));
        }
示例#27
0
        private string GetDocumentation(TypeProxy type, string xpathRoot, string subpath)
        {
            var document = GetDocument(type.Assembly);

            if (document != null)
            {
                var node = document.SelectSingleNode(xpathRoot + subpath);

                if (node != null)
                {
                    return(node.InnerText);
                }
            }

            return(null);
        }
示例#28
0
        private SwiftType TranslateArray(TypeProxy arrayType)
        {
            //Console.Out.WriteLine("Translating array {0}", arrayType.FullName);

            var elementType = TranslateType(arrayType.GetElementType());

            if (elementType == null)
            {
                return(null);
            }

            var swiftType = new SwiftArray(elementType);

            _swiftTypes.Add(arrayType, swiftType);

            return(swiftType);
        }
示例#29
0
        private SwiftType TranslateNullable(TypeProxy nullableType, TypeProxy innerType)
        {
            // Nullable<T> gets translated into Optional<T>

            var innerSwiftType = TranslateType(innerType);

            if (innerSwiftType == null)
            {
                return(null);
            }

            var swiftType = new SwiftOptional(innerSwiftType);

            _swiftTypes.Add(nullableType, swiftType);

            return(swiftType);
        }
示例#30
0
        private SwiftType TranslateList(TypeProxy collectionType, TypeProxy elementType)
        {
            // IEnumerable<T> gets translated into [T]

            var elementSwiftType = TranslateType(elementType);

            if (elementSwiftType == null)
            {
                return(null);
            }

            var swiftType = new SwiftArray(elementSwiftType);

            _swiftTypes.Add(collectionType, swiftType);

            return(swiftType);
        }
示例#31
0
        private SwiftType TranslateSet(TypeProxy collectionType, TypeProxy elementType)
        {
            // ISet<T> gets translated into Set<T>

            var elementSwiftType = TranslateType(elementType);

            if (elementSwiftType == null)
            {
                return(null);
            }

            var swiftType = new SwiftSet(elementSwiftType);

            _swiftTypes.Add(collectionType, swiftType);

            return(swiftType);
        }
示例#32
0
 public virtual Type VisitTypeProxy(TypeProxy node) {
   Contract.Requires(node != null);
   Contract.Ensures(Contract.Result<Type>() != null);
   // if the type proxy is instantiated with some more
   // specific type, we visit the instantiation
   if (node.ProxyFor != null)
     return cce.NonNull((Type/*!*/)this.Visit(node.ProxyFor));
   return this.VisitType(node);
 }
示例#33
0
 public override Type VisitTypeProxy(TypeProxy node)
 {
     Contract.Ensures(Contract.Result<Type>() == node);
     // if the type proxy is instantiated with some more
     // specific type, we visit the instantiation
     if (node.ProxyFor != null)
         this.Visit(node.ProxyFor);
     return this.VisitType(node);
 }