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


C# BindingContext类代码示例

本文整理汇总了C#中BindingContext的典型用法代码示例。如果您正苦于以下问题:C# BindingContext类的具体用法?C# BindingContext怎么用?C# BindingContext使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


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

示例1: ConvertArray

        private object ConvertArray(string[] items, Type destinationType, BindingContext context)
        {
            var elementType = destinationType.GetElementType();

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

            var converter = context.TypeConverters.Where(c => c.CanConvertTo(elementType)).FirstOrDefault();

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

            var returnArray = items.Select(s => converter.Convert(s, elementType, context));

            var genericCastMethod = this.enumerableCastMethod.MakeGenericMethod(new[] { elementType });
            var generictoArrayMethod = this.enumerableToArrayMethod.MakeGenericMethod(new[] { elementType });

            var castArray = genericCastMethod.Invoke(null, new object[] { returnArray });

            return generictoArrayMethod.Invoke(null, new[] { castArray });
        }
开发者ID:nathanpalmer,项目名称:Nancy,代码行数:25,代码来源:CollectionConverter.cs

示例2: Deserialize

        /// <summary>
        /// Deserialize the request body to a model
        /// </summary>
        /// <param name="mediaRange">Content type to deserialize</param>
        /// <param name="bodyStream">Request body stream</param>
        /// <param name="context">Current context</param>
        /// <returns>Model instance</returns>
        public object Deserialize(MediaRange mediaRange, Stream bodyStream, BindingContext context)
        {
            var serializer = new JavaScriptSerializer(
                null,
                false,
                this.configuration.MaxJsonLength,
                this.configuration.MaxRecursions,
                this.configuration.RetainCasing,
                this.configuration.UseISO8601DateFormat,
                this.configuration.Converters,
                this.configuration.PrimitiveConverters);

            serializer.RegisterConverters(this.configuration.Converters, this.configuration.PrimitiveConverters);

            bodyStream.Position = 0;
            string bodyText;
            using (var bodyReader = new StreamReader(bodyStream))
            {
                bodyText = bodyReader.ReadToEnd();
            }

            var genericDeserializeMethod = this.deserializeMethod.MakeGenericMethod(context.DestinationType);

            var deserializedObject = genericDeserializeMethod.Invoke(serializer, new object[] { bodyText });

            return deserializedObject;
        }
开发者ID:afwilliams,项目名称:Nancy,代码行数:34,代码来源:JsonBodyDeserializer.cs

示例3: Convert

        /// <summary>
        /// Convert the string representation to the destination type
        /// </summary>
        /// <param name="input">Input string</param>
        /// <param name="destinationType">Destination type</param>
        /// <param name="context">Current context</param>
        /// <returns>Converted object of the destination type</returns>
        public object Convert(string input, Type destinationType, BindingContext context)
        {
            // TODO - Lots of reflection in here, should probably cache the methodinfos
            if (string.IsNullOrEmpty(input))
            {
                return null;
            }

            var items = input.Split(',');

            // Strategy, schmategy ;-)
            if (this.IsCollection(destinationType))
            {
                return this.ConvertCollection(items, destinationType, context);
            }

            if (this.IsArray(destinationType))
            {
                return this.ConvertArray(items, destinationType, context);
            }

            if (this.IsEnumerable(destinationType))
            {
                return this.ConvertEnumerable(items, destinationType, context);
            }

            return null;
        }
开发者ID:nathanpalmer,项目名称:Nancy,代码行数:35,代码来源:CollectionConverter.cs

示例4: Convert

        /// <summary>
        /// Convert the string representation to the destination type
        /// </summary>
        /// <param name="input">Input string</param>
        /// <param name="destinationType">Destination type</param>
        /// <param name="context">Current context</param>
        /// <returns>Converted object of the destination type</returns>
        public object Convert(string input, Type destinationType, BindingContext context)
        {
            if (string.IsNullOrEmpty(input))
            {
                return null;
            }

            var items = input.Split(',');

            // Strategy, schmategy ;-)
            if (destinationType.IsCollection())
            {
                return this.ConvertCollection(items, destinationType, context);
            }

            if (destinationType.IsArray())
            {
                return this.ConvertArray(items, destinationType, context);
            }

            if (destinationType.IsEnumerable())
            {
                return this.ConvertEnumerable(items, destinationType, context);
            }

            return null;
        }
开发者ID:Borzoo,项目名称:Nancy,代码行数:34,代码来源:CollectionConverter.cs

示例5: CreateInstance

 public static CheckedContext CreateInstance(
     BindingContext parentCtx,
     bool checkedNormal,
     bool checkedConstant)
 {
     return new CheckedContext(parentCtx, checkedNormal, checkedConstant);
 }
开发者ID:ChuangYang,项目名称:corefx,代码行数:7,代码来源:BindingContexts.cs

