当前位置: 首页>>代码示例>>C#>>正文


C# IContext.Contains方法代码示例

本文整理汇总了C#中IContext.Contains方法的典型用法代码示例。如果您正苦于以下问题:C# IContext.Contains方法的具体用法?C# IContext.Contains怎么用?C# IContext.Contains使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在IContext的用法示例。


在下文中一共展示了IContext.Contains方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: Render

        public override void Render(HttpContextBase httpContext, IContext requestContext)
        {
            if (httpContext.Session != null)
                foreach (object key in httpContext.Session.Keys)
                {
                    if (requestContext.Contains(key))
                        throw new ApplicationException(String.Format("{0} is present on both the Session and the Request.", key));

                    requestContext.Add(key.ToString(), httpContext.Session[key.ToString()]);
                }

            try
            {
                var templateTuple = manager.RenderTemplate(requestContext.Response.RenderTarget, (IDictionary<string, object>)requestContext);
                manager = templateTuple.Item1;
                TextReader reader = templateTuple.Item2;
                char[] buffer = new char[4096];
                int count = 0;
                while ((count = reader.ReadBlock(buffer, 0, 4096)) > 0)
                    httpContext.Response.Write(buffer, 0, count);
            }
            catch (Exception ex)
            {
                httpContext.Response.StatusCode = 500;
                httpContext.Response.Write(RenderException(requestContext.Response.RenderTarget, ex, true));
            }
        }
开发者ID:jijo-paulose,项目名称:bistro-framework,代码行数:27,代码来源:DjangoEngine.cs

示例2: GetControllerInstance

        /// <summary>
		/// Gets the controller instance.
		/// </summary>
		/// <param name="info">The info.</param>
		/// <param name="context">The context.</param>
		/// <param name="requestContext">The request context.</param>
		/// <returns></returns>
		public virtual IController GetControllerInstance(ControllerInvocationInfo info, HttpContextBase context, IContext requestContext)
		{
			IController instance = controllerConstructor.Invoke(EmptyParams) as IController;
			instance.Initialize();

			// the order here matters. we may have something that's both a session field
			// and a request field. want to make sure that it gets set in a consistent fashion

			// also, keep checking for presence of values. this way, if something is
			// marked as more than one scope, and is present in one but not the other,
			// it won't get overriden with a null.

			foreach (string field in info.Parameters.Keys)
				// not all path parameters may be present on the controller
				if (info.BindPoint.ParameterFields.ContainsKey(field))
					SetValue(
						instance, 
						info.BindPoint.ParameterFields[field], 
						info.Parameters[field]);

            if (context != null)
            {
                if (context.Session != null)
                {
                    // asking for a non-existant session value will simply return null
                    ArrayList allSessionFields = new ArrayList(context.Session.Keys);
                    foreach (string sessionField in descriptor.SessionFields.Keys)
                        if (allSessionFields.Contains(sessionField))
                            SetValue(instance, descriptor.SessionFields[sessionField], context.Session[sessionField]);
                }

                //TODO: both the allCookies and allFormFields collections should be computed once per request, not for every controller
                List<string> allCookies = new List<string>(context.Request.Cookies.AllKeys);
                foreach (string cookie in descriptor.CookieFields.Keys)
                    if (allCookies.Contains(cookie))
                        SetValue(instance, descriptor.CookieFields[cookie].Field, context.Request.Cookies[cookie].Value);

                HttpFileCollectionBase files = context.Request.Files;
                foreach (string file in files.AllKeys)
                    if (descriptor.FormFields.ContainsKey(file))
                        SetFileValue(instance, descriptor.FormFields[file], files[file]);

                List<string> allFormFields = new List<string>(context.Request.Form.AllKeys);
                foreach (string formField in descriptor.FormFields.Keys)
                    if (allFormFields.Contains(formField))
                        SetValue(instance, descriptor.FormFields[formField], context.Request.Form[formField]);
            }

			foreach (string requestField in descriptor.RequestFields.Keys)
				if (requestContext.Contains(requestField))
					SetValue(instance, descriptor.RequestFields[requestField], requestContext[requestField]);

            if (mapper != null)
            {
                IMappable mappable = instance as IMappable;
                if (mappable != null)
                    mappable.Mapper = mapper;
            }

			return instance;
		}
