本文整理汇总了C#中Collection.Union方法的典型用法代码示例。如果您正苦于以下问题:C# Collection.Union方法的具体用法?C# Collection.Union怎么用?C# Collection.Union使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Collection
的用法示例。
在下文中一共展示了Collection.Union方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: GetDirections
private void GetDirections()
{
if ((_mainViewModel.DirectionsCriteria.From.IsCurrentLocation || _mainViewModel.DirectionsCriteria.To.IsCurrentLocation) && (_mainViewModel.CurrentLocation == null || _mainViewModel.CurrentLocation.IsUnknown))
{
MessageBox.Show("Your current location is unavailable at the moment. Please try again later.", "No Current Location", MessageBoxButton.OK);
return;
}
GoToDefaultState();
var from = _mainViewModel.DirectionsCriteria.From;
var to = _mainViewModel.DirectionsCriteria.To;
if (from.IsCurrentLocation)
{
from.Location = _mainViewModel.CurrentLocation;
}
if (to.IsCurrentLocation)
{
to.Location = _mainViewModel.CurrentLocation;
}
var origin = from.Location == null ? from.Input : from.Location.ToString();
var destination = to.Location == null ? to.Input : to.Location.ToString();
ProgressBar.IsIndeterminate = true;
GoogleMapsServices.GetDirections(origin, destination, _mainViewModel.DirectionsCriteria.Mode, _mainViewModel.DirectionsCriteria.Method, _mainViewModel.Settings.DistanceUnit,
results =>
{
ProgressBar.IsIndeterminate = false;
if (results == null || results.Legs.Count() == 0 || results.OverviewPolyline == null)
{
MessageBox.Show("There was a problem finding directions for you. Please make sure your \"From\" and \"To\" locations are valid and you are connected to the Internet.", "Unable To Find Directions", MessageBoxButton.OK);
return;
}
var itineraries = new Collection<ItineraryItem>();
var steps = results.Legs.First().Steps;
var polyline = new Collection<Location>();
foreach (var step in steps)
{
itineraries.Add(
new ItineraryItem
{
DistanceString = step.Distance.Text,
Instruction = XmlTagRegex.Replace(DivTagRegex.Replace(step.HtmlInstructions, Environment.NewLine), String.Empty),
Location = step.StartLocation
});
polyline.Union(GoogleMapsServices.DecodePolylinePoints(step.Polyline.Points));
}
itineraries.Add(
new ItineraryItem
{
DistanceString = "End",
Instruction = "Arriving at destination",
Location = steps.Last().EndLocation
});
_mainViewModel.Itineraries = itineraries;
_mainViewModel.RouteLocations = GoogleMapsServices.DecodePolylinePoints(results.OverviewPolyline.Points);
Map.SetView(results.Bounds);
_mainViewModel.EditingUserPin = null;
AppBarMenuItemItinerary.IsEnabled = true;
if (_mainViewModel.DirectionsCriteria.From.IsCurrentLocation)
{
_mainViewModel.DirectionsCriteria.From.Location = null;
}
if (_mainViewModel.DirectionsCriteria.To.IsCurrentLocation)
{
_mainViewModel.DirectionsCriteria.To.Location = null;
}
});
}
示例2: GetFunctionParameters
protected override Collection<ParameterDescriptor> GetFunctionParameters(IFunctionInvoker functionInvoker, FunctionMetadata functionMetadata,
BindingMetadata triggerMetadata, Collection<CustomAttributeBuilder> methodAttributes, Collection<FunctionBinding> inputBindings, Collection<FunctionBinding> outputBindings)
{
if (functionInvoker == null)
{
throw new ArgumentNullException("functionInvoker");
}
if (functionMetadata == null)
{
throw new ArgumentNullException("functionMetadata");
}
if (triggerMetadata == null)
{
throw new ArgumentNullException("triggerMetadata");
}
if (methodAttributes == null)
{
throw new ArgumentNullException("methodAttributes");
}
var csharpInvoker = functionInvoker as CSharpFunctionInvoker;
if (csharpInvoker == null)
{
throw new InvalidOperationException(string.Format(CultureInfo.InvariantCulture, "Expected invoker of type '{0}' but received '{1}'", typeof(CSharpFunctionInvoker).Name, functionInvoker.GetType().Name));
}
try
{
ApplyMethodLevelAttributes(functionMetadata, triggerMetadata, methodAttributes);
MethodInfo functionTarget = csharpInvoker.GetFunctionTargetAsync().Result;
ParameterInfo[] parameters = functionTarget.GetParameters();
Collection<ParameterDescriptor> descriptors = new Collection<ParameterDescriptor>();
IEnumerable<FunctionBinding> bindings = inputBindings.Union(outputBindings);
bool addHttpRequestSystemParameter = false;
foreach (var parameter in parameters)
{
// Is it the trigger parameter?
if (string.Compare(parameter.Name, triggerMetadata.Name, StringComparison.Ordinal) == 0)
{
descriptors.Add(CreateTriggerParameterDescriptor(parameter, triggerMetadata));
if (triggerMetadata.Type == BindingType.HttpTrigger &&
parameter.ParameterType != typeof(HttpRequestMessage))
{
addHttpRequestSystemParameter = true;
}
}
else
{
Type parameterType = parameter.ParameterType;
if (parameterType.IsByRef)
{
parameterType = parameterType.GetElementType();
}
var descriptor = new ParameterDescriptor(parameter.Name, parameter.ParameterType);
var binding = bindings.FirstOrDefault(b => string.Compare(b.Metadata.Name, parameter.Name, StringComparison.Ordinal) == 0);
if (binding != null)
{
Collection<CustomAttributeBuilder> customAttributes = binding.GetCustomAttributes();
if (customAttributes != null)
{
foreach (var customAttribute in customAttributes)
{
descriptor.CustomAttributes.Add(customAttribute);
}
}
}
if (parameter.IsOut)
{
descriptor.Attributes |= ParameterAttributes.Out;
}
descriptors.Add(descriptor);
}
}
// Add any additional common System parameters
// Add ExecutionContext to provide access to InvocationId, etc.
descriptors.Add(new ParameterDescriptor("context", typeof(ExecutionContext)));
// If we have an HTTP trigger binding but we're not binding
// to the HttpRequestMessage, require it as a system parameter
if (addHttpRequestSystemParameter)
{
descriptors.Add(new ParameterDescriptor(ScriptConstants.DefaultSystemTriggerParameterName, typeof(HttpRequestMessage)));
}
return descriptors;
}
catch (AggregateException exc)
{
if (!(exc.InnerException is CompilationErrorException))
{
throw;
}
}
catch (CompilationErrorException)
//.........这里部分代码省略.........
示例3: GetFunctionParameters
protected override Collection<ParameterDescriptor> GetFunctionParameters(IFunctionInvoker functionInvoker, FunctionMetadata functionMetadata,
BindingMetadata triggerMetadata, Collection<CustomAttributeBuilder> methodAttributes, Collection<FunctionBinding> inputBindings, Collection<FunctionBinding> outputBindings)
{
if (functionInvoker == null)
{
throw new ArgumentNullException("functionInvoker");
}
if (functionMetadata == null)
{
throw new ArgumentNullException("functionMetadata");
}
if (triggerMetadata == null)
{
throw new ArgumentNullException("triggerMetadata");
}
if (methodAttributes == null)
{
throw new ArgumentNullException("methodAttributes");
}
var dotNetInvoker = functionInvoker as DotNetFunctionInvoker;
if (dotNetInvoker == null)
{
throw new InvalidOperationException(string.Format(CultureInfo.InvariantCulture, "Expected invoker of type '{0}' but received '{1}'", typeof(DotNetFunctionInvoker).Name, functionInvoker.GetType().Name));
}
try
{
ApplyMethodLevelAttributes(functionMetadata, triggerMetadata, methodAttributes);
MethodInfo functionTarget = dotNetInvoker.GetFunctionTargetAsync().Result;
ParameterInfo[] parameters = functionTarget.GetParameters();
Collection<ParameterDescriptor> descriptors = new Collection<ParameterDescriptor>();
IEnumerable<FunctionBinding> bindings = inputBindings.Union(outputBindings);
ParameterDescriptor descriptor = null;
foreach (var parameter in parameters)
{
// Is it the trigger parameter?
if (string.Compare(parameter.Name, triggerMetadata.Name, StringComparison.Ordinal) == 0)
{
ParameterDescriptor triggerParameter = CreateTriggerParameter(triggerMetadata, parameter.ParameterType);
descriptors.Add(triggerParameter);
}
else
{
Type parameterType = parameter.ParameterType;
bool parameterIsByRef = parameterType.IsByRef;
if (parameterIsByRef)
{
parameterType = parameterType.GetElementType();
}
descriptor = new ParameterDescriptor(parameter.Name, parameter.ParameterType);
var binding = bindings.FirstOrDefault(b => string.Compare(b.Metadata.Name, parameter.Name, StringComparison.Ordinal) == 0);
if (binding != null)
{
Collection<CustomAttributeBuilder> customAttributes = binding.GetCustomAttributes(parameter.ParameterType);
if (customAttributes != null)
{
foreach (var customAttribute in customAttributes)
{
descriptor.CustomAttributes.Add(customAttribute);
}
}
}
// In the C# programming model, IsOut is set for out parameters
// In the F# programming model, neither IsOut nor IsIn are set for byref parameters (which are used as out parameters).
// Justification for this cariation of the programming model is that declaring 'out' parameters is (deliberately)
// awkward in F#, they require opening System.Runtime.InteropServices and adding the [<Out>] attribute, and using
// a byref parameter. In contrast declaring a byref parameter alone (neither labelled In nor Out) is simple enough.
if (parameter.IsOut || (functionMetadata.ScriptType == ScriptType.FSharp && parameterIsByRef && !parameter.IsIn))
{
descriptor.Attributes |= ParameterAttributes.Out;
}
descriptors.Add(descriptor);
}
}
// Add any additional required System parameters (if they haven't already been defined by the user)
if (!descriptors.Any(p => p.Type == typeof(ExecutionContext)))
{
// Add ExecutionContext to provide access to InvocationId, etc.
descriptors.Add(new ParameterDescriptor(ScriptConstants.SystemExecutionContextParameterName, typeof(ExecutionContext)));
}
// If we have an HTTP trigger binding but no parameter binds to the raw HttpRequestMessage,
// add it as a system parameter so it is accessible later in the pipeline.
if (string.Compare(triggerMetadata.Type, "httptrigger", StringComparison.OrdinalIgnoreCase) == 0 &&
!descriptors.Any(p => p.Type == typeof(HttpRequestMessage)))
{
descriptors.Add(new ParameterDescriptor(ScriptConstants.SystemTriggerParameterName, typeof(HttpRequestMessage)));
}
if (TryCreateReturnValueParameterDescriptor(functionTarget.ReturnType, bindings, out descriptor))
{
// If a return value binding has been specified, set up an output
// binding to map it to. By convention, this is set up as the last
// parameter.
//.........这里部分代码省略.........