示例6: RabbitMQTransportOutputChannel

        public RabbitMQTransportOutputChannel(BindingContext context, EndpointAddress address, Uri via)
            : base(context, address, via)
        {
            _bindingElement = context.Binding.Elements.Find<RabbitMQTransportBindingElement>();

            MessageEncodingBindingElement encoderElement;

            if (_bindingElement.MessageFormat == MessageFormat.MTOM)
            {
                encoderElement = context.Binding.Elements.Find<MtomMessageEncodingBindingElement>();
            }
            else if (_bindingElement.MessageFormat == MessageFormat.NetBinary)
            {
                encoderElement = context.Binding.Elements.Find<BinaryMessageEncodingBindingElement>();
            }
            else
            {
                encoderElement = context.Binding.Elements.Find<TextMessageEncodingBindingElement>();
            }

            if (encoderElement != null)
            {
                _encoder = encoderElement.CreateMessageEncoderFactory().Encoder;
            }

            _messageProcessor = context.BindingParameters.Find<IFaultMessageProcessor>();
        }
开发者ID:parshim,项目名称:MessageBus,代码行数:27,代码来源:RabbitMQTransportOutputChannel.cs

示例7: UdpDuplexChannel

		// channel factory
		public UdpDuplexChannel (UdpChannelFactory factory, BindingContext ctx, EndpointAddress address, Uri via)
			: base (factory)
		{
			binding_element = factory.Source;
			RemoteAddress = address;
			Via = via;
		}
开发者ID:afaerber,项目名称:mono,代码行数:8,代码来源:UdpDuplexChannel.cs

示例8: BindNamed

        void BindNamed(object commando, PropertyInfo property, List<CommandLineParameter> parameters, NamedArgumentAttribute attribute, BindingContext context)
        {
            var name = attribute.Name;
            var shortHand = attribute.ShortHand;
            var parameter = parameters.Where(p => p is NamedCommandLineParameter)
                .Cast<NamedCommandLineParameter>()
                .SingleOrDefault(p => p.Name == name || p.Name == shortHand);

            var value = parameter != null
                            ? Mutate(parameter, property)
                            : attribute.Default != null
                                  ? Mutate(attribute.Default, property)
                                  : null;

            if (value == null)
            {
                context.Report.PropertiesNotBound.Add(property);

                if (!attribute.Required) return;

                throw Ex("Could not find parameter matching required parameter named {0}", name);
            }

            property.SetValue(commando, value, null);

            context.Report.PropertiesBound.Add(property);
        }
开发者ID:rebus-org,项目名称:GoCommando,代码行数:27,代码来源:Binder.cs

示例9: Deserialize

        /// <summary>
        /// Deserialize the request body to a model
        /// </summary>
        /// <param name="mediaRange">Content type to deserialize</param>
        /// <param name="bodyStream">Request body stream</param>
        /// <param name="context">Current context</param>
        /// <returns>Model instance</returns>
        public object Deserialize(MediaRange mediaRange, Stream bodyStream, BindingContext context)
        {
            if (bodyStream.CanSeek)
            {
                bodyStream.Position = 0;
            }

            var deserializedObject = ServiceStack.JsonSerializer.DeserializeFromStream(context.DestinationType, bodyStream);
            if (deserializedObject == null)
            {
                return null;
            }

            IEnumerable<BindingMemberInfo> properties;
            IEnumerable<BindingMemberInfo> fields;

            if (context.DestinationType.IsGenericType)
            {
                var genericType = context.DestinationType.GetGenericArguments().FirstOrDefault();

                properties = genericType.GetProperties(BindingFlags.Public | BindingFlags.Instance).Select(p => new BindingMemberInfo(p));
                fields = genericType.GetFields(BindingFlags.Public | BindingFlags.Instance).Select(p => new BindingMemberInfo(p));
            }
            else
            {
                properties = context.DestinationType.GetProperties(BindingFlags.Public | BindingFlags.Instance).Select(p => new BindingMemberInfo(p));
                fields = context.DestinationType.GetFields(BindingFlags.Public | BindingFlags.Instance) .Select(p => new BindingMemberInfo(p));
            }

            return properties.Concat(fields).Except(context.ValidModelBindingMembers).Any()
                ? CreateObjectWithBlacklistExcluded(context, deserializedObject)
                : deserializedObject;
        }
开发者ID:NancyFx,项目名称:Nancy.Serialization.ServiceStack,代码行数:40,代码来源:ServiceStackBodyDeserializer.cs

示例10: FillMessageEncoder

		void FillMessageEncoder (BindingContext ctx)
		{
			var mbe = (MessageEncodingBindingElement) ctx.Binding.Elements.FirstOrDefault (be => be is MessageEncodingBindingElement);
			if (mbe == null)
				mbe = new TextMessageEncodingBindingElement ();
			message_encoder = mbe.CreateMessageEncoderFactory ().Encoder;
		}
