本文整理汇总了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 });
}
示例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;
}
示例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;
}
示例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;
}
示例5: CreateInstance
public static CheckedContext CreateInstance(
BindingContext parentCtx,
bool checkedNormal,
bool checkedConstant)
{
return new CheckedContext(parentCtx, checkedNormal, checkedConstant);
}
示例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>();
}
示例7: UdpDuplexChannel
// channel factory
public UdpDuplexChannel (UdpChannelFactory factory, BindingContext ctx, EndpointAddress address, Uri via)
: base (factory)
{
binding_element = factory.Source;
RemoteAddress = address;
Via = via;
}
示例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);
}
示例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;
}
示例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;
}
示例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"));
}
示例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);
}
示例13: RabbitMQOutputChannelBase
protected RabbitMQOutputChannelBase(BindingContext context, EndpointAddress address, Uri via)
: base(context)
{
_address = address;
_via = via;
_sendMethod = Send;
}
示例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();
}
示例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();
}