IHighlightingDefinition GetDefinition() { Func<IHighlightingDefinition> func; lock (lockObj) { if (this.definition != null) return this.definition; func = this.lazyLoadingFunction; } Exception exception = null; IHighlightingDefinition def = null; try { using (var busyLock = BusyManager.Enter(this)) { if (!busyLock.Success) throw new InvalidOperationException("Tried to create delay-loaded highlighting definition recursively. Make sure the are no cyclic references between the highlighting definitions."); def = func(); } if (def == null) throw new InvalidOperationException("Function for delay-loading highlighting definition returned null"); } catch (Exception ex) { exception = ex; } lock (lockObj) { this.lazyLoadingFunction = null; if (this.definition == null && this.storedException == null) { this.definition = def; this.storedException = exception; } if (this.storedException != null) throw new HighlightingDefinitionInvalidException("Error delay-loading highlighting definition", this.storedException); return this.definition; } }
public IEnumerable <IMethod> GetConstructors(Predicate <IMethod> filter = null, GetMemberOptions options = GetMemberOptions.IgnoreInheritedMembers) { if (Kind == TypeKind.Void) { return(EmptyList <IMethod> .Instance); } if (ComHelper.IsComImport(this)) { IType coClass = ComHelper.GetCoClass(this); using (var busyLock = BusyManager.Enter(this)) { if (busyLock.Success) { return(coClass.GetConstructors(filter, options) .Select(m => new SpecializedMethod(m, m.Substitution) { DeclaringType = this })); } } return(EmptyList <IMethod> .Instance); } if ((options & GetMemberOptions.IgnoreInheritedMembers) == GetMemberOptions.IgnoreInheritedMembers) { return(GetFiltered(this.Methods, ExtensionMethods.And(m => m.IsConstructor && !m.IsStatic, filter))); } else { return(GetMembersHelper.GetConstructors(this, filter, options)); } }
string[] GetInternalsVisibleTo() { var result = this.internalsVisibleTo; if (result != null) { return(result); } else { using (var busyLock = BusyManager.Enter(this)) { Debug.Assert(busyLock.Success); if (!busyLock.Success) { return(new string[0]); } internalsVisibleTo = ( from attr in this.AssemblyAttributes where attr.AttributeType.Name == "InternalsVisibleToAttribute" && attr.AttributeType.Namespace == "System.Runtime.CompilerServices" && attr.PositionalArguments.Count == 1 select GetShortName(attr.PositionalArguments.Single().ConstantValue as string) ).ToArray(); } return(internalsVisibleTo); } }
public virtual IEnumerable <IEvent> GetEvents(ITypeResolveContext context, Predicate <IEvent> filter = null) { ITypeDefinition compound = GetCompoundClass(); if (compound != this) { return(compound.GetEvents(context, filter)); } List <IEvent> events = new List <IEvent>(); using (var busyLock = BusyManager.Enter(this)) { if (busyLock.Success) { int baseCount = 0; foreach (var baseType in GetBaseTypes(context)) { ITypeDefinition baseTypeDef = baseType.GetDefinition(); if (baseTypeDef != null && (baseTypeDef.ClassType != ClassType.Interface || this.ClassType == ClassType.Interface)) { events.AddRange(baseType.GetEvents(context, filter)); baseCount++; } } if (baseCount > 1) { RemoveDuplicates(events); } AddFilteredRange(events, this.Events, filter); } } return(events); }
public virtual IEnumerable <IMethod> GetMethods(ITypeResolveContext context, Predicate <IMethod> filter = null) { ITypeDefinition compound = GetCompoundClass(); if (compound != this) { return(compound.GetMethods(context, filter)); } List <IMethod> methods = new List <IMethod>(); using (var busyLock = BusyManager.Enter(this)) { if (busyLock.Success) { int baseCount = 0; foreach (var baseType in GetBaseTypes(context)) { ITypeDefinition baseTypeDef = baseType.GetDefinition(); if (baseTypeDef != null && (baseTypeDef.ClassType != ClassType.Interface || this.ClassType == ClassType.Interface)) { methods.AddRange(baseType.GetMethods(context, filter)); baseCount++; } } if (baseCount > 1) { RemoveDuplicates(methods); } AddFilteredRange(methods, this.Methods.Where(m => !m.IsConstructor), filter); } } return(methods); }
private async void LoadModel(string fileName) { CloseBackstage(); BusyManager.SetBusy(0, 100, "LoadModel"); var bimStore3D = await ImportManager.LoadAsync(fileName); var model = new BimStore3DViewModel(bimStore3D, MaterialManager); View3DManager.SetModel(model); BusyManager.SetFree(); }
void ISupportsInterning.PrepareForInterning(IInterningProvider provider) { // protect against cyclic constraints using (var busyLock = BusyManager.Enter(this)) { if (busyLock.Success) { constraints = provider.InternList(constraints); attributes = provider.InternList(attributes); } } }
public MainWindowViewModel() { MaterialManager = new MaterialManagerModel(); ImportManager = new ImportManagerModel((i, o) => { BusyManager.SetValue(i); BusyManager.SetMessage(o as string); }, MaterialManager); View3DManager = new View3DManagerModel(); BimModelsMostRecentlyUsedManager = new BimModelsMostRecentlyUsedManagerModel(); BusyManager = new BusyManagerModel(); VisualizerManager = new VisualizerManagerModel(MaterialManager); }
IType ResolveForwardedType(ExportedType forwarder) { IModule module = ResolveModule(forwarder); var typeName = forwarder.GetFullTypeName(metadata); if (module == null) { return(new UnknownType(typeName)); } using (var busyLock = BusyManager.Enter(this)) { if (busyLock.Success) { var td = module.GetTypeDefinition(typeName); if (td != null) { return(td); } } } return(new UnknownType(typeName)); IModule ResolveModule(ExportedType type) { switch (type.Implementation.Kind) { case HandleKind.AssemblyFile: // TODO : Resolve assembly file (module)... return(this); case HandleKind.ExportedType: var outerType = metadata.GetExportedType((ExportedTypeHandle)type.Implementation); return(ResolveModule(outerType)); case HandleKind.AssemblyReference: var asmRef = metadata.GetAssemblyReference((AssemblyReferenceHandle)type.Implementation); string shortName = metadata.GetString(asmRef.Name); foreach (var asm in Compilation.Modules) { if (string.Equals(asm.AssemblyName, shortName, StringComparison.OrdinalIgnoreCase)) { return(asm); } } return(null); default: throw new BadImageFormatException("Expected implementation to be either an AssemblyFile, ExportedType or AssemblyReference."); } } }
IType CalculateEffectiveBaseClass() { // protect against cyclic type parameters using (var busyLock = BusyManager.Enter(this)) { if (!busyLock.Success) { return(SpecialType.UnknownType); } if (HasValueTypeConstraint) { return(this.Compilation.FindType(KnownTypeCode.ValueType)); } List <IType> classTypeConstraints = new List <IType>(); foreach (IType constraint in this.DirectBaseTypes) { if (constraint.Kind == TypeKind.Class) { classTypeConstraints.Add(constraint); } else if (constraint.Kind == TypeKind.TypeParameter) { IType baseClass = ((ITypeParameter)constraint).EffectiveBaseClass; if (baseClass.Kind == TypeKind.Class) { classTypeConstraints.Add(baseClass); } } } if (classTypeConstraints.Count == 0) { return(this.Compilation.FindType(KnownTypeCode.Object)); } // Find the derived-most type in the resulting set: IType result = classTypeConstraints[0]; for (int i = 1; i < classTypeConstraints.Count; i++) { if (classTypeConstraints[i].GetDefinition().IsDerivedFrom(result.GetDefinition())) { result = classTypeConstraints[i]; } } return(result); } }
public ITypeDefinition GetTypeDefinition(TopLevelTypeName topLevelTypeName) { IUnresolvedTypeDefinition td; ITypeReference typeRef; if (unresolvedAssembly.typeDefinitions.TryGetValue(topLevelTypeName, out td)) { return(GetTypeDefinition(td)); } if (unresolvedAssembly.typeForwarders.TryGetValue(topLevelTypeName, out typeRef)) { // Protect against cyclic type forwarders: using (var busyLock = BusyManager.Enter(typeRef)) { if (busyLock.Success) { return(typeRef.Resolve(compilation.TypeResolveContext).GetDefinition()); } } } return(null); }
public override ResolveResult Resolve(CSharpResolver resolver) { ResolveResult targetRR = target.Resolve(resolver); if (targetRR.IsError) { return(targetRR); } IList <IType> typeArgs = typeArguments.Resolve(resolver.CurrentTypeResolveContext); using (var busyLock = BusyManager.Enter(this)) { if (busyLock.Success) { return(resolver.ResolveMemberType(targetRR, identifier, typeArgs)); } else { // This can happen for "class Test : $Test.Base$ { public class Base {} }": return(ErrorResolveResult.UnknownError); // don't cache this error } } }
public bool?IsReferenceType(ITypeResolveContext context) { switch (flags.Data & (FlagReferenceTypeConstraint | FlagValueTypeConstraint)) { case FlagReferenceTypeConstraint: return(true); case FlagValueTypeConstraint: return(false); } // protect against cyclic dependencies between type parameters using (var busyLock = BusyManager.Enter(this)) { if (busyLock.Success) { foreach (ITypeReference constraintRef in this.Constraints) { IType constraint = constraintRef.Resolve(context); ITypeDefinition constraintDef = constraint.GetDefinition(); // While interfaces are reference types, an interface constraint does not // force the type parameter to be a reference type; so we need to explicitly look for classes here. if (constraintDef != null && constraintDef.Kind == TypeKind.Class) { return(true); } if (constraint is ITypeParameter) { bool?isReferenceType = constraint.IsReferenceType(context); if (isReferenceType.HasValue) { return(isReferenceType.Value); } } } } } return(null); }
public virtual IEnumerable <IType> GetNestedTypes(ITypeResolveContext context, Predicate <ITypeDefinition> filter = null) { ITypeDefinition compound = GetCompoundClass(); if (compound != this) { return(compound.GetNestedTypes(context, filter)); } List <IType> nestedTypes = new List <IType>(); using (var busyLock = BusyManager.Enter(this)) { if (busyLock.Success) { foreach (var baseTypeRef in this.BaseTypes) { IType baseType = baseTypeRef.Resolve(context); ITypeDefinition baseTypeDef = baseType.GetDefinition(); if (baseTypeDef != null && baseTypeDef.ClassType != ClassType.Interface) { // get nested types from baseType (not baseTypeDef) so that generics work correctly nestedTypes.AddRange(baseType.GetNestedTypes(context, filter)); break; // there is at most 1 non-interface base } } foreach (ITypeDefinition nestedType in this.NestedTypes) { if (filter == null || filter(nestedType)) { nestedTypes.Add(nestedType); } } } } return(nestedTypes); }