开发者ID:jijo-paulose,项目名称:bistro-framework,代码行数:68,代码来源:ControllerHandler.cs

示例3: Parse

        public object Parse(Type type, XObject config, bool isAssignableTypeAllowed, XmlLocation childLocation, IContext context)
        {
            var configElement = config as XElement;
            if (configElement == null)
                throw new TestLibsException($"Couldn't parse type: {type} from following config (element node expected):\n{config}");

            var xmlType = _xmlType.Value;

            string uniqueName = null;
            object createdObject = null;

            if (context != null)
            {
                createdObject = new XmlBaseType();

                var xmlNode = _uniqProperty.Value.Location.Value.GetElement(configElement);
                uniqueName = XmlParser.Parse(_uniqProperty.Value.PropertyType, xmlNode) as string;

                if (uniqueName != null)
                {
                    if (context.Contains(type, uniqueName))
                        return context.ResolveValue(type, uniqueName);
                }
            }

            if (isAssignableTypeAllowed)
            {
                var possibleTypeName = configElement.Name.ToString();
                var assignableXmlTypes = ReflectionManager.GetAssignableTypes(type);

                foreach (var assignableXmlType in assignableXmlTypes)
                {
                    if (assignableXmlType.Location.Check(XmlLocationType.Element, possibleTypeName))
                    {
                        xmlType = assignableXmlType;
                    }
                }

                if (xmlType == _xmlType.Value)
                    throw new TestLibsException($"Couldn't find any type that could be parsed from element with name: {possibleTypeName}\nPossible element names: {assignableXmlTypes.Select(xt => $"Type: {xt.XType}, description: {xt.Description}\n{xt.Location}").ToList().ToStringWithList("=")}");
            }
            else
            {
                xmlType = ReflectionManager.GetXmlType(type);
            }

            var parsedPropertiesDict = new Dictionary<XmlProperty, bool>();
            xmlType.XmlProperties.ForEach(p => parsedPropertiesDict.Add(p, false));

            createdObject = Activator.CreateInstance(xmlType.XType);
            if (uniqueName != null)
            {
                _uniqProperty.Value.SetValue(createdObject, uniqueName);
                parsedPropertiesDict[_uniqProperty.Value] = true;
            }


            var propertyToParse = parsedPropertiesDict.Keys.FirstOrDefault(k => !parsedPropertiesDict[k]);
            while (propertyToParse != null)
            {
                ParseProperty(propertyToParse, configElement, createdObject, parsedPropertiesDict, context);
                propertyToParse = parsedPropertiesDict.Keys.FirstOrDefault(k => !parsedPropertiesDict[k]);
            }

            return createdObject;
        }
开发者ID:IIITanbI,项目名称:1,代码行数:66,代码来源:DefaultQaTypeParser.cs

示例4: ContainsKeys

 /// <summary>
 /// Determine if the context contains each key in keys.
 /// </summary>
 /// <param name="context">Context to process</param>
 /// <param name="keys">Keys to verify</param>
 /// <returns>True if contact contains each key in keys</returns>
 protected bool ContainsKeys(IContext context, string[] keys)
 {
     bool found = true;
     foreach (string key in keys)
     {
         found = found && context.Contains(key);
     }
     return found;
 }
开发者ID:benouarred,项目名称:struts-archive,代码行数:15,代码来源:BaseNexusTest.cs

示例5: LoadRequestFields

 protected virtual void LoadRequestFields(IContext requestContext, IController instance)
 {
     foreach (string requestField in descriptor.RequestFields.Keys)
         if (requestContext.Contains(requestField))
             SetValue(instance, descriptor.RequestFields[requestField], requestContext[requestField]);
 }
开发者ID:jijo-paulose,项目名称:bistro-framework,代码行数:6,代码来源:ControllerHandler.cs


注:本文中的IContext.Contains方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。