Here are the examples of the csharp api System.Linq.Enumerable.Empty() taken from open source projects. By voting up you can indicate which examples are most useful and appropriate.
5416 Examples
19
View Source File : AvifParser.cs
License : MIT License
Project Creator : 0xC0000054
License : MIT License
Project Creator : 0xC0000054
private IEnumerable<IItemReferenceEntry> GetMatchingReferences(uint itemId, FourCC requiredReferenceType)
{
ItemReferenceBox itemReferenceBox = this.metaBox.ItemReferences;
if (itemReferenceBox != null)
{
return itemReferenceBox.EnumerateMatchingReferences(itemId, requiredReferenceType);
}
else
{
return Enumerable.Empty<IItemReferenceEntry>();
}
}
19
View Source File : IO.cs
License : MIT License
Project Creator : 13xforever
License : MIT License
Project Creator : 13xforever
public static IEnumerable<string> GetFilepaths(string rootPath, string patternMatch, SearchOption searchOption)
{
var foundFiles = Enumerable.Empty<string>();
try
{
foundFiles = foundFiles.Concat(Directory.EnumerateFiles(rootPath, patternMatch));
}
catch (Exception e) when (e is UnauthorizedAccessException || e is PathTooLongException)
{
Console.WriteLine($"{rootPath}: {e.Message}");
}
if (searchOption == SearchOption.AllDirectories)
{
try
{
var subDirs = Directory.EnumerateDirectories(rootPath);
foreach (var dir in subDirs)
{
try
{
var newFiles = GetFilepaths(dir, patternMatch, searchOption);
foundFiles = foundFiles.Concat(newFiles);
}
catch (Exception e) when (e is UnauthorizedAccessException || e is PathTooLongException)
{
Console.WriteLine($"{dir}: {e.Message}");
}
}
}
catch (Exception e) when (e is UnauthorizedAccessException || e is PathTooLongException)
{
Console.WriteLine($"{rootPath}: {e.Message}");
}
}
return foundFiles;
}
19
View Source File : IO.cs
License : MIT License
Project Creator : 13xforever
License : MIT License
Project Creator : 13xforever
private static IEnumerable<string> GetFilepaths(string rootPath, string patternMatch, int currentLevel, int maxLevel)
{
var foundFiles = Enumerable.Empty<string>();
try
{
foundFiles = foundFiles.Concat(Directory.EnumerateFiles(rootPath, patternMatch));
}
catch (Exception e) when (e is UnauthorizedAccessException || e is PathTooLongException)
{
Console.WriteLine($"{rootPath}: {e.Message}");
}
if (currentLevel < maxLevel)
{
try
{
var subDirs = Directory.EnumerateDirectories(rootPath);
foreach (var dir in subDirs)
{
try
{
var newFiles = GetFilepaths(dir, patternMatch, currentLevel+1, maxLevel);
foundFiles = foundFiles.Concat(newFiles);
}
catch (Exception e) when (e is UnauthorizedAccessException || e is PathTooLongException)
{
Console.WriteLine($"{dir}: {e.Message}");
}
}
}
catch (Exception e) when (e is UnauthorizedAccessException || e is PathTooLongException)
{
Console.WriteLine($"{rootPath}: {e.Message}");
}
}
return foundFiles;
}
19
View Source File : Program.cs
License : MIT License
Project Creator : 13xforever
License : MIT License
Project Creator : 13xforever
private static IEnumerable<string> GetFilePaths(string rootPath, string patternMatch, SearchOption searchOption)
{
var foundFiles = Enumerable.Empty<string>();
try
{
foundFiles = foundFiles.Concat(Directory.EnumerateFiles(rootPath, patternMatch));
}
catch (Exception e) when (e is UnauthorizedAccessException || e is PathTooLongException)
{
Console.WriteLine($"{rootPath}: {e.Message}");
}
if (searchOption == SearchOption.AllDirectories)
{
try
{
var subDirs = Directory.EnumerateDirectories(rootPath);
foreach (var dir in subDirs)
{
try
{
var newFiles = GetFilePaths(dir, patternMatch, searchOption);
foundFiles = foundFiles.Concat(newFiles);
}
catch (Exception e) when (e is UnauthorizedAccessException || e is PathTooLongException)
{
Console.WriteLine($"{dir}: {e.Message}");
}
}
}
catch (Exception e) when (e is UnauthorizedAccessException || e is PathTooLongException)
{
Console.WriteLine($"{rootPath}: {e.Message}");
}
}
return foundFiles;
}
19
View Source File : BssMapObjMarshalReader.cs
License : MIT License
Project Creator : 1996v
License : MIT License
Project Creator : 1996v
public IEnumerator<KeyValuePair<TKey, TValue>> GetEnumerator()
{
if (Count == 0)
{
return Enumerable.Empty<KeyValuePair<TKey, TValue>>().GetEnumerator();
}
Reader.BssomBuffer.TryReadFixedRef(Paras.MapHead.RouteLength, out bool haveEnoughSizeAndCanBeFixed);
if (haveEnoughSizeAndCanBeFixed)
{
return new Enumerator(this);
}
else
{
return new EnumeratorSlow(this);
}
}
19
View Source File : HttpClientAsync.cs
License : MIT License
Project Creator : 188867052
License : MIT License
Project Creator : 188867052
private static IServiceProvider CreateServices(IEnumerable<Endpoint> endpoints)
{
if (endpoints == null)
{
endpoints = Enumerable.Empty<Endpoint>();
}
var services = GetCommonServices();
services.AddRouting();
services.TryAddEnumerable(ServiceDescriptor.Singleton<EndpointDataSource>(new DefaultEndpointDataSource(endpoints)));
services.TryAddSingleton<IUrlHelperFactory, UrlHelperFactory>();
return services.BuildServiceProvider();
}
19
View Source File : TcpClientEx.cs
License : MIT License
Project Creator : 1iveowl
License : MIT License
Project Creator : 1iveowl
private static async Task<byte[]> ReadOneByteAtTheTimeAsync(Stream stream, CancellationToken ct)
{
if (ct.IsCancellationRequested)
{
return Enumerable.Empty<byte>().ToArray();
}
var oneByteArray = new byte[1];
try
{
if (stream == null)
{
throw new Exception("Read stream cannot be null.");
}
if (!stream.CanRead)
{
throw new Exception("Stream connection have been closed.");
}
var bytesRead = await stream.ReadAsync(oneByteArray, 0, 1, ct).ConfigureAwait(false);
if (bytesRead < oneByteArray.Length)
{
throw new Exception("Stream connection aborted unexpectedly. Check connection and socket security version/TLS version).");
}
}
catch (ObjectDisposedException)
{
Debug.WriteLine("Ignoring Object Disposed Exception - This is an expected exception.");
return Enumerable.Empty<byte>().ToArray();
}
catch (IOException)
{
return Enumerable.Empty<byte>().ToArray();
}
return oneByteArray;
}
19
View Source File : HttpStreamParser.cs
License : MIT License
Project Creator : 1iveowl
License : MIT License
Project Creator : 1iveowl
internal async Task<IHttpRequestResponse> ParseAsync(Stream stream, CancellationToken ct)
{
_disposableParserCompletion = _parserDelegate.ParserCompletionObservable
.Subscribe(parserState =>
{
switch (parserState)
{
case ParserState.Start:
break;
case ParserState.Parsing:
break;
case ParserState.Completed:
break;
case ParserState.Failed:
HasParsingError = true;
break;
default:
throw new ArgumentOutOfRangeException(nameof(parserState), parserState, null);
}
},
ex => throw ex,
() =>
{
IsDone = true;
});
await Observable.While(
() => !HasParsingError && !IsDone,
Observable.FromAsync(() => ReadBytesAsync(stream, ct)))
.Catch<byte[], SimpleHttpListenerException>(ex =>
{
HasParsingError = true;
return Observable.Return(Enumerable.Empty<byte>().ToArray());
})
.Where(b => b != Enumerable.Empty<byte>().ToArray())
.Where(bSegment => bSegment.Length > 0)
.Select(b => new ArraySegment<byte>(b, 0, b.Length))
.Select(bSegment => _parser.Execute(bSegment));
_parser.Execute(default);
_parserDelegate.RequestResponse.MajorVersion = _parser.MajorVersion;
_parserDelegate.RequestResponse.MinorVersion = _parser.MinorVersion;
_parserDelegate.RequestResponse.ShouldKeepAlive = _parser.ShouldKeepAlive;
return _parserDelegate.RequestResponse;
}
19
View Source File : HttpStreamParser.cs
License : MIT License
Project Creator : 1iveowl
License : MIT License
Project Creator : 1iveowl
private async Task<byte[]> ReadBytesAsync(Stream stream, CancellationToken ct)
{
if (_parserDelegate.RequestResponse.IsEndOfRequest || HasParsingError)
{
IsDone = true;
return Enumerable.Empty<byte>().ToArray();
}
if (ct.IsCancellationRequested)
{
return Enumerable.Empty<byte>().ToArray();
}
var b = new byte[1];
if (stream == null)
{
throw new Exception("Read stream cannot be null.");
}
if (!stream.CanRead)
{
throw new Exception("Stream connection have been closed.");
}
var bytesRead = 0;
try
{
//Debug.WriteLine("Reading byte.");
bytesRead = await stream.ReadAsync(b, 0, 1, ct).ConfigureAwait(false);
//Debug.WriteLine("Done reading byte.");
}
catch (Exception ex)
{
HasParsingError = true;
throw new SimpleHttpListenerException("Unable to read network stream.", ex);
}
if (bytesRead < b.Length)
{
IsDone = true;
}
return _errorCorrections.Contains(ErrorCorrection.HeaderCompletionError)
? ResilientHeader(b)
: b;
}
19
View Source File : TcpClientEx.cs
License : MIT License
Project Creator : 1iveowl
License : MIT License
Project Creator : 1iveowl
private static IObservable<byte[]> CreateByteStreamObservable2(Stream stream, TcpClient tcpClient, CancellationToken ct)
{
var observableBytes = Observable.Create<byte[]>(obs =>
{
while (!ct.IsCancellationRequested)
{
if (ct.IsCancellationRequested || !tcpClient.Connected)
{
obs.OnNext(Enumerable.Empty<byte>().ToArray());
}
var oneByteArray = new byte[1];
try
{
if (stream == null)
{
throw new Exception("Read stream cannot be null.");
}
if (!stream.CanRead)
{
throw new Exception("Stream connection have been closed.");
}
var bytesRead = stream.ReadByte();
; //var bytesRead = await stream.ReadAsync(oneByteArray, 0, 1, ct).ConfigureAwait(false);
if (bytesRead < oneByteArray.Length)
{
throw new Exception("Stream connection aborted unexpectedly. Check connection and socket security version/TLS version).");
}
}
catch (ObjectDisposedException)
{
Debug.WriteLine("Ignoring Object Disposed Exception - This is an expected exception.");
obs.OnNext(Enumerable.Empty<byte>().ToArray());
}
catch (IOException)
{
obs.OnNext(Enumerable.Empty<byte>().ToArray());
}
obs.OnNext(oneByteArray);
}
obs.OnCompleted();
return Disposable.Empty;
});
return observableBytes.SubscribeOn(Scheduler.Default);
}
19
View Source File : TrackingExpressionVisitor.cs
License : MIT License
Project Creator : 71
License : MIT License
Project Creator : 71
public override Expression Visit(Expression node)
{
if (node == null)
return null;
if (Projector != null)
{
// Project things in here, to avoid traversing the tree multiple times
// ReSharper disable once PossibleInvalidCastExceptionInForeachLoop
foreach (ExpressionProjector projector in Projector.GetInvocationList())
node = projector(node);
}
node = node.ReduceExtensions();
if (node is BlockExpression block)
// Make sure we don't have smaller scopes that would break the variable replacedignements
node = block.Update(Enumerable.Empty<ParameterExpression>(), block.Expressions);
if (node is ParameterExpression variable && !Variables.Contains(variable) && !variable.IsreplacedignableTo<VirtualStateMachine>())
// Keep track of variable
Variables.Add(variable);
if (node.NodeType == ExpressionType.Extension && !node.CanReduce)
// In case we're returning a special expression (ie: YieldExpression)
return node;
return base.Visit(node);
}
19
View Source File : ConcurrentQueueCapacityInitializer.cs
License : MIT License
Project Creator : Abc-Arbitrage
License : MIT License
Project Creator : Abc-Arbitrage
public IEnumerator<LogEvent> GetEnumerator() => Enumerable.Empty<LogEvent>().GetEnumerator();
19
View Source File : XmlFoldingStrategy.cs
License : MIT License
Project Creator : Abdesol
License : MIT License
Project Creator : Abdesol
public IEnumerable<NewFolding> CreateNewFoldings(TextDoreplacedent doreplacedent, out int firstErrorOffset)
{
try {
XmlTextReader reader = new XmlTextReader(doreplacedent.CreateReader());
reader.XmlResolver = null; // don't resolve DTDs
return CreateNewFoldings(doreplacedent, reader, out firstErrorOffset);
} catch (XmlException) {
firstErrorOffset = 0;
return Enumerable.Empty<NewFolding>();
}
}
19
View Source File : NoReadOnlySections.cs
License : MIT License
Project Creator : Abdesol
License : MIT License
Project Creator : Abdesol
public IEnumerable<ISegment> GetDeletableSegments(ISegment segment)
{
return Enumerable.Empty<ISegment>();
}
19
View Source File : WorkFlowInvoker.cs
License : Apache License 2.0
Project Creator : AbpApp
License : Apache License 2.0
Project Creator : AbpApp
private Task<WorkflowExecutionContext> ExecuteAsync(
Workflow workflow,
bool resume,
IEnumerable<string> startActivityIds = default,
CancellationToken cancellationToken = default)
{
var startActivities = startActivityIds != null
? workflow.Activities.Find(startActivityIds)
: Enumerable.Empty<IActivity>();
return ExecuteAsync(workflow, resume, startActivities, cancellationToken);
}
19
View Source File : SixCloudUser.cs
License : MIT License
Project Creator : Accelerider
License : MIT License
Project Creator : Accelerider
public override Task<ILazyTreeNode<INetDiskFile>> GetFileRootAsync()
{
var tree = new LazyTreeNode<INetDiskFile>(new SixCloudFile())
{
ChildrenProvider = async parent =>
{
var json = await WebApi.GetFilesByPathAsync(new GetFilesByPathArgs { Path = parent.Path, PageSize = 999 });
return json.Success
? json.Result["list"].Select(item => item.ToObject<SixCloudFile>()).ToList()
: Enumerable.Empty<SixCloudFile>();
}
};
return Task.FromResult<ILazyTreeNode<INetDiskFile>>(tree);
}
19
View Source File : HttpRequestMessageWrapper.cs
License : MIT License
Project Creator : actions
License : MIT License
Project Creator : actions
IEnumerable<String> IHttpHeaders.GetValues(String name)
{
IEnumerable<String> values;
if (!m_request.Headers.TryGetValues(name, out values))
{
values = Enumerable.Empty<String>();
}
return values;
}
19
View Source File : HttpResponseMessageWrapper.cs
License : MIT License
Project Creator : actions
License : MIT License
Project Creator : actions
IEnumerable<String> IHttpHeaders.GetValues(String name)
{
IEnumerable<String> values;
if (!m_response.Headers.TryGetValues(name, out values))
{
values = Enumerable.Empty<String>();
}
return values;
}
19
View Source File : EnumerableExtensions.cs
License : MIT License
Project Creator : actions
License : MIT License
Project Creator : actions
public static IEnumerable<T> AsEmptyIfNull<T>(this IEnumerable<T> source)
=> source ?? Enumerable.Empty<T>();
19
View Source File : XmlSerializableDataContractExtensions.cs
License : MIT License
Project Creator : actions
License : MIT License
Project Creator : actions
private static SerializableProperties GetSerializableProperties(TypeInfo type)
{
if (SerializablePropertiesByType.TryGetValue(type, out var properties))
{
return properties;
}
var dataContract = type.GetCustomAttribute(typeof(XmlSerializableDataContractAttribute)) as XmlSerializableDataContractAttribute;
var enableCamelCaseNameCompat = dataContract == null ? false : dataContract.EnableCamelCaseNameCompat;
var declaredProperties = new List<SerializableProperty>();
foreach (var declaredProperty in type.DeclaredProperties)
{
if (declaredProperty.GetCustomAttribute(typeof(XmlIgnoreAttribute)) != null)
{
continue;
}
if (declaredProperty.SetMethod == null)
{
continue;
}
var dataMember = declaredProperty.GetCustomAttribute(typeof(DataMemberAttribute)) as DataMemberAttribute;
if (dataMember == null)
{
continue;
}
var shouldSerializeMethodName = string.Concat("ShouldSerialize", declaredProperty.Name);
var shouldSerializeMethod = type.GetDeclaredMethod(shouldSerializeMethodName);
declaredProperties.Add(new SerializableProperty(declaredProperty, dataMember, shouldSerializeMethod, enableCamelCaseNameCompat));
}
var inheritedProperties = Enumerable.Empty<SerializableProperty>();
if (type.BaseType != typeof(object))
{
inheritedProperties = GetSerializableProperties(type.BaseType.GetTypeInfo()).EnumeratedInOrder;
}
var serializableProperties = new SerializableProperties(declaredProperties, inheritedProperties);
return SerializablePropertiesByType.GetOrAdd(type, serializableProperties);
}
19
View Source File : VssApiResourceLocationCollection.cs
License : MIT License
Project Creator : actions
License : MIT License
Project Creator : actions
public IEnumerable<ApiResourceLocation> GetResourceLocations(String area, String resourceName)
{
List<ApiResourceLocation> locationsByKey;
String locationCacheKey = GetLocationCacheKey(area, resourceName);
if (m_locationsByKey.TryGetValue(locationCacheKey, out locationsByKey))
{
return locationsByKey;
}
else
{
return Enumerable.Empty<ApiResourceLocation>();
}
}
19
View Source File : SuppressionManager.cs
License : GNU General Public License v3.0
Project Creator : Acumatica
License : GNU General Public License v3.0
Project Creator : Acumatica
private static void InitOrReset(IEnumerable<SuppressionManagerInitInfo> suppressionFileInfos,
Func<ISuppressionFileSystemService> fileSystemServiceFabric,
Func<IIOErrorProcessor> errorProcessorFabric,
Func<ICustomBuildActionSetter> buildActionSetterFabric)
{
suppressionFileInfos = suppressionFileInfos ?? Enumerable.Empty<SuppressionManagerInitInfo>();
lock (_initializationLocker)
{
if (Instance == null)
{
ISuppressionFileSystemService fileSystemService;
if (fileSystemServiceFabric == null)
{
IIOErrorProcessor errorProcessor = errorProcessorFabric?.Invoke();
fileSystemService = new SuppressionFileWithChangesTrackingSystemService(errorProcessor);
}
else
{
fileSystemService = fileSystemServiceFabric();
}
ICustomBuildActionSetter customBuildActionSetter = buildActionSetterFabric?.Invoke();
Instance = new SuppressionManager(fileSystemService, customBuildActionSetter);
}
else
{
Instance.Clear();
}
Instance.LoadSuppressionFiles(suppressionFileInfos);
}
}
19
View Source File : FieldTypeAttributesRegister.cs
License : GNU General Public License v3.0
Project Creator : Acumatica
License : GNU General Public License v3.0
Project Creator : Acumatica
public IEnumerable<FieldTypeAttributeInfo> GetFieldTypeAttributeInfos(ITypeSymbol attributeSymbol)
{
attributeSymbol.ThrowOnNull(nameof(attributeSymbol));
var expandedAttributes = _attributeInformation.GetAreplacedaticaAttributesFullList(attributeSymbol);
if (expandedAttributes.IsNullOrEmpty())
return Enumerable.Empty<FieldTypeAttributeInfo>();
List<FieldTypeAttributeInfo> typeAttributeInfos = new List<FieldTypeAttributeInfo>(capacity: 2);
foreach (ITypeSymbol attribute in expandedAttributes)
{
FieldTypeAttributeInfo? attributeInfo = GetTypeAttributeInfo(attribute);
if (attributeInfo != null)
{
typeAttributeInfos.Add(attributeInfo.Value);
}
}
return typeAttributeInfos;
}
19
View Source File : DacSymbolsHierarchyUtils.cs
License : GNU General Public License v3.0
Project Creator : Acumatica
License : GNU General Public License v3.0
Project Creator : Acumatica
public static IEnumerable<ITypeSymbol> GetDacExtensionsWithDac(this ITypeSymbol dacExtension, PXContext pxContext)
{
dacExtension.ThrowOnNull(nameof(dacExtension));
pxContext.ThrowOnNull(nameof(pxContext));
if (!dacExtension.IsDacExtension(pxContext))
{
return Enumerable.Empty<ITypeSymbol>();
}
var extensionBaseType = dacExtension.BaseType;
var typeArguments = extensionBaseType.TypeArguments;
var dacType = typeArguments.LastOrDefault();
if (dacType == null || !dacType.IsDAC(pxContext))
{
return Enumerable.Empty<ITypeSymbol>();
}
var types = new List<ITypeSymbol>(typeArguments.Length + 1) { dacExtension };
var typeArgumentsExceptDac = typeArguments.Take(typeArguments.Length - 1);
foreach (var ta in typeArgumentsExceptDac)
{
if (!ta.IsDacExtension(pxContext))
{
return Enumerable.Empty<ITypeSymbol>();
}
types.Add(ta);
}
types.Add(dacType);
return types;
}
19
View Source File : DacSymbolsHierarchyUtils.cs
License : GNU General Public License v3.0
Project Creator : Acumatica
License : GNU General Public License v3.0
Project Creator : Acumatica
public static IEnumerable<ITypeSymbol> GetDacExtensionWithBaseExtensions(this ITypeSymbol dacExtension, PXContext pxContext,
SortDirection sortDirection, bool includeDac)
{
pxContext.ThrowOnNull(nameof(pxContext));
if (dacExtension == null || !dacExtension.IsDacExtension(pxContext))
return Enumerable.Empty<ITypeSymbol>();
var extensionBaseType = dacExtension.GetBaseTypesAndThis()
.FirstOrDefault(type => type.IsDacExtensionBaseType()) as INamedTypeSymbol;
if (extensionBaseType == null)
return Enumerable.Empty<ITypeSymbol>();
var dacType = extensionBaseType.TypeArguments.LastOrDefault();
if (dacType == null || !dacType.IsDAC(pxContext))
return Enumerable.Empty<ITypeSymbol>();
return sortDirection == SortDirection.Ascending
? GetExtensionInAscendingOrder(dacType, dacExtension, extensionBaseType, pxContext, includeDac)
: GetExtensionInDescendingOrder(dacType, dacExtension, extensionBaseType, pxContext, includeDac);
}
19
View Source File : DacSymbolsHierarchyUtils.cs
License : GNU General Public License v3.0
Project Creator : Acumatica
License : GNU General Public License v3.0
Project Creator : Acumatica
private static IEnumerable<ITypeSymbol> GetExtensionInAscendingOrder(ITypeSymbol dacType, ITypeSymbol dacExtension,
INamedTypeSymbol extensionBaseType, PXContext pxContext, bool includeDac)
{
int dacIndex = extensionBaseType.TypeArguments.Length - 1;
var extensions = new List<ITypeSymbol>(capacity: extensionBaseType.TypeArguments.Length);
if (includeDac)
{
extensions.AddRange(dacType.GetDacWithBaseTypes().Reverse());
}
for (int i = dacIndex - 1; i >= 0; i--)
{
var baseExtension = extensionBaseType.TypeArguments[i];
if (!baseExtension.IsDacExtension(pxContext))
return Enumerable.Empty<ITypeSymbol>();
extensions.Add(baseExtension); //According to Platform team we shouldn't consider case when the extensions chaining mixes with .Net inheritance
}
extensions.AddRange(dacExtension.GetDacExtensionWithBaseTypes().Reverse());
return extensions.Distinct();
}
19
View Source File : GraphSymbolHierarchyUtils.cs
License : GNU General Public License v3.0
Project Creator : Acumatica
License : GNU General Public License v3.0
Project Creator : Acumatica
public static IEnumerable<ITypeSymbol> GetGraphExtensionWithBaseExtensions(this ITypeSymbol graphExtension, PXContext pxContext,
SortDirection sortDirection, bool includeGraph)
{
pxContext.ThrowOnNull(nameof(pxContext));
if (graphExtension == null || !graphExtension.InheritsFrom(pxContext.PXGraphExtensionType))
return Enumerable.Empty<ITypeSymbol>();
INamedTypeSymbol extensionBaseType = graphExtension.GetBaseTypesAndThis()
.FirstOrDefault(type => type.IsGraphExtensionBaseType()) as INamedTypeSymbol;
if (extensionBaseType == null)
return Enumerable.Empty<ITypeSymbol>();
var graphType = extensionBaseType.TypeArguments.LastOrDefault();
if (graphType == null || !graphType.IsPXGraph(pxContext))
return Enumerable.Empty<ITypeSymbol>();
return sortDirection == SortDirection.Ascending
? GetExtensionInAscendingOrder(graphType, graphExtension, extensionBaseType, pxContext, includeGraph)
: GetExtensionInDescendingOrder(graphType, graphExtension, extensionBaseType, pxContext, includeGraph);
}
19
View Source File : GraphSymbolHierarchyUtils.cs
License : GNU General Public License v3.0
Project Creator : Acumatica
License : GNU General Public License v3.0
Project Creator : Acumatica
private static IEnumerable<ITypeSymbol> GetExtensionInAscendingOrder(ITypeSymbol graphType, ITypeSymbol graphExtension,
INamedTypeSymbol extensionBaseType, PXContext pxContext, bool includeGraph)
{
int graphIndex = extensionBaseType.TypeArguments.Length - 1;
var extensions = new List<ITypeSymbol>(capacity: extensionBaseType.TypeArguments.Length);
if (includeGraph)
{
extensions.AddRange(graphType.GetGraphWithBaseTypes().Reverse());
}
for (int i = graphIndex - 1; i >= 0; i--)
{
var baseExtension = extensionBaseType.TypeArguments[i];
if (!baseExtension.IsPXGraphExtension(pxContext))
return Enumerable.Empty<ITypeSymbol>();
extensions.Add(baseExtension); //According to Platform team we shouldn't consider case when the graph extensions chaining mixes with .Net inheritance
}
extensions.AddRange(graphExtension.GetExtensionWithBaseTypes().Reverse());
return extensions.Distinct();
}
19
View Source File : GraphSymbolHierarchyUtils.cs
License : GNU General Public License v3.0
Project Creator : Acumatica
License : GNU General Public License v3.0
Project Creator : Acumatica
private static IEnumerable<ITypeSymbol> GetExtensionInDescendingOrder(ITypeSymbol graphType, ITypeSymbol graphExtension,
INamedTypeSymbol extensionBaseType, PXContext pxContext, bool includeGraph)
{
int graphIndex = extensionBaseType.TypeArguments.Length - 1;
var extensions = new List<ITypeSymbol>(capacity: extensionBaseType.TypeArguments.Length);
extensions.AddRange(graphExtension.GetExtensionWithBaseTypes());
for (int i = 0; i <= graphIndex - 1; i++)
{
var baseExtension = extensionBaseType.TypeArguments[i];
if (!baseExtension.IsPXGraphExtension(pxContext))
return Enumerable.Empty<ITypeSymbol>();
extensions.Add(baseExtension); //According to Platform team we shouldn't consider case when the graph extensions chaining mixes with .Net inheritance
}
if (includeGraph)
{
extensions.AddRange(graphType.GetGraphWithBaseTypes());
}
return extensions.Distinct();
}
19
View Source File : SuppressionManager.cs
License : GNU General Public License v3.0
Project Creator : Acumatica
License : GNU General Public License v3.0
Project Creator : Acumatica
public static IEnumerable<SuppressionDiffResult> ValidateSuppressionBaseDiff()
{
if (Instance == null)
{
return Enumerable.Empty<SuppressionDiffResult>();
}
var diffList = new List<SuppressionDiffResult>();
lock (Instance._fileSystemService)
{
foreach (SuppressionFile currentFile in Instance._fileByreplacedembly.Files)
{
var oldFile = SuppressionFile.Load(Instance._fileSystemService, suppressionFilePath: currentFile.Path,
generateSuppressionBase: false);
diffList.Add(CompareFiles(oldFile, currentFile));
}
}
return diffList;
}
19
View Source File : DacSymbolsHierarchyUtils.cs
License : GNU General Public License v3.0
Project Creator : Acumatica
License : GNU General Public License v3.0
Project Creator : Acumatica
private static IEnumerable<ITypeSymbol> GetExtensionInDescendingOrder(ITypeSymbol dacType, ITypeSymbol dacExtension,
INamedTypeSymbol extensionBaseType, PXContext pxContext, bool includeDac)
{
int dacIndex = extensionBaseType.TypeArguments.Length - 1;
var extensions = new List<ITypeSymbol>(capacity: extensionBaseType.TypeArguments.Length);
extensions.AddRange(dacExtension.GetDacExtensionWithBaseTypes());
for (int i = 0; i <= dacIndex - 1; i++)
{
var baseExtension = extensionBaseType.TypeArguments[i];
if (!baseExtension.IsDacExtension(pxContext))
return Enumerable.Empty<ITypeSymbol>();
extensions.Add(baseExtension); //According to Platform team we shouldn't consider case when the extensions chaining mixes with .Net inheritance
}
if (includeDac)
{
extensions.AddRange(dacType.GetDacWithBaseTypes());
}
return extensions.Distinct();
}
19
View Source File : SuppressionManager.SuppressionFileCreator.cs
License : GNU General Public License v3.0
Project Creator : Acumatica
License : GNU General Public License v3.0
Project Creator : Acumatica
public TextDoreplacedent AddAdditionalSuppressionDoreplacedentToProject(Project project)
{
project.ThrowOnNull(nameof(project));
string suppressionFileName = project.replacedemblyName + SuppressionFile.SuppressionFileExtension;
string projectDir = Instance._fileSystemService.GetFileDirectory(project.FilePath);
string suppressionFilePath = Path.Combine(projectDir, suppressionFileName);
//Create new xml doreplacedent and get its text
var newXDoreplacedent = SuppressionFile.NewDoreplacedentFromMessages(Enumerable.Empty<SuppressMessage>());
if (newXDoreplacedent == null) //-V3022
return null;
string docText = newXDoreplacedent.GetXDoreplacedentStringWithDeclaration();
//Add file to project without applying changes to workspace
return project.AddAdditionalDoreplacedent(suppressionFileName, docText, filePath: suppressionFilePath);
}
19
View Source File : FirstViewsInGraphRule.cs
License : GNU General Public License v3.0
Project Creator : Acumatica
License : GNU General Public License v3.0
Project Creator : Acumatica
public override IEnumerable<ITypeSymbol> GetCandidatesFromGraphRule(PrimaryDacFinder dacFinder)
{
if (dacFinder == null || dacFinder.GraphViews.Length == 0 || dacFinder.CancellationToken.IsCancellationRequested)
{
return Enumerable.Empty<ITypeSymbol>();
}
return dacFinder.GraphViews.Take(NumberOfViews)
.Select(view => view.Type.GetDacFromView(dacFinder.PxContext))
.Where(dac => dac != null);
}
19
View Source File : NoReadOnlyViewGraphRule.cs
License : GNU General Public License v3.0
Project Creator : Acumatica
License : GNU General Public License v3.0
Project Creator : Acumatica
public override IEnumerable<ITypeSymbol> GetCandidatesFromGraphRule(PrimaryDacFinder dacFinder)
{
if (dacFinder == null || dacFinder.CancellationToken.IsCancellationRequested)
return Enumerable.Empty<ITypeSymbol>();
List<INamedTypeSymbol> readOnlyViews = new List<INamedTypeSymbol>(capacity: 4);
List<INamedTypeSymbol> editableViews = new List<INamedTypeSymbol>(capacity: dacFinder.GraphViews.Length);
foreach (var viewWithType in dacFinder.GraphViews)
{
if (dacFinder.CancellationToken.IsCancellationRequested)
return Enumerable.Empty<ITypeSymbol>();
if (viewWithType.Type.IsPXNonUpdateableBqlCommand(dacFinder.PxContext))
readOnlyViews.Add(viewWithType.Type);
else
editableViews.Add(viewWithType.Type);
}
if (editableViews.Count == 0 || dacFinder.CancellationToken.IsCancellationRequested)
return Enumerable.Empty<ITypeSymbol>();
return readOnlyViews.Select(viewType => viewType.GetDacFromView(dacFinder.PxContext));
}
19
View Source File : PairOfViewsWithSpecialNamesGraphRule.cs
License : GNU General Public License v3.0
Project Creator : Acumatica
License : GNU General Public License v3.0
Project Creator : Acumatica
public override IEnumerable<ITypeSymbol> GetCandidatesFromGraphRule(PrimaryDacFinder dacFinder)
{
if (dacFinder?.GraphSemanticModel?.GraphSymbol == null || dacFinder.CancellationToken.IsCancellationRequested ||
dacFinder.GraphViews.Length == 0)
{
return Enumerable.Empty<ITypeSymbol>();
}
bool firstNameFound = dacFinder.GraphSemanticModel.ViewsByNames.TryGetValue(_firstName, out var firstView);
bool secondNameFound = dacFinder.GraphSemanticModel.ViewsByNames.TryGetValue(_secondName, out var secondView);
if (!firstNameFound || !secondNameFound)
{
return Enumerable.Empty<ITypeSymbol>();
}
ITypeSymbol firstDacCandidate = firstView.Type.GetDacFromView(dacFinder.PxContext);
ITypeSymbol secondDacCandidate = secondView.Type.GetDacFromView(dacFinder.PxContext);
var dacCandidate = ChooseDacCandidate(firstDacCandidate, secondDacCandidate);
return dacCandidate?.ToEnumerable() ?? Enumerable.Empty<ITypeSymbol>();
}
19
View Source File : PrimaryDacSpecifiedGraphRule.cs
License : GNU General Public License v3.0
Project Creator : Acumatica
License : GNU General Public License v3.0
Project Creator : Acumatica
public override IEnumerable<ITypeSymbol> GetCandidatesFromGraphRule(PrimaryDacFinder dacFinder)
{
if (dacFinder?.GraphSemanticModel?.GraphSymbol == null)
return Enumerable.Empty<ITypeSymbol>();
ITypeSymbol primaryDac = dacFinder.GraphSemanticModel.GraphSymbol
.GetDeclaredPrimaryDacFromGraphOrGraphExtension(dacFinder.PxContext);
return primaryDac?.ToEnumerable() ?? Enumerable.Empty<ITypeSymbol>();
}
19
View Source File : PXFilteredProcessingGraphRule.cs
License : GNU General Public License v3.0
Project Creator : Acumatica
License : GNU General Public License v3.0
Project Creator : Acumatica
public override IEnumerable<ITypeSymbol> GetCandidatesFromGraphRule(PrimaryDacFinder dacFinder)
{
if (_pxFilteredProcessingType == null || dacFinder?.GraphSemanticModel?.GraphSymbol == null ||
dacFinder.CancellationToken.IsCancellationRequested || dacFinder.GraphViews.Length == 0)
{
return Enumerable.Empty<ITypeSymbol>();
}
List<ITypeSymbol> primaryDacCandidates = new List<ITypeSymbol>(1);
foreach (DataViewInfo view in dacFinder.GraphViews)
{
if (dacFinder.CancellationToken.IsCancellationRequested)
return Enumerable.Empty<ITypeSymbol>();
var fProcessingView = view.Type.GetBaseTypesAndThis()
.FirstOrDefault(t => _pxFilteredProcessingType.Equals(t) ||
_pxFilteredProcessingType.Equals(t?.OriginalDefinition));
if (fProcessingView == null || !(fProcessingView is INamedTypeSymbol filteredProcessingView))
continue;
var typeParameters = filteredProcessingView.TypeArguments;
if (typeParameters.Length < 2 || !typeParameters[1].IsDAC())
continue;
primaryDacCandidates.Add(typeParameters[1]);
}
return primaryDacCandidates;
}
19
View Source File : PXImportAttributeGraphRule.cs
License : GNU General Public License v3.0
Project Creator : Acumatica
License : GNU General Public License v3.0
Project Creator : Acumatica
public override IEnumerable<ITypeSymbol> GetCandidatesFromGraphRule(PrimaryDacFinder dacFinder)
{
if (dacFinder == null || dacFinder.CancellationToken.IsCancellationRequested)
return Enumerable.Empty<ITypeSymbol>();
List<ITypeSymbol> primaryDacCandidates = new List<ITypeSymbol>(1);
foreach (DataViewInfo viewInfo in dacFinder.GraphViews)
{
if (dacFinder.CancellationToken.IsCancellationRequested)
return Enumerable.Empty<ITypeSymbol>();
ImmutableArray<AttributeData> attributes = viewInfo.Symbol.GetAttributes();
if (attributes.Length == 0)
continue;
var importAttributeType = dacFinder.PxContext.AttributeTypes.PXImportAttribute;
var importAttributeData = attributes.FirstOrDefault(a => a.AttributeClreplaced.Equals(importAttributeType));
if (importAttributeData == null)
continue;
else if (dacFinder.CancellationToken.IsCancellationRequested)
return Enumerable.Empty<ITypeSymbol>();
var dacArgType = (from arg in importAttributeData.ConstructorArguments
where arg.Kind == TypedConstantKind.Type && arg.Type.IsDAC()
select arg.Type)
.FirstOrDefault();
if (dacArgType != null)
{
primaryDacCandidates.Add(dacArgType);
}
}
return primaryDacCandidates;
}
19
View Source File : ViewsWithoutPXViewNameAttributeGraphRule.cs
License : GNU General Public License v3.0
Project Creator : Acumatica
License : GNU General Public License v3.0
Project Creator : Acumatica
public override IEnumerable<ITypeSymbol> GetCandidatesFromGraphRule(PrimaryDacFinder dacFinder)
{
if (dacFinder?.GraphSemanticModel?.GraphSymbol == null || dacFinder.CancellationToken.IsCancellationRequested ||
dacFinder.GraphViews.Length == 0)
{
return Enumerable.Empty<ITypeSymbol>();
}
List<ITypeSymbol> dacCandidates = new List<ITypeSymbol>(dacFinder.GraphViews.Length);
bool grapHasViewsWithViewNameAttribute = false;
foreach (DataViewInfo viewInfo in dacFinder.GraphViews)
{
if (dacFinder.CancellationToken.IsCancellationRequested)
return Enumerable.Empty<ITypeSymbol>();
ImmutableArray<AttributeData> attributes = viewInfo.Symbol.GetAttributes();
if (attributes.Length == 0)
continue;
bool viewHasViewNameAttribute = attributes.SelectMany(a => a.AttributeClreplaced.GetBaseTypesAndThis())
.Any(baseType => baseType.Equals(_pxViewNameAttribute));
if (!viewHasViewNameAttribute)
{
var dac = viewInfo.Type.GetDacFromView(dacFinder.PxContext);
if (dac != null)
{
dacCandidates.Add(dac);
}
}
else
{
grapHasViewsWithViewNameAttribute = true;
}
}
return grapHasViewsWithViewNameAttribute
? dacCandidates
: Enumerable.Empty<ITypeSymbol>();
}
19
View Source File : AttributeInformation.cs
License : GNU General Public License v3.0
Project Creator : Acumatica
License : GNU General Public License v3.0
Project Creator : Acumatica
public IEnumerable<ITypeSymbol> GetAreplacedaticaAttributesFullList(ITypeSymbol attributeType, bool includeBaseTypes = false)
{
if (attributeType == null || attributeType.Equals(_eventSubscriberAttribute))
return Enumerable.Empty<ITypeSymbol>();
var baseAreplacedaticaAttributeTypes = attributeType.GetBaseTypesAndThis().ToList();
if (!baseAreplacedaticaAttributeTypes.Contains(_eventSubscriberAttribute))
return Enumerable.Empty<ITypeSymbol>();
HashSet<ITypeSymbol> results;
if (includeBaseTypes)
{
results = baseAreplacedaticaAttributeTypes.TakeWhile(a => !a.Equals(_eventSubscriberAttribute))
.ToHashSet();
}
else
{
results = new HashSet<ITypeSymbol>() { attributeType };
}
bool isAggregateAttribute = baseAreplacedaticaAttributeTypes.Contains(_aggregateAttribute) ||
baseAreplacedaticaAttributeTypes.Contains(_dynamicAggregateAttribute);
if (isAggregateAttribute)
{
var allAreplacedaticaAttributes = attributeType.GetAllAttributesDefinedOnThisAndBaseTypes()
.Where(attribute => attribute.InheritsFrom(_eventSubscriberAttribute));
foreach (var attribute in allAreplacedaticaAttributes)
{
CollectAggregatedAttribute(attribute, DefaultRecursionDepth);
}
}
return results;
void CollectAggregatedAttribute(ITypeSymbol aggregatedAttribute, int depth)
{
results.Add(aggregatedAttribute);
if (depth < 0)
return;
if (includeBaseTypes)
{
aggregatedAttribute.GetBaseTypes()
.TakeWhile(baseType => !baseType.Equals(_eventSubscriberAttribute))
.ForEach(baseType => results.Add(baseType));
}
if (IsAggregatorAttribute(aggregatedAttribute))
{
var allAreplacedaticaAttributes = aggregatedAttribute.GetAllAttributesDefinedOnThisAndBaseTypes()
.Where(attribute => attribute.InheritsFrom(_eventSubscriberAttribute));
foreach (var attribute in allAreplacedaticaAttributes)
{
CollectAggregatedAttribute(attribute, depth - 1);
}
}
}
}
19
View Source File : PXGraphSemanticModel.cs
License : GNU General Public License v3.0
Project Creator : Acumatica
License : GNU General Public License v3.0
Project Creator : Acumatica
private IEnumerable<GraphInitializerInfo> GetDeclaredInitializers()
{
_cancellation.ThrowIfCancellationRequested();
if (Type == GraphType.PXGraph)
{
return Symbol.GetDeclaredInstanceConstructors(_cancellation)
.Select((ctr, order) => new GraphInitializerInfo(GraphInitializerType.InstanceConstructor, ctr.Node, ctr.Symbol, order));
}
else if (Type == GraphType.PXGraphExtension)
{
(MethodDeclarationSyntax node, IMethodSymbol symbol) = Symbol.GetGraphExtensionInitialization(_pxContext, _cancellation);
if (node != null && symbol != null)
{
return new GraphInitializerInfo(GraphInitializerType.InitializeMethod, node, symbol, declarationOrder: 0)
.ToEnumerable();
}
}
return Enumerable.Empty<GraphInitializerInfo>();
}
19
View Source File : GraphSyntaxUtils.cs
License : GNU General Public License v3.0
Project Creator : Acumatica
License : GNU General Public License v3.0
Project Creator : Acumatica
internal static IEnumerable<(ITypeSymbol GraphSymbol, SyntaxNode GraphNode)> GetDeclaredGraphsAndExtensions(
this SyntaxNode root, SemanticModel semanticModel,
PXContext context, CancellationToken cancellationToken = default)
{
root.ThrowOnNull(nameof(root));
context.ThrowOnNull(nameof(context));
semanticModel.ThrowOnNull(nameof(semanticModel));
cancellationToken.ThrowIfCancellationRequested();
return context.IsPlatformReferenced
? GetDeclaredGraphsAndExtensionsImpl()
: Enumerable.Empty<(ITypeSymbol, SyntaxNode)>();
IEnumerable<(ITypeSymbol GraphSymbol, SyntaxNode GraphNode)> GetDeclaredGraphsAndExtensionsImpl()
{
var declaredClreplacedes = root.DescendantNodesAndSelf().OfType<ClreplacedDeclarationSyntax>();
foreach (ClreplacedDeclarationSyntax clreplacedNode in declaredClreplacedes)
{
ITypeSymbol clreplacedTypeSymbol = clreplacedNode.GetTypeSymbolFromClreplacedDeclaration(semanticModel, cancellationToken);
if (clreplacedTypeSymbol != null && clreplacedTypeSymbol.IsPXGrapreplacedxtension(context))
{
yield return (clreplacedTypeSymbol, clreplacedNode);
}
}
}
}
19
View Source File : PXColorizerMainTagger.cs
License : GNU General Public License v3.0
Project Creator : Acumatica
License : GNU General Public License v3.0
Project Creator : Acumatica
protected internal override IEnumerable<ITagSpan<IClreplacedificationTag>> GetTagsSynchronousImplementation(ITextSnapshot snapshot)
{
TaggerType currentTaggerType = GetCurrentTaggerTypeFromSettings();
if (!_taggersByType.TryGetValue(currentTaggerType, out PXColorizerTaggerBase activeTagger))
return Enumerable.Empty<ITagSpan<IClreplacedificationTag>>();
return activeTagger.GetTagsSynchronousImplementation(snapshot);
}
19
View Source File : PXColorizerMainTagger.cs
License : GNU General Public License v3.0
Project Creator : Acumatica
License : GNU General Public License v3.0
Project Creator : Acumatica
protected internal override Task<IEnumerable<ITagSpan<IClreplacedificationTag>>> GetTagsAsyncImplementationAsync(ITextSnapshot snapshot,
CancellationToken cancellationToken)
{
TaggerType currentTaggerType = GetCurrentTaggerTypeFromSettings();
if (!_taggersByType.TryGetValue(currentTaggerType, out PXColorizerTaggerBase activeTagger))
return Task.FromResult(Enumerable.Empty<ITagSpan<IClreplacedificationTag>>());
if (activeTagger.UseAsyncTagging)
{
return activeTagger.GetTagsAsyncImplementationAsync(snapshot, cancellationToken);
}
else
{
var tags = activeTagger.GetTagsSynchronousImplementation(snapshot);
return Task.FromResult(tags);
}
}
19
View Source File : PXOutliningTagger.cs
License : GNU General Public License v3.0
Project Creator : Acumatica
License : GNU General Public License v3.0
Project Creator : Acumatica
public IEnumerable<ITagSpan<IOutliningRegionTag>> GetTags(NormalizedSnapshotSpanCollection spans)
{
if (spans == null || spans.Count == 0 || AreplacedinatorVSPackage.Instance?.UseBqlOutlining != true)
return Enumerable.Empty<ITagSpan<IOutliningRegionTag>>();
if (ColorizerTagger == null)
{
if (!TryGetColorizingTaggerFromBuffer(Buffer, out PXColorizerTaggerBase colorizingTagger) || colorizingTagger == null)
return Enumerable.Empty<ITagSpan<IOutliningRegionTag>>();
SubscribeToColorizingTaggerEvents(colorizingTagger);
}
switch (ColorizerTagger?.TaggerType)
{
case TaggerType.General when AreplacedinatorVSPackage.Instance?.UseRegexColoring == true:
case TaggerType.RegEx:
case null:
return Enumerable.Empty<ITagSpan<IOutliningRegionTag>>();
}
return ColorizerTagger.OutliningsTagsCache.ProcessedTags;
}
19
View Source File : PXRegexColorizerTagger.cs
License : GNU General Public License v3.0
Project Creator : Acumatica
License : GNU General Public License v3.0
Project Creator : Acumatica
protected internal async override Task<IEnumerable<ITagSpan<IClreplacedificationTag>>> GetTagsAsyncImplementationAsync(ITextSnapshot snapshot,
CancellationToken cancellationToken)
{
var taggingInfo = await Task.Run(() => GetTagsSynchronousImplementation(snapshot))
.TryAwait();
if (!taggingInfo.IsSuccess)
return Enumerable.Empty<ITagSpan<IClreplacedificationTag>>();
return taggingInfo.Result;
}
19
View Source File : PXColorizerTaggerBase.cs
License : GNU General Public License v3.0
Project Creator : Acumatica
License : GNU General Public License v3.0
Project Creator : Acumatica
public virtual IEnumerable<ITagSpan<IClreplacedificationTag>> GetTags(NormalizedSnapshotSpanCollection spans)
{
if (spans == null || spans.Count == 0 || AreplacedinatorVSPackage.Instance?.ColoringEnabled != true)
return Enumerable.Empty<ITagSpan<IClreplacedificationTag>>();
ITextSnapshot snapshot = spans[0].Snapshot;
if (CheckIfRetaggingIsNotNecessary(snapshot))
{
return ClreplacedificationTagsCache.ProcessedTags;
}
if (UseAsyncTagging)
{
return GetTagsAsync(snapshot);
}
else
{
ResetCacheAndFlags(snapshot);
return GetTagsSynchronousImplementation(snapshot);
}
}
19
View Source File : CodeMapSubtreeSorter.cs
License : GNU General Public License v3.0
Project Creator : Acumatica
License : GNU General Public License v3.0
Project Creator : Acumatica
public override void DefaultVisit(TreeNodeViewModel node)
{
if (node == null || SortContext == null)
return;
node.ChildrenSortType = SortContext.SortType;
node.ChildrenSortDirection = SortContext.SortDirection;
if (node.Children.Count == 0)
return;
else if (node.Children.Count > 1) //Optimization for single element collections - do not sort and reset them
{
var sorted = NodesSorter.SortNodes(node.Children, SortContext.SortType, SortContext.SortDirection)
?.ToList(capacity: node.Children.Count)
?? Enumerable.Empty<TreeNodeViewModel>();
node.Children.Reset(sorted);
}
if (SortContext.SortDescendants)
{
base.DefaultVisit(node);
}
}
19
View Source File : VisualTreeUtils.cs
License : GNU General Public License v3.0
Project Creator : Acumatica
License : GNU General Public License v3.0
Project Creator : Acumatica
public static IEnumerable<FrameworkElement> GetVisualDescendants(this FrameworkElement uiElement)
{
uiElement.ThrowOnNull(nameof(uiElement));
int elementChildrenCount = VisualTreeHelper.GetChildrenCount(uiElement);
if (elementChildrenCount == 0)
return Enumerable.Empty<FrameworkElement>();
return GetVisualDescendantsImpl(uiElement, elementChildrenCount);
//-------------------------------------------Local function-----------------------------------
IEnumerable<FrameworkElement> GetVisualDescendantsImpl(FrameworkElement parent, int childrenCount)
{
for (int i = 0; i < childrenCount; i++)
{
var child = VisualTreeHelper.GetChild(parent, i) as FrameworkElement;
if (child == null)
continue;
yield return child;
int grandchildrenCount = VisualTreeHelper.GetChildrenCount(child);
foreach (var descendant in GetVisualDescendantsImpl(child, grandchildrenCount).OfType<FrameworkElement>())
{
yield return descendant;
}
}
}
}
19
View Source File : DefaultCodeMapTreeBuilder_Graph.cs
License : GNU General Public License v3.0
Project Creator : Acumatica
License : GNU General Public License v3.0
Project Creator : Acumatica
protected virtual IEnumerable<TreeNodeViewModel> CreateEventsCategoryChildren<TGraphEventInfo>(GraphEventCategoryNodeViewModel graphEventCategory,
DacVmConstructor<TGraphEventInfo> constructor)
where TGraphEventInfo : GraphEventInfoBase<TGraphEventInfo>
{
graphEventCategory.ThrowOnNull(nameof(graphEventCategory));
var graphSemanticModel = graphEventCategory.GraphViewModel.GraphSemanticModel;
var graphCategoryEvents = graphEventCategory.GetCategoryGraphNodeSymbols()
?.OfType<TGraphEventInfo>()
.Where(eventInfo => eventInfo.SignatureType != EventHandlerSignatureType.None);
if (graphCategoryEvents.IsNullOrEmpty())
return Enumerable.Empty<TreeNodeViewModel>();
Cancellation.ThrowIfCancellationRequested();
var dacGroupingNodesViewModels = from eventInfo in graphCategoryEvents
where eventInfo.Symbol.ContainingType == graphSemanticModel.Symbol ||
eventInfo.Symbol.ContainingType.OriginalDefinition == graphSemanticModel.Symbol.OriginalDefinition
group eventInfo by eventInfo.DacName into graphEventsForDAC
select constructor(graphEventCategory, graphEventsForDAC.Key, graphEventsForDAC) into dacNodeVM
where dacNodeVM != null
select dacNodeVM;
return dacGroupingNodesViewModels;
}
See More Examples