开发者ID:nickchal,项目名称:pash,代码行数:7,代码来源:UdpDuplexChannel.cs

示例11: Main

	public static void Main ()
	{
		HttpTransportBindingElement el =
			new HttpTransportBindingElement ();
		BindingContext bc = new BindingContext (
			new CustomBinding (),
			new BindingParameterCollection (),
			new Uri ("http://localhost:37564"),
			String.Empty, ListenUriMode.Explicit);
		IChannelListener<IReplyChannel> listener =
			el.BuildChannelListener<IReplyChannel> (bc);

		listener.Open ();

		IReplyChannel reply = listener.AcceptChannel ();

		reply.Open ();

		if (!reply.WaitForRequest (TimeSpan.FromSeconds (10))) {
			Console.WriteLine ("No request reached here.");
			return;
		}
		Console.WriteLine ("Receiving request ...");
		RequestContext ctx = reply.ReceiveRequest ();
		if (ctx == null)
			return;
		Console.WriteLine ("Starting reply ...");
		ctx.Reply (Message.CreateMessage (MessageVersion.Default, "Ack"));
	}
开发者ID:alesliehughes,项目名称:olive,代码行数:29,代码来源:reply.cs

示例12: MsmqIntegrationChannelListener

 internal MsmqIntegrationChannelListener(MsmqBindingElementBase bindingElement, BindingContext context, MsmqReceiveParameters receiveParameters)
     : base(bindingElement, context, receiveParameters, null)
 {
     SetSecurityTokenAuthenticator(MsmqUri.FormatNameAddressTranslator.Scheme, context);
     MsmqIntegrationReceiveParameters parameters = receiveParameters as MsmqIntegrationReceiveParameters;
     xmlSerializerList = XmlSerializer.FromTypes(parameters.TargetSerializationTypes);
 }
开发者ID:nlh774,项目名称:DotNetReferenceSource,代码行数:7,代码来源:MsmqIntegrationChannelListener.cs

示例13: RabbitMQOutputChannelBase

 protected RabbitMQOutputChannelBase(BindingContext context, EndpointAddress address, Uri via)
     : base(context)
 {
     _address = address;
     _via = via;
     _sendMethod = Send;
 }
开发者ID:ronybot,项目名称:MessageBus,代码行数:7,代码来源:RabbitMQOutputChannelBase.cs

示例14: WindowsStreamSecurityUpgradeProvider

        public WindowsStreamSecurityUpgradeProvider(WindowsStreamSecurityBindingElement bindingElement,
            BindingContext context, bool isClient)
            : base(context.Binding)
        {
            _extractGroupsForWindowsAccounts = TransportDefaults.ExtractGroupsForWindowsAccounts;
            _protectionLevel = bindingElement.ProtectionLevel;
            _scheme = context.Binding.Scheme;
            _isClient = isClient;
            _listenUri = TransportSecurityHelpers.GetListenUri(context.ListenUriBaseAddress, context.ListenUriRelativeAddress);

            SecurityCredentialsManager credentialProvider = context.BindingParameters.Find<SecurityCredentialsManager>();

            if (credentialProvider == null)
            {
                if (isClient)
                {
                    credentialProvider = ClientCredentials.CreateDefaultCredentials();
                }
                else
                {
                    throw ExceptionHelper.PlatformNotSupported("WindowsStreamSecurityUpgradeProvider for server is not supported.");
                }
            }

            _securityTokenManager = credentialProvider.CreateSecurityTokenManager();
        }
开发者ID:shijiaxing,项目名称:wcf,代码行数:26,代码来源:WindowsStreamSecurityUpgradeProvider.cs

示例15: WindowsStreamSecurityUpgradeProvider

        public WindowsStreamSecurityUpgradeProvider(WindowsStreamSecurityBindingElement bindingElement,
            BindingContext context, bool isClient)
            : base(context.Binding)
        {
            this.extractGroupsForWindowsAccounts = TransportDefaults.ExtractGroupsForWindowsAccounts;
            this.protectionLevel = bindingElement.ProtectionLevel;
            this.scheme = context.Binding.Scheme;
            this.isClient = isClient;
            this.listenUri = TransportSecurityHelpers.GetListenUri(context.ListenUriBaseAddress, context.ListenUriRelativeAddress);

            SecurityCredentialsManager credentialProvider = context.BindingParameters.Find<SecurityCredentialsManager>();
            if (credentialProvider == null)
            {
                if (isClient)
                {
                    credentialProvider = ClientCredentials.CreateDefaultCredentials();
                }
                else
                {
                    credentialProvider = ServiceCredentials.CreateDefaultCredentials();
                }
            }


            this.securityTokenManager = credentialProvider.CreateSecurityTokenManager();
        }
开发者ID:iskiselev,项目名称:JSIL.NetFramework,代码行数:26,代码来源:WindowsStreamSecurityUpgradeProvider.cs


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