本文整理汇总了C#中ReadOnlyCollection.FirstOrDefault方法的典型用法代码示例。如果您正苦于以下问题:C# ReadOnlyCollection.FirstOrDefault方法的具体用法?C# ReadOnlyCollection.FirstOrDefault怎么用?C# ReadOnlyCollection.FirstOrDefault使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ReadOnlyCollection
的用法示例。
在下文中一共展示了ReadOnlyCollection.FirstOrDefault方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: AssemblyLocator
static AssemblyLocator()
{
AllAssemblies = new ReadOnlyCollection<Assembly>(
BuildManager.GetReferencedAssemblies().Cast<Assembly>().ToList());
IList<Assembly> binFolderAssemblies = new List<Assembly>();
string binFolder = HttpRuntime.AppDomainAppPath + "bin\\";
IList<string> dllFiles = Directory.GetFiles(binFolder, "*.dll",
SearchOption.TopDirectoryOnly).ToList();
foreach (string dllFile in dllFiles)
{
AssemblyName assemblyName = AssemblyName.GetAssemblyName(dllFile);
Assembly locatedAssembly = AllAssemblies.FirstOrDefault(a =>
AssemblyName.ReferenceMatchesDefinition(a.GetName(), assemblyName));
if (locatedAssembly != null)
{
binFolderAssemblies.Add(locatedAssembly);
}
}
BinFolderAssemblies = new ReadOnlyCollection<Assembly>(binFolderAssemblies);
}
示例2: RegisteredQualifier
public RegisteredQualifier(RegisteredCommand command, IEnumerable<string> names, string help)
: base(command, help)
{
_names = new ReadOnlyCollection<string>(names.ToArray());
var firstLongName = _names.FirstOrDefault(n => n.Length > 1);
var firstName = _names.First();
_name = firstLongName ?? firstName;
}
示例3: Initialize
private async void Initialize()
{
if (await _accountService.VerifyUserAuthenticationAsync() == null)
{
return;
}
// Populate ShippingAddress collection
var shippingAddresses = (await _checkoutDataRepository.GetAllShippingAddressesAsync()).Select(address => CreateCheckoutData(address, Constants.ShippingAddress));
ShippingAddresses = new ReadOnlyCollection<CheckoutDataViewModel>(shippingAddresses.ToList());
if (ShippingAddresses != null)
{
var defaultShippingAddress = await _checkoutDataRepository.GetDefaultShippingAddressAsync();
var selectedShippingAddress = defaultShippingAddress != null ? ShippingAddresses.FirstOrDefault(s => s.EntityId == defaultShippingAddress.Id) : null;
SetProperty(ref _selectedShippingAddress, selectedShippingAddress, "SelectedShippingAddress");
}
// Populate BillingAddress collection
var billingAddresses = (await _checkoutDataRepository.GetAllBillingAddressesAsync()).Select(address => CreateCheckoutData(address, Constants.BillingAddress));
BillingAddresses = new ReadOnlyCollection<CheckoutDataViewModel>(billingAddresses.ToList());
if (BillingAddresses != null)
{
var defaultBillingAddress = await _checkoutDataRepository.GetDefaultBillingAddressAsync();
var selectedBillingAddress = defaultBillingAddress != null ? BillingAddresses.FirstOrDefault(s => s.EntityId == defaultBillingAddress.Id) : null;
SetProperty(ref _selectedBillingAddress, selectedBillingAddress, "SelectedBillingAddress");
}
// Populate PaymentMethod collection
var paymentMethods = (await _checkoutDataRepository.GetAllPaymentMethodsAsync()).Select(CreateCheckoutData);
PaymentMethods = new ReadOnlyCollection<CheckoutDataViewModel>(paymentMethods.ToList());
if (PaymentMethods != null)
{
var defaultPaymentMethod = await _checkoutDataRepository.GetDefaultPaymentMethodAsync();
var selectedPaymentMethod = defaultPaymentMethod != null ? PaymentMethods.FirstOrDefault(s => s.EntityId == defaultPaymentMethod.Id) : null;
SetProperty(ref _selectedPaymentMethod, selectedPaymentMethod, "SelectedPaymentMethod");
}
}
示例4: AssemblyLocator
static AssemblyLocator()
{
if (!string.IsNullOrEmpty(HttpRuntime.AppDomainId))
{
try
{
AllAssemblies = new ReadOnlyCollection<Assembly>(BuildManager.GetReferencedAssemblies().Cast<Assembly>().ToList());
}
catch //fallback to appdomain way
{
AllAssemblies = new ReadOnlyCollection<Assembly>(AppDomain.CurrentDomain.GetAssemblies().ToList());
}
IList<Assembly> binFolderAssemblies = new List<Assembly>();
string binFolder = HttpRuntime.BinDirectory;
IList<string> dllFiles = Directory.GetFiles(binFolder, "*.dll", SearchOption.TopDirectoryOnly).ToList();
foreach (string dllFile in dllFiles)
{
AssemblyName assemblyName = AssemblyName.GetAssemblyName(dllFile);
Assembly locatedAssembly = AllAssemblies.FirstOrDefault(a => AssemblyName.ReferenceMatchesDefinition(a.GetName(), assemblyName));
if (locatedAssembly != null)
{
binFolderAssemblies.Add(locatedAssembly);
}
}
BinFolderAssemblies = new ReadOnlyCollection<Assembly>(binFolderAssemblies);
}
else
{
//fake it so it works in unit tests
AllAssemblies = new ReadOnlyCollection<Assembly>(AppDomain.CurrentDomain.GetAssemblies().Cast<Assembly>().ToList());
List<Assembly> binFolderAssemblies = new List<Assembly>(AllAssemblies);
BinFolderAssemblies = new ReadOnlyCollection<Assembly>(binFolderAssemblies);
}
}
示例5: Open
public async void Open(object parameter, Action successAction)
{
// Populate ShippingAddress collection
var shippingAddresses = _checkoutDataRepository.GetAllShippingAddresses().Select(address => CreateCheckoutData(address, Constants.ShippingAddress));
ShippingAddresses = new ReadOnlyCollection<CheckoutDataViewModel>(shippingAddresses.ToList());
if (ShippingAddresses != null)
{
var defaultShippingAddress = _checkoutDataRepository.GetDefaultShippingAddress();
var selectedShippingAddress = defaultShippingAddress != null ? ShippingAddresses.FirstOrDefault(s => s.EntityId == defaultShippingAddress.Id) : null;
SetProperty(ref _selectedShippingAddress, selectedShippingAddress);
}
// Populate BillingAddress collection
var billingAddresses = _checkoutDataRepository.GetAllBillingAddresses().Select(address => CreateCheckoutData(address, Constants.BillingAddress));
BillingAddresses = new ReadOnlyCollection<CheckoutDataViewModel>(billingAddresses.ToList());
if (BillingAddresses != null)
{
var defaultBillingAddress = _checkoutDataRepository.GetDefaultBillingAddress();
var selectedBillingAddress = defaultBillingAddress != null ? BillingAddresses.FirstOrDefault(s => s.EntityId == defaultBillingAddress.Id) : null;
SetProperty(ref _selectedBillingAddress, selectedBillingAddress);
}
// Populate PaymentMethod collection
var paymentMethods = (await _checkoutDataRepository.GetAllPaymentMethodsAsync()).Select(payment => CreateCheckoutData(payment));
PaymentMethods = new ReadOnlyCollection<CheckoutDataViewModel>(paymentMethods.ToList());
if (PaymentMethods != null)
{
var defaultPaymentMethod = await _checkoutDataRepository.GetDefaultPaymentMethodAsync();
var selectedPaymentMethod = defaultPaymentMethod != null ? PaymentMethods.FirstOrDefault(s => s.EntityId == defaultPaymentMethod.Id) : null;
SetProperty(ref _selectedPaymentMethod, selectedPaymentMethod);
}
}
示例6: SelectCheckoutDataAsync
private async Task SelectCheckoutDataAsync()
{
var selectedData = SelectedCheckoutData;
IEnumerable<CheckoutDataViewModel> checkoutData = null;
switch (selectedData.DataType)
{
case Constants.ShippingAddress:
checkoutData = _checkoutDataRepository.GetAllShippingAddresses().Select(address => CreateCheckoutData(address, Constants.ShippingAddress));
AllCheckoutDataViewModels = new ReadOnlyCollection<CheckoutDataViewModel>(checkoutData.ToList());
SelectCheckoutDataLabel = string.Format(CultureInfo.CurrentUICulture, _resourceLoader.GetString("SelectCheckoutData"), _resourceLoader.GetString("ShippingAddress"));
break;
case Constants.BillingAddress:
checkoutData = _checkoutDataRepository.GetAllBillingAddresses().Select(address => CreateCheckoutData(address, Constants.BillingAddress));
AllCheckoutDataViewModels = new ReadOnlyCollection<CheckoutDataViewModel>(checkoutData.ToList());
SelectCheckoutDataLabel = string.Format(CultureInfo.CurrentUICulture, _resourceLoader.GetString("SelectCheckoutData"), _resourceLoader.GetString("BillingAddress"));
break;
case Constants.PaymentMethod:
checkoutData = (await _checkoutDataRepository.GetAllPaymentMethodsAsync()).Select(paymentMethod => CreateCheckoutData(paymentMethod));
AllCheckoutDataViewModels = new ReadOnlyCollection<CheckoutDataViewModel>(checkoutData.ToList());
SelectCheckoutDataLabel = string.Format(CultureInfo.CurrentUICulture, _resourceLoader.GetString("SelectCheckoutData"), _resourceLoader.GetString("PaymentMethod"));
break;
}
if (AllCheckoutDataViewModels != null)
{
IsSelectCheckoutDataPopupOpened = true;
// Select the order's CheckoutData
SelectedAllCheckoutData = AllCheckoutDataViewModels.FirstOrDefault(c => c.EntityId == SelectedCheckoutData.EntityId);
}
}
示例7: OnNavigatedTo
public override async void OnNavigatedTo(object navigationParameter, NavigationMode navigationMode, Dictionary<string, object> viewState)
{
//Get latest shopping cart
var shoppingCart = await _shoppingCartRepository.GetShoppingCartAsync();
_order = _orderRepository.GetCurrentOrder();
_order.ShoppingCart = shoppingCart;
// Populate the ShoppingCart items
var shoppingCartItemVMs = _order.ShoppingCart.ShoppingCartItems.Select(item => new ShoppingCartItemViewModel(item));
ShoppingCartItemViewModels = new ReadOnlyCollection<ShoppingCartItemViewModel>(shoppingCartItemVMs.ToList());
// Populate the ShippingMethods and set the selected one
var shippingMethods = await _shippingMethodService.GetShippingMethodsAsync();
ShippingMethods = new ReadOnlyCollection<ShippingMethod>(shippingMethods.ToList());
SelectedShippingMethod = _order.ShippingMethod != null ? ShippingMethods.FirstOrDefault(c => c.Id == _order.ShippingMethod.Id) : null;
// Populate the CheckoutData items (Addresses & payment information)
CheckoutDataViewModels = new ObservableCollection<CheckoutDataViewModel>
{
CreateCheckoutData(_order.ShippingAddress, Constants.ShippingAddress),
CreateCheckoutData(_order.BillingAddress, Constants.BillingAddress),
CreateCheckoutData(_order.PaymentMethod)
};
if (navigationMode == NavigationMode.Refresh)
{
// Restore the selected CheckoutData manually
string selectedCheckoutData = RetrieveEntityStateValue<string>("selectedCheckoutData", viewState);
if (!string.IsNullOrWhiteSpace(selectedCheckoutData))
{
SelectedCheckoutData = CheckoutDataViewModels.FirstOrDefault(c => c.EntityId == selectedCheckoutData);
}
}
base.OnNavigatedTo(navigationParameter, navigationMode, viewState);
}
示例8: TypeNode
//.........这里部分代码省略.........
if (IsIgnored)
return;
var fieldOrderAttribute = attributes.OfType<FieldOrderAttribute>().SingleOrDefault();
if (fieldOrderAttribute != null)
_order = fieldOrderAttribute.Order;
var serializeAsAttribute = attributes.OfType<SerializeAsAttribute>().SingleOrDefault();
if (serializeAsAttribute != null)
{
_serializedType = serializeAsAttribute.SerializedType;
Endianness = serializeAsAttribute.Endianness;
if (!String.IsNullOrEmpty(serializeAsAttribute.Encoding))
Encoding = Encoding.GetEncoding(serializeAsAttribute.Encoding);
}
FieldLengthAttribute = attributes.OfType<FieldLengthAttribute>().SingleOrDefault();
if (FieldLengthAttribute != null)
{
FieldLengthBinding = new Binding(FieldLengthAttribute, GetBindingLevel(FieldLengthAttribute.Binding));
}
FieldCountAttribute = attributes.OfType<FieldCountAttribute>().SingleOrDefault();
if (FieldCountAttribute != null)
{
FieldCountBinding = new Binding(FieldCountAttribute, FindAncestorLevel(FieldCountAttribute.Binding));
}
FieldOffsetAttribute = attributes.OfType<FieldOffsetAttribute>().SingleOrDefault();
if (FieldOffsetAttribute != null)
{
FieldOffsetBinding = new Binding(FieldOffsetAttribute, GetBindingLevel(FieldOffsetAttribute.Binding));
}
var serializeWhenAttributes = attributes.OfType<SerializeWhenAttribute>().ToArray();
SerializeWhenAttributes = new ReadOnlyCollection<SerializeWhenAttribute>(serializeWhenAttributes);
if (SerializeWhenAttributes.Count > 0)
{
SerializeWhenBindings = new ReadOnlyCollection<ConditionalBinding>(
serializeWhenAttributes.Select(
attribute => new ConditionalBinding(attribute, GetBindingLevel(attribute.Binding))).ToList());
}
var subtypeAttributes = attributes.OfType<SubtypeAttribute>().ToArray();
SubtypeAttributes = new ReadOnlyCollection<SubtypeAttribute>(subtypeAttributes);
if (SubtypeAttributes.Count > 0)
{
var bindingGroups =
SubtypeAttributes.GroupBy(subtypeAttribute => subtypeAttribute.Binding);
if (bindingGroups.Count() > 1)
throw new BindingException("Subtypes must all use the same binding configuration.");
var firstBinding = SubtypeAttributes[0];
SubtypeBinding = new Binding(firstBinding, GetBindingLevel(firstBinding.Binding));
var valueGroups = SubtypeAttributes.GroupBy(attribute => attribute.Value);
if (valueGroups.Count() < SubtypeAttributes.Count)
throw new InvalidOperationException("Subtype values must be unique.");
if (SubtypeBinding.BindingMode == BindingMode.TwoWay)
{
var subTypeGroups = SubtypeAttributes.GroupBy(attribute => attribute.Subtype);
if (subTypeGroups.Count() < SubtypeAttributes.Count)
throw new InvalidOperationException(
"Subtypes must be unique for two-way subtype bindings. Set BindingMode to OneWay to disable updates to the binding source during serialization.");
}
var invalidSubtype =
SubtypeAttributes.FirstOrDefault(attribute => !Type.IsAssignableFrom(attribute.Subtype));
if (invalidSubtype != null)
throw new InvalidOperationException(String.Format("{0} is not a subtype of {1}",
invalidSubtype.Subtype, Type));
}
SerializeUntilAttribute = attributes.OfType<SerializeUntilAttribute>().SingleOrDefault();
if (SerializeUntilAttribute != null)
{
SerializeUntilBinding = new Binding(SerializeUntilAttribute,
GetBindingLevel(SerializeUntilAttribute.Binding));
}
ItemLengthAttribute = attributes.OfType<ItemLengthAttribute>().SingleOrDefault();
if (ItemLengthAttribute != null)
{
ItemLengthBinding = new Binding(ItemLengthAttribute, GetBindingLevel(ItemLengthAttribute.Binding));
}
ItemSerializeUntilAttribute = attributes.OfType<ItemSerializeUntilAttribute>().SingleOrDefault();
if (ItemSerializeUntilAttribute != null)
{
ItemSerializeUntilBinding = new Binding(ItemSerializeUntilAttribute,
GetBindingLevel(ItemSerializeUntilAttribute.Binding));
}
}
示例9: InitCasinoButtons
private void InitCasinoButtons()
{
//Buttons
_CasinoButtons = new List<CasinoButtonViewModel>()
{
new CasinoButtonViewModel { Kind = RouletteButtonKind.Turn, Name = "Turn"},
new CasinoButtonViewModel { Kind = RouletteButtonKind.RemoveBets, Name = "Remove Bets"},
new CasinoButtonViewModel { Kind = RouletteButtonKind.Black, Name = "Black"},
new CasinoButtonViewModel { Kind = RouletteButtonKind.Red, Name = "Red"},
new CasinoButtonViewModel { Kind = RouletteButtonKind.Odd, Name = "Odd"},
new CasinoButtonViewModel { Kind = RouletteButtonKind.Even, Name = "Even"},
new CasinoButtonViewModel { Kind = RouletteButtonKind.To18, Name = "1 To 18"},
new CasinoButtonViewModel { Kind = RouletteButtonKind.From19, Name = "19 To 36"},
new CasinoButtonViewModel { Kind = RouletteButtonKind.RefreshPosition, Name = "Refresh Position", IsPositionAbsolute = true},
};
CasinoButtons = new ReadOnlyCollection<CasinoButtonViewModel>(_CasinoButtons);
//Numbers
_CasinoNumbers = new List<CasinoNumberViewModel>();
CasinoNumbers = new ReadOnlyCollection<CasinoNumberViewModel>(_CasinoNumbers);
for (int i = 0; i <= 36; i++)
_CasinoNumbers.Add(new CasinoNumberViewModel { Number = i });
//Bets
_CasinoBets = new List<CasinoBetButtonViewModel>()
{
new CasinoBetButtonViewModel { Amount = 0.1, MultiBetStartBalance = 0},
new CasinoBetButtonViewModel { Amount = 0.5, MultiBetStartBalance = 100 },
new CasinoBetButtonViewModel { Amount = 1, MultiBetStartBalance = 200, IsAvailable = true },
new CasinoBetButtonViewModel { Amount = 5, MultiBetStartBalance = 400, IsAvailable = true },
new CasinoBetButtonViewModel { Amount = 25, MultiBetStartBalance = 1000, IsAvailable = true },
new CasinoBetButtonViewModel { Amount = 100, MultiBetStartBalance = 4000 },
};
CasinoBets = new ReadOnlyCollection<CasinoBetButtonViewModel>(_CasinoBets);
DefaultBet = CasinoBets.FirstOrDefault(cur => cur.Amount == 1);
}
示例10: PickAudioFormat
public static AudioFormat PickAudioFormat(ReadOnlyCollection<AudioFormat> audioFormats,
AudioFormatEx desiredFormat)
{
return audioFormats.FirstOrDefault(audioFormat => desiredFormat.Equals(audioFormat));
}