diff --git a/build/dependencies.props b/build/dependencies.props index b6a1ad60ce..37ead2dfab 100644 --- a/build/dependencies.props +++ b/build/dependencies.props @@ -29,9 +29,9 @@ 16.0.142-g25b7188c54 16.0.142-g25b7188c54 7.10.6071 - 15.8.243 + 16.0.201-pre-g7d366164d0 2.0.6142705 - 15.8.243 + 16.0.201-pre-g7d366164d0 15.8.28010 10.0.30320 11.0.61031 diff --git a/build/sources.props b/build/sources.props index 02efac4549..b6c5726ce5 100644 --- a/build/sources.props +++ b/build/sources.props @@ -11,7 +11,8 @@ https://dotnet.myget.org/F/msbuild/api/v3/index.json; https://dotnet.myget.org/F/roslyn/api/v3/index.json; https://vside.myget.org/F/vssdk/api/v3/index.json; - https://vside.myget.org/F/vsmac/api/v3/index.json + https://vside.myget.org/F/vsmac/api/v3/index.json; + https://vside.myget.org/F/devcore/api/v3/index.json; $(RestoreSources); diff --git a/src/Microsoft.VisualStudio.LanguageServices.Razor/Microsoft.VisualStudio.LanguageServices.Razor.csproj b/src/Microsoft.VisualStudio.LanguageServices.Razor/Microsoft.VisualStudio.LanguageServices.Razor.csproj index 5dcbf78723..15e4085185 100644 --- a/src/Microsoft.VisualStudio.LanguageServices.Razor/Microsoft.VisualStudio.LanguageServices.Razor.csproj +++ b/src/Microsoft.VisualStudio.LanguageServices.Razor/Microsoft.VisualStudio.LanguageServices.Razor.csproj @@ -13,7 +13,6 @@ $(DefineConstants);RAZOR_EXTENSION_DEVELOPER_MODE - @@ -24,6 +23,7 @@ + diff --git a/src/Microsoft.VisualStudio.LanguageServices.Razor/ProjectSystem/Rules/RazorConfiguration.cs b/src/Microsoft.VisualStudio.LanguageServices.Razor/ProjectSystem/Rules/RazorConfiguration.cs index d8c2484f5b..a21bc050c9 100644 --- a/src/Microsoft.VisualStudio.LanguageServices.Razor/ProjectSystem/Rules/RazorConfiguration.cs +++ b/src/Microsoft.VisualStudio.LanguageServices.Razor/ProjectSystem/Rules/RazorConfiguration.cs @@ -8,205 +8,268 @@ // //------------------------------------------------------------------------------ -namespace Microsoft.CodeAnalysis.Razor.ProjectSystem.Rules { - - - internal partial class RazorConfiguration { - - /// Backing field for deserialized rule.. - private static Microsoft.Build.Framework.XamlTypes.Rule deserializedFallbackRule; - - /// The name of the schema to look for at runtime to fulfill property access. - internal const string SchemaName = "RazorConfiguration"; - - /// The ItemType given in the Rule.DataSource property. May not apply to every Property's individual DataSource. - internal const string PrimaryDataSourceItemType = "RazorConfiguration"; - - /// The Label given in the Rule.DataSource property. May not apply to every Property's individual DataSource. - internal const string PrimaryDataSourceLabel = ""; - - /// Razor Extensions (The "Extensions" property). - internal const string ExtensionsProperty = "Extensions"; - - /// Backing field for the property. - private Microsoft.VisualStudio.ProjectSystem.Properties.IRule rule; - - /// Backing field for the file name of the rule property. - private string file; - - /// Backing field for the ItemType property. - private string itemType; - - /// Backing field for the ItemName property. - private string itemName; - - /// Configured Project - private Microsoft.VisualStudio.ProjectSystem.ConfiguredProject configuredProject; - - /// The dictionary of named catalogs. - private System.Collections.Immutable.IImmutableDictionary catalogs; - - /// Backing field for the property. - private Microsoft.VisualStudio.ProjectSystem.Properties.IRule fallbackRule; - - /// Thread locking object - private object locker = new object(); - - /// Initializes a new instance of the RazorConfiguration class. - internal RazorConfiguration(Microsoft.VisualStudio.ProjectSystem.Properties.IRule rule) { - this.rule = rule; - } - - /// Initializes a new instance of the RazorConfiguration class. - internal RazorConfiguration(Microsoft.VisualStudio.ProjectSystem.ConfiguredProject configuredProject, System.Collections.Immutable.IImmutableDictionary catalogs, string context, string file, string itemType, string itemName) : - this(GetRule(System.Collections.Immutable.ImmutableDictionary.GetValueOrDefault(catalogs, context), file, itemType, itemName)) { - if ((configuredProject == null)) { - throw new System.ArgumentNullException("configuredProject"); - } - this.configuredProject = configuredProject; - this.catalogs = catalogs; - this.file = file; - this.itemType = itemType; - this.itemName = itemName; - } - - /// Initializes a new instance of the RazorConfiguration class. - internal RazorConfiguration(Microsoft.VisualStudio.ProjectSystem.Properties.IRule rule, Microsoft.VisualStudio.ProjectSystem.ConfiguredProject configuredProject) : - this(rule) { - if ((rule == null)) { - throw new System.ArgumentNullException("rule"); - } - if ((configuredProject == null)) { - throw new System.ArgumentNullException("configuredProject"); - } - this.configuredProject = configuredProject; - this.rule = rule; - this.file = this.rule.File; - this.itemType = this.rule.ItemType; - this.itemName = this.rule.ItemName; - } - - /// Initializes a new instance of the RazorConfiguration class. - internal RazorConfiguration(Microsoft.VisualStudio.ProjectSystem.ConfiguredProject configuredProject, System.Collections.Immutable.IImmutableDictionary catalogs, string context, Microsoft.VisualStudio.ProjectSystem.Properties.IProjectPropertiesContext propertyContext) : - this(configuredProject, catalogs, context, GetContextFile(propertyContext), propertyContext.ItemType, propertyContext.ItemName) { - } - - /// Initializes a new instance of the RazorConfiguration class that assumes a project context (neither property sheet nor items). - internal RazorConfiguration(Microsoft.VisualStudio.ProjectSystem.ConfiguredProject configuredProject, System.Collections.Immutable.IImmutableDictionary catalogs) : - this(configuredProject, catalogs, "Project", null, null, null) { - } - - /// Gets the IRule used to get and set properties. - public Microsoft.VisualStudio.ProjectSystem.Properties.IRule Rule { - get { - return this.rule; - } - } - - /// Razor Extensions - internal Microsoft.VisualStudio.ProjectSystem.Properties.IEvaluatedProperty Extensions { - get { - Microsoft.VisualStudio.ProjectSystem.Properties.IRule localRule = this.rule; - if ((localRule == null)) { - localRule = this.GeneratedFallbackRule; - } - if ((localRule == null)) { - return null; - } - Microsoft.VisualStudio.ProjectSystem.Properties.IEvaluatedProperty property = ((Microsoft.VisualStudio.ProjectSystem.Properties.IEvaluatedProperty)(localRule.GetProperty(ExtensionsProperty))); - if (((property == null) - && (this.GeneratedFallbackRule != null))) { - localRule = this.GeneratedFallbackRule; - property = ((Microsoft.VisualStudio.ProjectSystem.Properties.IEvaluatedProperty)(localRule.GetProperty(ExtensionsProperty))); - } - return property; - } - } - - /// Get the fallback rule if the current rule on disk is missing or a property in the rule on disk is missing - private Microsoft.VisualStudio.ProjectSystem.Properties.IRule GeneratedFallbackRule { - get { - if (((this.fallbackRule == null) - && (this.configuredProject != null))) { - System.Threading.Monitor.Enter(this.locker); - try { - if ((this.fallbackRule == null)) { - this.InitializeFallbackRule(); - } - } - finally { - System.Threading.Monitor.Exit(this.locker); - } - } - return this.fallbackRule; - } - } - - private static Microsoft.VisualStudio.ProjectSystem.Properties.IRule GetRule(Microsoft.VisualStudio.ProjectSystem.Properties.IPropertyPagesCatalog catalog, string file, string itemType, string itemName) { - if ((catalog == null)) { - return null; - } - return catalog.BindToContext(SchemaName, file, itemType, itemName); - } - - private static string GetContextFile(Microsoft.VisualStudio.ProjectSystem.Properties.IProjectPropertiesContext propertiesContext) { - if ((propertiesContext.IsProjectFile == true)) { - return null; - } - else { - return propertiesContext.File; - } - } - - private void InitializeFallbackRule() { - if ((this.configuredProject == null)) { - return; - } - Microsoft.Build.Framework.XamlTypes.Rule unboundRule = RazorConfiguration.deserializedFallbackRule; - if ((unboundRule == null)) { - System.IO.Stream xamlStream = null; - System.Reflection.Assembly thisAssembly = System.Reflection.Assembly.GetExecutingAssembly(); - try { - xamlStream = thisAssembly.GetManifestResourceStream("XamlRuleToCode:RazorConfiguration.xaml"); - Microsoft.Build.Framework.XamlTypes.IProjectSchemaNode root = ((Microsoft.Build.Framework.XamlTypes.IProjectSchemaNode)(System.Xaml.XamlServices.Load(xamlStream))); - System.Collections.Generic.IEnumerator ruleEnumerator = root.GetSchemaObjects(typeof(Microsoft.Build.Framework.XamlTypes.Rule)).GetEnumerator(); - for ( - ; ((unboundRule == null) - && ruleEnumerator.MoveNext()); - ) { - Microsoft.Build.Framework.XamlTypes.Rule t = ((Microsoft.Build.Framework.XamlTypes.Rule)(ruleEnumerator.Current)); - if (System.StringComparer.OrdinalIgnoreCase.Equals(t.Name, SchemaName)) { - unboundRule = t; - unboundRule.Name = "30e71838-2cb8-4c67-ab28-7670763124af"; - RazorConfiguration.deserializedFallbackRule = unboundRule; - } - } - } - finally { - if ((xamlStream != null)) { - ((System.IDisposable)(xamlStream)).Dispose(); - } - } - } - this.configuredProject.Services.AdditionalRuleDefinitions.AddRuleDefinition(unboundRule, "FallbackRuleCodeGenerationContext"); - Microsoft.VisualStudio.ProjectSystem.Properties.IPropertyPagesCatalog catalog = this.configuredProject.Services.PropertyPagesCatalog.GetMemoryOnlyCatalog("FallbackRuleCodeGenerationContext"); - this.fallbackRule = catalog.BindToContext(unboundRule.Name, this.file, this.itemType, this.itemName); - } - } - - internal partial class RazorProjectProperties { - - private static System.Func>, object, RazorConfiguration> CreateRazorConfigurationPropertiesDelegate = new System.Func>, object, RazorConfiguration>(CreateRazorConfigurationProperties); - - private static RazorConfiguration CreateRazorConfigurationProperties(System.Threading.Tasks.Task> namedCatalogs, object state) { - RazorProjectProperties that = ((RazorProjectProperties)(state)); - return new RazorConfiguration(that.ConfiguredProject, namedCatalogs.Result, "Project", that.File, that.ItemType, that.ItemName); - } - - /// Gets the strongly-typed property accessor used to get and set Configuration Properties properties. - internal System.Threading.Tasks.Task GetRazorConfigurationPropertiesAsync() { - System.Threading.Tasks.Task> namedCatalogsTask = this.GetNamedCatalogsAsync(); - return namedCatalogsTask.ContinueWith(CreateRazorConfigurationPropertiesDelegate, this, System.Threading.CancellationToken.None, System.Threading.Tasks.TaskContinuationOptions.ExecuteSynchronously, System.Threading.Tasks.TaskScheduler.Default); - } - } +namespace Microsoft.CodeAnalysis.Razor.ProjectSystem.Rules +{ + + + internal partial class RazorConfiguration + { + + /// Backing field for deserialized rule.. + private static Microsoft.Build.Framework.XamlTypes.Rule deserializedFallbackRule; + + /// The name of the schema to look for at runtime to fulfill property access. + internal const string SchemaName = "RazorConfiguration"; + + /// The ItemType given in the Rule.DataSource property. May not apply to every Property's individual DataSource. + internal const string PrimaryDataSourceItemType = "RazorConfiguration"; + + /// The Label given in the Rule.DataSource property. May not apply to every Property's individual DataSource. + internal const string PrimaryDataSourceLabel = ""; + + /// Razor Extensions (The "Extensions" property). + internal const string ExtensionsProperty = "Extensions"; + + /// Backing field for the property. + private Microsoft.VisualStudio.ProjectSystem.Properties.IRule rule; + + /// Backing field for the file name of the rule property. + private string file; + + /// Backing field for the ItemType property. + private string itemType; + + /// Backing field for the ItemName property. + private string itemName; + + /// Configured Project + private Microsoft.VisualStudio.ProjectSystem.ConfiguredProject configuredProject; + + /// The dictionary of named catalogs. + private System.Collections.Immutable.IImmutableDictionary catalogs; + + /// Backing field for the property. + private Microsoft.VisualStudio.ProjectSystem.Properties.IRule fallbackRule; + + /// Thread locking object + private object locker = new object(); + + /// Initializes a new instance of the RazorConfiguration class. + internal RazorConfiguration(Microsoft.VisualStudio.ProjectSystem.Properties.IRule rule) + { + this.rule = rule; + } + + /// Initializes a new instance of the RazorConfiguration class. + internal RazorConfiguration(Microsoft.VisualStudio.ProjectSystem.ConfiguredProject configuredProject, System.Collections.Immutable.IImmutableDictionary catalogs, string context, string file, string itemType, string itemName) : + this(GetRule(System.Collections.Immutable.ImmutableDictionary.GetValueOrDefault(catalogs, context), file, itemType, itemName)) + { + if ((configuredProject == null)) + { + throw new System.ArgumentNullException("configuredProject"); + } + this.configuredProject = configuredProject; + this.catalogs = catalogs; + this.file = file; + this.itemType = itemType; + this.itemName = itemName; + } + + /// Initializes a new instance of the RazorConfiguration class. + internal RazorConfiguration(Microsoft.VisualStudio.ProjectSystem.Properties.IRule rule, Microsoft.VisualStudio.ProjectSystem.ConfiguredProject configuredProject) : + this(rule) + { + if ((rule == null)) + { + throw new System.ArgumentNullException("rule"); + } + if ((configuredProject == null)) + { + throw new System.ArgumentNullException("configuredProject"); + } + this.configuredProject = configuredProject; + this.rule = rule; + this.file = this.rule.File; + this.itemType = this.rule.ItemType; + this.itemName = this.rule.ItemName; + } + + /// Initializes a new instance of the RazorConfiguration class. + internal RazorConfiguration(Microsoft.VisualStudio.ProjectSystem.ConfiguredProject configuredProject, System.Collections.Immutable.IImmutableDictionary catalogs, string context, Microsoft.VisualStudio.ProjectSystem.Properties.IProjectPropertiesContext propertyContext) : + this(configuredProject, catalogs, context, GetContextFile(propertyContext), propertyContext.ItemType, propertyContext.ItemName) + { + } + + /// Initializes a new instance of the RazorConfiguration class that assumes a project context (neither property sheet nor items). + internal RazorConfiguration(Microsoft.VisualStudio.ProjectSystem.ConfiguredProject configuredProject, System.Collections.Immutable.IImmutableDictionary catalogs) : + this(configuredProject, catalogs, "Project", null, null, null) + { + } + + /// Gets the IRule used to get and set properties. + public Microsoft.VisualStudio.ProjectSystem.Properties.IRule Rule + { + get + { + return this.rule; + } + } + + /// Razor Extensions + internal Microsoft.VisualStudio.ProjectSystem.Properties.IEvaluatedProperty Extensions + { + get + { + Microsoft.VisualStudio.ProjectSystem.Properties.IRule localRule = this.rule; + if ((localRule == null)) + { + localRule = this.GeneratedFallbackRule; + } + if ((localRule == null)) + { + return null; + } + Microsoft.VisualStudio.ProjectSystem.Properties.IEvaluatedProperty property = ((Microsoft.VisualStudio.ProjectSystem.Properties.IEvaluatedProperty)(localRule.GetProperty(ExtensionsProperty))); + if (((property == null) + && (this.GeneratedFallbackRule != null))) + { + localRule = this.GeneratedFallbackRule; + property = ((Microsoft.VisualStudio.ProjectSystem.Properties.IEvaluatedProperty)(localRule.GetProperty(ExtensionsProperty))); + } + return property; + } + } + + /// Get the fallback rule if the current rule on disk is missing or a property in the rule on disk is missing + private Microsoft.VisualStudio.ProjectSystem.Properties.IRule GeneratedFallbackRule + { + get + { + if (((this.fallbackRule == null) + && (this.configuredProject != null))) + { + System.Threading.Monitor.Enter(this.locker); + try + { + if ((this.fallbackRule == null)) + { + this.InitializeFallbackRule(); + } + } + finally + { + System.Threading.Monitor.Exit(this.locker); + } + } + return this.fallbackRule; + } + } + + private static Microsoft.VisualStudio.ProjectSystem.Properties.IRule GetRule(Microsoft.VisualStudio.ProjectSystem.Properties.IPropertyPagesCatalog catalog, string file, string itemType, string itemName) + { + if ((catalog == null)) + { + return null; + } + return catalog.BindToContext(SchemaName, file, itemType, itemName); + } + + private static string GetContextFile(Microsoft.VisualStudio.ProjectSystem.Properties.IProjectPropertiesContext propertiesContext) + { + if ((propertiesContext.IsProjectFile == true)) + { + return null; + } + else + { + return propertiesContext.File; + } + } + + private void InitializeFallbackRule() + { + if ((this.configuredProject == null)) + { + return; + } + Microsoft.Build.Framework.XamlTypes.Rule unboundRule = RazorConfiguration.deserializedFallbackRule; + if ((unboundRule == null)) + { + System.IO.Stream xamlStream = null; + System.Reflection.Assembly thisAssembly = System.Reflection.Assembly.GetExecutingAssembly(); + try + { + xamlStream = thisAssembly.GetManifestResourceStream("XamlRuleToCode:RazorConfiguration.xaml"); + Microsoft.Build.Framework.XamlTypes.IProjectSchemaNode root = ((Microsoft.Build.Framework.XamlTypes.IProjectSchemaNode)(System.Xaml.XamlServices.Load(xamlStream))); + System.Collections.Generic.IEnumerator ruleEnumerator = root.GetSchemaObjects(typeof(Microsoft.Build.Framework.XamlTypes.Rule)).GetEnumerator(); + for ( + ; ((unboundRule == null) + && ruleEnumerator.MoveNext()); + ) + { + Microsoft.Build.Framework.XamlTypes.Rule t = ((Microsoft.Build.Framework.XamlTypes.Rule)(ruleEnumerator.Current)); + if (System.StringComparer.OrdinalIgnoreCase.Equals(t.Name, SchemaName)) + { + unboundRule = t; + unboundRule.Name = "f269edfbdecc0079d5f539c22552711e194f39b2367903515ae5440a64b20a0f"; + RazorConfiguration.deserializedFallbackRule = unboundRule; + } + } + } + finally + { + if ((xamlStream != null)) + { + ((System.IDisposable)(xamlStream)).Dispose(); + } + } + } + this.configuredProject.Services.AdditionalRuleDefinitions.AddRuleDefinition(unboundRule, "FallbackRuleCodeGenerationContext"); + Microsoft.VisualStudio.ProjectSystem.Properties.IPropertyPagesCatalog catalog = this.configuredProject.Services.PropertyPagesCatalog.GetMemoryOnlyCatalog("FallbackRuleCodeGenerationContext"); + this.fallbackRule = catalog.BindToContext(unboundRule.Name, this.file, this.itemType, this.itemName); + } + } + + internal partial class RazorProjectProperties + { + + private static System.Func>, object, RazorConfiguration> CreateRazorConfigurationPropertiesDelegate = new System.Func>, object, RazorConfiguration>(CreateRazorConfigurationProperties); + + private static RazorConfiguration CreateRazorConfigurationProperties(System.Threading.Tasks.Task> namedCatalogs, object state) + { + RazorProjectProperties that = ((RazorProjectProperties)(state)); + return new RazorConfiguration(that.ConfiguredProject, namedCatalogs.Result, "Project", that.File, that.ItemType, that.ItemName); + } + + /// Gets the strongly-typed property accessor used to get and set Configuration Properties properties. + internal System.Threading.Tasks.Task GetRazorConfigurationPropertiesAsync() + { + System.Threading.Tasks.Task> namedCatalogsTask = this.GetNamedCatalogsAsync(); + return namedCatalogsTask.ContinueWith(CreateRazorConfigurationPropertiesDelegate, this, System.Threading.CancellationToken.None, System.Threading.Tasks.TaskContinuationOptions.ExecuteSynchronously, System.Threading.Tasks.TaskScheduler.Default); + } + + /// Gets the strongly-typed property accessor used to get value from the current project snapshot Configuration Properties properties. + internal bool TryGetCurrentRazorConfigurationPropertiesSnapshot(out RazorConfiguration snapshot, [System.Runtime.InteropServices.OptionalAttribute()] [System.Runtime.InteropServices.DefaultParameterValueAttribute(true)] bool requiredToMatchProjectVersion) + { + snapshot = null; + Microsoft.VisualStudio.ProjectSystem.IProjectVersionedValue catalogSnapshot; + if (this.TryGetCurrentCatalogSnapshot(out catalogSnapshot)) + { + if (requiredToMatchProjectVersion) + { + if ((this.ConfiguredProject.ProjectVersion.CompareTo(catalogSnapshot.DataSourceVersions[Microsoft.VisualStudio.ProjectSystem.ProjectDataSources.ConfiguredProjectVersion]) != 0)) + { + return false; + } + } + Microsoft.VisualStudio.ProjectSystem.Properties.IRule rule = this.GetSnapshotRule(catalogSnapshot.Value, "Project", RazorConfiguration.SchemaName); + if ((rule != null)) + { + snapshot = new RazorConfiguration(rule, this.ConfiguredProject); + return true; + } + } + return false; + } + } } diff --git a/src/Microsoft.VisualStudio.LanguageServices.Razor/ProjectSystem/Rules/RazorExtension.cs b/src/Microsoft.VisualStudio.LanguageServices.Razor/ProjectSystem/Rules/RazorExtension.cs index 0ce503811b..6000099f24 100644 --- a/src/Microsoft.VisualStudio.LanguageServices.Razor/ProjectSystem/Rules/RazorExtension.cs +++ b/src/Microsoft.VisualStudio.LanguageServices.Razor/ProjectSystem/Rules/RazorExtension.cs @@ -8,228 +8,296 @@ // //------------------------------------------------------------------------------ -namespace Microsoft.CodeAnalysis.Razor.ProjectSystem.Rules { - - - internal partial class RazorExtension { - - /// Backing field for deserialized rule.. - private static Microsoft.Build.Framework.XamlTypes.Rule deserializedFallbackRule; - - /// The name of the schema to look for at runtime to fulfill property access. - internal const string SchemaName = "RazorExtension"; - - /// The ItemType given in the Rule.DataSource property. May not apply to every Property's individual DataSource. - internal const string PrimaryDataSourceItemType = "RazorExtension"; - - /// The Label given in the Rule.DataSource property. May not apply to every Property's individual DataSource. - internal const string PrimaryDataSourceLabel = ""; - - /// Razor Extension Assembly Name (The "AssemblyName" property). - internal const string AssemblyNameProperty = "AssemblyName"; - - /// Razor Extension Assembly File Path (The "AssemblyFilePath" property). - internal const string AssemblyFilePathProperty = "AssemblyFilePath"; - - /// Backing field for the property. - private Microsoft.VisualStudio.ProjectSystem.Properties.IRule rule; - - /// Backing field for the file name of the rule property. - private string file; - - /// Backing field for the ItemType property. - private string itemType; - - /// Backing field for the ItemName property. - private string itemName; - - /// Configured Project - private Microsoft.VisualStudio.ProjectSystem.ConfiguredProject configuredProject; - - /// The dictionary of named catalogs. - private System.Collections.Immutable.IImmutableDictionary catalogs; - - /// Backing field for the property. - private Microsoft.VisualStudio.ProjectSystem.Properties.IRule fallbackRule; - - /// Thread locking object - private object locker = new object(); - - /// Initializes a new instance of the RazorExtension class. - internal RazorExtension(Microsoft.VisualStudio.ProjectSystem.Properties.IRule rule) { - this.rule = rule; - } - - /// Initializes a new instance of the RazorExtension class. - internal RazorExtension(Microsoft.VisualStudio.ProjectSystem.ConfiguredProject configuredProject, System.Collections.Immutable.IImmutableDictionary catalogs, string context, string file, string itemType, string itemName) : - this(GetRule(System.Collections.Immutable.ImmutableDictionary.GetValueOrDefault(catalogs, context), file, itemType, itemName)) { - if ((configuredProject == null)) { - throw new System.ArgumentNullException("configuredProject"); - } - this.configuredProject = configuredProject; - this.catalogs = catalogs; - this.file = file; - this.itemType = itemType; - this.itemName = itemName; - } - - /// Initializes a new instance of the RazorExtension class. - internal RazorExtension(Microsoft.VisualStudio.ProjectSystem.Properties.IRule rule, Microsoft.VisualStudio.ProjectSystem.ConfiguredProject configuredProject) : - this(rule) { - if ((rule == null)) { - throw new System.ArgumentNullException("rule"); - } - if ((configuredProject == null)) { - throw new System.ArgumentNullException("configuredProject"); - } - this.configuredProject = configuredProject; - this.rule = rule; - this.file = this.rule.File; - this.itemType = this.rule.ItemType; - this.itemName = this.rule.ItemName; - } - - /// Initializes a new instance of the RazorExtension class. - internal RazorExtension(Microsoft.VisualStudio.ProjectSystem.ConfiguredProject configuredProject, System.Collections.Immutable.IImmutableDictionary catalogs, string context, Microsoft.VisualStudio.ProjectSystem.Properties.IProjectPropertiesContext propertyContext) : - this(configuredProject, catalogs, context, GetContextFile(propertyContext), propertyContext.ItemType, propertyContext.ItemName) { - } - - /// Initializes a new instance of the RazorExtension class that assumes a project context (neither property sheet nor items). - internal RazorExtension(Microsoft.VisualStudio.ProjectSystem.ConfiguredProject configuredProject, System.Collections.Immutable.IImmutableDictionary catalogs) : - this(configuredProject, catalogs, "Project", null, null, null) { - } - - /// Gets the IRule used to get and set properties. - public Microsoft.VisualStudio.ProjectSystem.Properties.IRule Rule { - get { - return this.rule; - } - } - - /// Razor Extension Assembly Name - internal Microsoft.VisualStudio.ProjectSystem.Properties.IEvaluatedProperty AssemblyName { - get { - Microsoft.VisualStudio.ProjectSystem.Properties.IRule localRule = this.rule; - if ((localRule == null)) { - localRule = this.GeneratedFallbackRule; - } - if ((localRule == null)) { - return null; - } - Microsoft.VisualStudio.ProjectSystem.Properties.IEvaluatedProperty property = ((Microsoft.VisualStudio.ProjectSystem.Properties.IEvaluatedProperty)(localRule.GetProperty(AssemblyNameProperty))); - if (((property == null) - && (this.GeneratedFallbackRule != null))) { - localRule = this.GeneratedFallbackRule; - property = ((Microsoft.VisualStudio.ProjectSystem.Properties.IEvaluatedProperty)(localRule.GetProperty(AssemblyNameProperty))); - } - return property; - } - } - - /// Razor Extension Assembly File Path - internal Microsoft.VisualStudio.ProjectSystem.Properties.IEvaluatedProperty AssemblyFilePath { - get { - Microsoft.VisualStudio.ProjectSystem.Properties.IRule localRule = this.rule; - if ((localRule == null)) { - localRule = this.GeneratedFallbackRule; - } - if ((localRule == null)) { - return null; - } - Microsoft.VisualStudio.ProjectSystem.Properties.IEvaluatedProperty property = ((Microsoft.VisualStudio.ProjectSystem.Properties.IEvaluatedProperty)(localRule.GetProperty(AssemblyFilePathProperty))); - if (((property == null) - && (this.GeneratedFallbackRule != null))) { - localRule = this.GeneratedFallbackRule; - property = ((Microsoft.VisualStudio.ProjectSystem.Properties.IEvaluatedProperty)(localRule.GetProperty(AssemblyFilePathProperty))); - } - return property; - } - } - - /// Get the fallback rule if the current rule on disk is missing or a property in the rule on disk is missing - private Microsoft.VisualStudio.ProjectSystem.Properties.IRule GeneratedFallbackRule { - get { - if (((this.fallbackRule == null) - && (this.configuredProject != null))) { - System.Threading.Monitor.Enter(this.locker); - try { - if ((this.fallbackRule == null)) { - this.InitializeFallbackRule(); - } - } - finally { - System.Threading.Monitor.Exit(this.locker); - } - } - return this.fallbackRule; - } - } - - private static Microsoft.VisualStudio.ProjectSystem.Properties.IRule GetRule(Microsoft.VisualStudio.ProjectSystem.Properties.IPropertyPagesCatalog catalog, string file, string itemType, string itemName) { - if ((catalog == null)) { - return null; - } - return catalog.BindToContext(SchemaName, file, itemType, itemName); - } - - private static string GetContextFile(Microsoft.VisualStudio.ProjectSystem.Properties.IProjectPropertiesContext propertiesContext) { - if ((propertiesContext.IsProjectFile == true)) { - return null; - } - else { - return propertiesContext.File; - } - } - - private void InitializeFallbackRule() { - if ((this.configuredProject == null)) { - return; - } - Microsoft.Build.Framework.XamlTypes.Rule unboundRule = RazorExtension.deserializedFallbackRule; - if ((unboundRule == null)) { - System.IO.Stream xamlStream = null; - System.Reflection.Assembly thisAssembly = System.Reflection.Assembly.GetExecutingAssembly(); - try { - xamlStream = thisAssembly.GetManifestResourceStream("XamlRuleToCode:RazorExtension.xaml"); - Microsoft.Build.Framework.XamlTypes.IProjectSchemaNode root = ((Microsoft.Build.Framework.XamlTypes.IProjectSchemaNode)(System.Xaml.XamlServices.Load(xamlStream))); - System.Collections.Generic.IEnumerator ruleEnumerator = root.GetSchemaObjects(typeof(Microsoft.Build.Framework.XamlTypes.Rule)).GetEnumerator(); - for ( - ; ((unboundRule == null) - && ruleEnumerator.MoveNext()); - ) { - Microsoft.Build.Framework.XamlTypes.Rule t = ((Microsoft.Build.Framework.XamlTypes.Rule)(ruleEnumerator.Current)); - if (System.StringComparer.OrdinalIgnoreCase.Equals(t.Name, SchemaName)) { - unboundRule = t; - unboundRule.Name = "6b577687-703b-41a1-8f5f-c44644f65f2a"; - RazorExtension.deserializedFallbackRule = unboundRule; - } - } - } - finally { - if ((xamlStream != null)) { - ((System.IDisposable)(xamlStream)).Dispose(); - } - } - } - this.configuredProject.Services.AdditionalRuleDefinitions.AddRuleDefinition(unboundRule, "FallbackRuleCodeGenerationContext"); - Microsoft.VisualStudio.ProjectSystem.Properties.IPropertyPagesCatalog catalog = this.configuredProject.Services.PropertyPagesCatalog.GetMemoryOnlyCatalog("FallbackRuleCodeGenerationContext"); - this.fallbackRule = catalog.BindToContext(unboundRule.Name, this.file, this.itemType, this.itemName); - } - } - - internal partial class RazorProjectProperties { - - private static System.Func>, object, RazorExtension> CreateRazorExtensionPropertiesDelegate = new System.Func>, object, RazorExtension>(CreateRazorExtensionProperties); - - private static RazorExtension CreateRazorExtensionProperties(System.Threading.Tasks.Task> namedCatalogs, object state) { - RazorProjectProperties that = ((RazorProjectProperties)(state)); - return new RazorExtension(that.ConfiguredProject, namedCatalogs.Result, "Project", that.File, that.ItemType, that.ItemName); - } - - /// Gets the strongly-typed property accessor used to get and set Extension Properties properties. - internal System.Threading.Tasks.Task GetRazorExtensionPropertiesAsync() { - System.Threading.Tasks.Task> namedCatalogsTask = this.GetNamedCatalogsAsync(); - return namedCatalogsTask.ContinueWith(CreateRazorExtensionPropertiesDelegate, this, System.Threading.CancellationToken.None, System.Threading.Tasks.TaskContinuationOptions.ExecuteSynchronously, System.Threading.Tasks.TaskScheduler.Default); - } - } +namespace Microsoft.CodeAnalysis.Razor.ProjectSystem.Rules +{ + + + internal partial class RazorExtension + { + + /// Backing field for deserialized rule.. + private static Microsoft.Build.Framework.XamlTypes.Rule deserializedFallbackRule; + + /// The name of the schema to look for at runtime to fulfill property access. + internal const string SchemaName = "RazorExtension"; + + /// The ItemType given in the Rule.DataSource property. May not apply to every Property's individual DataSource. + internal const string PrimaryDataSourceItemType = "RazorExtension"; + + /// The Label given in the Rule.DataSource property. May not apply to every Property's individual DataSource. + internal const string PrimaryDataSourceLabel = ""; + + /// Razor Extension Assembly Name (The "AssemblyName" property). + internal const string AssemblyNameProperty = "AssemblyName"; + + /// Razor Extension Assembly File Path (The "AssemblyFilePath" property). + internal const string AssemblyFilePathProperty = "AssemblyFilePath"; + + /// Backing field for the property. + private Microsoft.VisualStudio.ProjectSystem.Properties.IRule rule; + + /// Backing field for the file name of the rule property. + private string file; + + /// Backing field for the ItemType property. + private string itemType; + + /// Backing field for the ItemName property. + private string itemName; + + /// Configured Project + private Microsoft.VisualStudio.ProjectSystem.ConfiguredProject configuredProject; + + /// The dictionary of named catalogs. + private System.Collections.Immutable.IImmutableDictionary catalogs; + + /// Backing field for the property. + private Microsoft.VisualStudio.ProjectSystem.Properties.IRule fallbackRule; + + /// Thread locking object + private object locker = new object(); + + /// Initializes a new instance of the RazorExtension class. + internal RazorExtension(Microsoft.VisualStudio.ProjectSystem.Properties.IRule rule) + { + this.rule = rule; + } + + /// Initializes a new instance of the RazorExtension class. + internal RazorExtension(Microsoft.VisualStudio.ProjectSystem.ConfiguredProject configuredProject, System.Collections.Immutable.IImmutableDictionary catalogs, string context, string file, string itemType, string itemName) : + this(GetRule(System.Collections.Immutable.ImmutableDictionary.GetValueOrDefault(catalogs, context), file, itemType, itemName)) + { + if ((configuredProject == null)) + { + throw new System.ArgumentNullException("configuredProject"); + } + this.configuredProject = configuredProject; + this.catalogs = catalogs; + this.file = file; + this.itemType = itemType; + this.itemName = itemName; + } + + /// Initializes a new instance of the RazorExtension class. + internal RazorExtension(Microsoft.VisualStudio.ProjectSystem.Properties.IRule rule, Microsoft.VisualStudio.ProjectSystem.ConfiguredProject configuredProject) : + this(rule) + { + if ((rule == null)) + { + throw new System.ArgumentNullException("rule"); + } + if ((configuredProject == null)) + { + throw new System.ArgumentNullException("configuredProject"); + } + this.configuredProject = configuredProject; + this.rule = rule; + this.file = this.rule.File; + this.itemType = this.rule.ItemType; + this.itemName = this.rule.ItemName; + } + + /// Initializes a new instance of the RazorExtension class. + internal RazorExtension(Microsoft.VisualStudio.ProjectSystem.ConfiguredProject configuredProject, System.Collections.Immutable.IImmutableDictionary catalogs, string context, Microsoft.VisualStudio.ProjectSystem.Properties.IProjectPropertiesContext propertyContext) : + this(configuredProject, catalogs, context, GetContextFile(propertyContext), propertyContext.ItemType, propertyContext.ItemName) + { + } + + /// Initializes a new instance of the RazorExtension class that assumes a project context (neither property sheet nor items). + internal RazorExtension(Microsoft.VisualStudio.ProjectSystem.ConfiguredProject configuredProject, System.Collections.Immutable.IImmutableDictionary catalogs) : + this(configuredProject, catalogs, "Project", null, null, null) + { + } + + /// Gets the IRule used to get and set properties. + public Microsoft.VisualStudio.ProjectSystem.Properties.IRule Rule + { + get + { + return this.rule; + } + } + + /// Razor Extension Assembly Name + internal Microsoft.VisualStudio.ProjectSystem.Properties.IEvaluatedProperty AssemblyName + { + get + { + Microsoft.VisualStudio.ProjectSystem.Properties.IRule localRule = this.rule; + if ((localRule == null)) + { + localRule = this.GeneratedFallbackRule; + } + if ((localRule == null)) + { + return null; + } + Microsoft.VisualStudio.ProjectSystem.Properties.IEvaluatedProperty property = ((Microsoft.VisualStudio.ProjectSystem.Properties.IEvaluatedProperty)(localRule.GetProperty(AssemblyNameProperty))); + if (((property == null) + && (this.GeneratedFallbackRule != null))) + { + localRule = this.GeneratedFallbackRule; + property = ((Microsoft.VisualStudio.ProjectSystem.Properties.IEvaluatedProperty)(localRule.GetProperty(AssemblyNameProperty))); + } + return property; + } + } + + /// Razor Extension Assembly File Path + internal Microsoft.VisualStudio.ProjectSystem.Properties.IEvaluatedProperty AssemblyFilePath + { + get + { + Microsoft.VisualStudio.ProjectSystem.Properties.IRule localRule = this.rule; + if ((localRule == null)) + { + localRule = this.GeneratedFallbackRule; + } + if ((localRule == null)) + { + return null; + } + Microsoft.VisualStudio.ProjectSystem.Properties.IEvaluatedProperty property = ((Microsoft.VisualStudio.ProjectSystem.Properties.IEvaluatedProperty)(localRule.GetProperty(AssemblyFilePathProperty))); + if (((property == null) + && (this.GeneratedFallbackRule != null))) + { + localRule = this.GeneratedFallbackRule; + property = ((Microsoft.VisualStudio.ProjectSystem.Properties.IEvaluatedProperty)(localRule.GetProperty(AssemblyFilePathProperty))); + } + return property; + } + } + + /// Get the fallback rule if the current rule on disk is missing or a property in the rule on disk is missing + private Microsoft.VisualStudio.ProjectSystem.Properties.IRule GeneratedFallbackRule + { + get + { + if (((this.fallbackRule == null) + && (this.configuredProject != null))) + { + System.Threading.Monitor.Enter(this.locker); + try + { + if ((this.fallbackRule == null)) + { + this.InitializeFallbackRule(); + } + } + finally + { + System.Threading.Monitor.Exit(this.locker); + } + } + return this.fallbackRule; + } + } + + private static Microsoft.VisualStudio.ProjectSystem.Properties.IRule GetRule(Microsoft.VisualStudio.ProjectSystem.Properties.IPropertyPagesCatalog catalog, string file, string itemType, string itemName) + { + if ((catalog == null)) + { + return null; + } + return catalog.BindToContext(SchemaName, file, itemType, itemName); + } + + private static string GetContextFile(Microsoft.VisualStudio.ProjectSystem.Properties.IProjectPropertiesContext propertiesContext) + { + if ((propertiesContext.IsProjectFile == true)) + { + return null; + } + else + { + return propertiesContext.File; + } + } + + private void InitializeFallbackRule() + { + if ((this.configuredProject == null)) + { + return; + } + Microsoft.Build.Framework.XamlTypes.Rule unboundRule = RazorExtension.deserializedFallbackRule; + if ((unboundRule == null)) + { + System.IO.Stream xamlStream = null; + System.Reflection.Assembly thisAssembly = System.Reflection.Assembly.GetExecutingAssembly(); + try + { + xamlStream = thisAssembly.GetManifestResourceStream("XamlRuleToCode:RazorExtension.xaml"); + Microsoft.Build.Framework.XamlTypes.IProjectSchemaNode root = ((Microsoft.Build.Framework.XamlTypes.IProjectSchemaNode)(System.Xaml.XamlServices.Load(xamlStream))); + System.Collections.Generic.IEnumerator ruleEnumerator = root.GetSchemaObjects(typeof(Microsoft.Build.Framework.XamlTypes.Rule)).GetEnumerator(); + for ( + ; ((unboundRule == null) + && ruleEnumerator.MoveNext()); + ) + { + Microsoft.Build.Framework.XamlTypes.Rule t = ((Microsoft.Build.Framework.XamlTypes.Rule)(ruleEnumerator.Current)); + if (System.StringComparer.OrdinalIgnoreCase.Equals(t.Name, SchemaName)) + { + unboundRule = t; + unboundRule.Name = "e8ad5dd707beca947f7c014baa70b46c1d7a7fd6c8b49a5511ab299d8e1a3c70"; + RazorExtension.deserializedFallbackRule = unboundRule; + } + } + } + finally + { + if ((xamlStream != null)) + { + ((System.IDisposable)(xamlStream)).Dispose(); + } + } + } + this.configuredProject.Services.AdditionalRuleDefinitions.AddRuleDefinition(unboundRule, "FallbackRuleCodeGenerationContext"); + Microsoft.VisualStudio.ProjectSystem.Properties.IPropertyPagesCatalog catalog = this.configuredProject.Services.PropertyPagesCatalog.GetMemoryOnlyCatalog("FallbackRuleCodeGenerationContext"); + this.fallbackRule = catalog.BindToContext(unboundRule.Name, this.file, this.itemType, this.itemName); + } + } + + internal partial class RazorProjectProperties + { + + private static System.Func>, object, RazorExtension> CreateRazorExtensionPropertiesDelegate = new System.Func>, object, RazorExtension>(CreateRazorExtensionProperties); + + private static RazorExtension CreateRazorExtensionProperties(System.Threading.Tasks.Task> namedCatalogs, object state) + { + RazorProjectProperties that = ((RazorProjectProperties)(state)); + return new RazorExtension(that.ConfiguredProject, namedCatalogs.Result, "Project", that.File, that.ItemType, that.ItemName); + } + + /// Gets the strongly-typed property accessor used to get and set Extension Properties properties. + internal System.Threading.Tasks.Task GetRazorExtensionPropertiesAsync() + { + System.Threading.Tasks.Task> namedCatalogsTask = this.GetNamedCatalogsAsync(); + return namedCatalogsTask.ContinueWith(CreateRazorExtensionPropertiesDelegate, this, System.Threading.CancellationToken.None, System.Threading.Tasks.TaskContinuationOptions.ExecuteSynchronously, System.Threading.Tasks.TaskScheduler.Default); + } + + /// Gets the strongly-typed property accessor used to get value from the current project snapshot Extension Properties properties. + internal bool TryGetCurrentRazorExtensionPropertiesSnapshot(out RazorExtension snapshot, [System.Runtime.InteropServices.OptionalAttribute()] [System.Runtime.InteropServices.DefaultParameterValueAttribute(true)] bool requiredToMatchProjectVersion) + { + snapshot = null; + Microsoft.VisualStudio.ProjectSystem.IProjectVersionedValue catalogSnapshot; + if (this.TryGetCurrentCatalogSnapshot(out catalogSnapshot)) + { + if (requiredToMatchProjectVersion) + { + if ((this.ConfiguredProject.ProjectVersion.CompareTo(catalogSnapshot.DataSourceVersions[Microsoft.VisualStudio.ProjectSystem.ProjectDataSources.ConfiguredProjectVersion]) != 0)) + { + return false; + } + } + Microsoft.VisualStudio.ProjectSystem.Properties.IRule rule = this.GetSnapshotRule(catalogSnapshot.Value, "Project", RazorExtension.SchemaName); + if ((rule != null)) + { + snapshot = new RazorExtension(rule, this.ConfiguredProject); + return true; + } + } + return false; + } + } } diff --git a/src/Microsoft.VisualStudio.LanguageServices.Razor/ProjectSystem/Rules/RazorGeneral.cs b/src/Microsoft.VisualStudio.LanguageServices.Razor/ProjectSystem/Rules/RazorGeneral.cs index 860fb1a80b..3c85d96d87 100644 --- a/src/Microsoft.VisualStudio.LanguageServices.Razor/ProjectSystem/Rules/RazorGeneral.cs +++ b/src/Microsoft.VisualStudio.LanguageServices.Razor/ProjectSystem/Rules/RazorGeneral.cs @@ -8,228 +8,296 @@ // //------------------------------------------------------------------------------ -namespace Microsoft.CodeAnalysis.Razor.ProjectSystem.Rules { - - - internal partial class RazorGeneral { - - /// Backing field for deserialized rule.. - private static Microsoft.Build.Framework.XamlTypes.Rule deserializedFallbackRule; - - /// The name of the schema to look for at runtime to fulfill property access. - internal const string SchemaName = "RazorGeneral"; - - /// The ItemType given in the Rule.DataSource property. May not apply to every Property's individual DataSource. - internal const string PrimaryDataSourceItemType = null; - - /// The Label given in the Rule.DataSource property. May not apply to every Property's individual DataSource. - internal const string PrimaryDataSourceLabel = ""; - - /// Razor Language Version (The "RazorLangVersion" property). - internal const string RazorLangVersionProperty = "RazorLangVersion"; - - /// Razor Configuration Name (The "RazorDefaultConfiguration" property). - internal const string RazorDefaultConfigurationProperty = "RazorDefaultConfiguration"; - - /// Backing field for the property. - private Microsoft.VisualStudio.ProjectSystem.Properties.IRule rule; - - /// Backing field for the file name of the rule property. - private string file; - - /// Backing field for the ItemType property. - private string itemType; - - /// Backing field for the ItemName property. - private string itemName; - - /// Configured Project - private Microsoft.VisualStudio.ProjectSystem.ConfiguredProject configuredProject; - - /// The dictionary of named catalogs. - private System.Collections.Immutable.IImmutableDictionary catalogs; - - /// Backing field for the property. - private Microsoft.VisualStudio.ProjectSystem.Properties.IRule fallbackRule; - - /// Thread locking object - private object locker = new object(); - - /// Initializes a new instance of the RazorGeneral class. - internal RazorGeneral(Microsoft.VisualStudio.ProjectSystem.Properties.IRule rule) { - this.rule = rule; - } - - /// Initializes a new instance of the RazorGeneral class. - internal RazorGeneral(Microsoft.VisualStudio.ProjectSystem.ConfiguredProject configuredProject, System.Collections.Immutable.IImmutableDictionary catalogs, string context, string file, string itemType, string itemName) : - this(GetRule(System.Collections.Immutable.ImmutableDictionary.GetValueOrDefault(catalogs, context), file, itemType, itemName)) { - if ((configuredProject == null)) { - throw new System.ArgumentNullException("configuredProject"); - } - this.configuredProject = configuredProject; - this.catalogs = catalogs; - this.file = file; - this.itemType = itemType; - this.itemName = itemName; - } - - /// Initializes a new instance of the RazorGeneral class. - internal RazorGeneral(Microsoft.VisualStudio.ProjectSystem.Properties.IRule rule, Microsoft.VisualStudio.ProjectSystem.ConfiguredProject configuredProject) : - this(rule) { - if ((rule == null)) { - throw new System.ArgumentNullException("rule"); - } - if ((configuredProject == null)) { - throw new System.ArgumentNullException("configuredProject"); - } - this.configuredProject = configuredProject; - this.rule = rule; - this.file = this.rule.File; - this.itemType = this.rule.ItemType; - this.itemName = this.rule.ItemName; - } - - /// Initializes a new instance of the RazorGeneral class. - internal RazorGeneral(Microsoft.VisualStudio.ProjectSystem.ConfiguredProject configuredProject, System.Collections.Immutable.IImmutableDictionary catalogs, string context, Microsoft.VisualStudio.ProjectSystem.Properties.IProjectPropertiesContext propertyContext) : - this(configuredProject, catalogs, context, GetContextFile(propertyContext), propertyContext.ItemType, propertyContext.ItemName) { - } - - /// Initializes a new instance of the RazorGeneral class that assumes a project context (neither property sheet nor items). - internal RazorGeneral(Microsoft.VisualStudio.ProjectSystem.ConfiguredProject configuredProject, System.Collections.Immutable.IImmutableDictionary catalogs) : - this(configuredProject, catalogs, "Project", null, null, null) { - } - - /// Gets the IRule used to get and set properties. - public Microsoft.VisualStudio.ProjectSystem.Properties.IRule Rule { - get { - return this.rule; - } - } - - /// Razor Language Version - internal Microsoft.VisualStudio.ProjectSystem.Properties.IEvaluatedProperty RazorLangVersion { - get { - Microsoft.VisualStudio.ProjectSystem.Properties.IRule localRule = this.rule; - if ((localRule == null)) { - localRule = this.GeneratedFallbackRule; - } - if ((localRule == null)) { - return null; - } - Microsoft.VisualStudio.ProjectSystem.Properties.IEvaluatedProperty property = ((Microsoft.VisualStudio.ProjectSystem.Properties.IEvaluatedProperty)(localRule.GetProperty(RazorLangVersionProperty))); - if (((property == null) - && (this.GeneratedFallbackRule != null))) { - localRule = this.GeneratedFallbackRule; - property = ((Microsoft.VisualStudio.ProjectSystem.Properties.IEvaluatedProperty)(localRule.GetProperty(RazorLangVersionProperty))); - } - return property; - } - } - - /// Razor Configuration Name - internal Microsoft.VisualStudio.ProjectSystem.Properties.IEvaluatedProperty RazorDefaultConfiguration { - get { - Microsoft.VisualStudio.ProjectSystem.Properties.IRule localRule = this.rule; - if ((localRule == null)) { - localRule = this.GeneratedFallbackRule; - } - if ((localRule == null)) { - return null; - } - Microsoft.VisualStudio.ProjectSystem.Properties.IEvaluatedProperty property = ((Microsoft.VisualStudio.ProjectSystem.Properties.IEvaluatedProperty)(localRule.GetProperty(RazorDefaultConfigurationProperty))); - if (((property == null) - && (this.GeneratedFallbackRule != null))) { - localRule = this.GeneratedFallbackRule; - property = ((Microsoft.VisualStudio.ProjectSystem.Properties.IEvaluatedProperty)(localRule.GetProperty(RazorDefaultConfigurationProperty))); - } - return property; - } - } - - /// Get the fallback rule if the current rule on disk is missing or a property in the rule on disk is missing - private Microsoft.VisualStudio.ProjectSystem.Properties.IRule GeneratedFallbackRule { - get { - if (((this.fallbackRule == null) - && (this.configuredProject != null))) { - System.Threading.Monitor.Enter(this.locker); - try { - if ((this.fallbackRule == null)) { - this.InitializeFallbackRule(); - } - } - finally { - System.Threading.Monitor.Exit(this.locker); - } - } - return this.fallbackRule; - } - } - - private static Microsoft.VisualStudio.ProjectSystem.Properties.IRule GetRule(Microsoft.VisualStudio.ProjectSystem.Properties.IPropertyPagesCatalog catalog, string file, string itemType, string itemName) { - if ((catalog == null)) { - return null; - } - return catalog.BindToContext(SchemaName, file, itemType, itemName); - } - - private static string GetContextFile(Microsoft.VisualStudio.ProjectSystem.Properties.IProjectPropertiesContext propertiesContext) { - if ((propertiesContext.IsProjectFile == true)) { - return null; - } - else { - return propertiesContext.File; - } - } - - private void InitializeFallbackRule() { - if ((this.configuredProject == null)) { - return; - } - Microsoft.Build.Framework.XamlTypes.Rule unboundRule = RazorGeneral.deserializedFallbackRule; - if ((unboundRule == null)) { - System.IO.Stream xamlStream = null; - System.Reflection.Assembly thisAssembly = System.Reflection.Assembly.GetExecutingAssembly(); - try { - xamlStream = thisAssembly.GetManifestResourceStream("XamlRuleToCode:RazorGeneral.xaml"); - Microsoft.Build.Framework.XamlTypes.IProjectSchemaNode root = ((Microsoft.Build.Framework.XamlTypes.IProjectSchemaNode)(System.Xaml.XamlServices.Load(xamlStream))); - System.Collections.Generic.IEnumerator ruleEnumerator = root.GetSchemaObjects(typeof(Microsoft.Build.Framework.XamlTypes.Rule)).GetEnumerator(); - for ( - ; ((unboundRule == null) - && ruleEnumerator.MoveNext()); - ) { - Microsoft.Build.Framework.XamlTypes.Rule t = ((Microsoft.Build.Framework.XamlTypes.Rule)(ruleEnumerator.Current)); - if (System.StringComparer.OrdinalIgnoreCase.Equals(t.Name, SchemaName)) { - unboundRule = t; - unboundRule.Name = "e0400917-b7e9-4731-b3e6-447b229db9d4"; - RazorGeneral.deserializedFallbackRule = unboundRule; - } - } - } - finally { - if ((xamlStream != null)) { - ((System.IDisposable)(xamlStream)).Dispose(); - } - } - } - this.configuredProject.Services.AdditionalRuleDefinitions.AddRuleDefinition(unboundRule, "FallbackRuleCodeGenerationContext"); - Microsoft.VisualStudio.ProjectSystem.Properties.IPropertyPagesCatalog catalog = this.configuredProject.Services.PropertyPagesCatalog.GetMemoryOnlyCatalog("FallbackRuleCodeGenerationContext"); - this.fallbackRule = catalog.BindToContext(unboundRule.Name, this.file, this.itemType, this.itemName); - } - } - - internal partial class RazorProjectProperties { - - private static System.Func>, object, RazorGeneral> CreateRazorGeneralPropertiesDelegate = new System.Func>, object, RazorGeneral>(CreateRazorGeneralProperties); - - private static RazorGeneral CreateRazorGeneralProperties(System.Threading.Tasks.Task> namedCatalogs, object state) { - RazorProjectProperties that = ((RazorProjectProperties)(state)); - return new RazorGeneral(that.ConfiguredProject, namedCatalogs.Result, "Project", that.File, that.ItemType, that.ItemName); - } - - /// Gets the strongly-typed property accessor used to get and set Razor Properties properties. - internal System.Threading.Tasks.Task GetRazorGeneralPropertiesAsync() { - System.Threading.Tasks.Task> namedCatalogsTask = this.GetNamedCatalogsAsync(); - return namedCatalogsTask.ContinueWith(CreateRazorGeneralPropertiesDelegate, this, System.Threading.CancellationToken.None, System.Threading.Tasks.TaskContinuationOptions.ExecuteSynchronously, System.Threading.Tasks.TaskScheduler.Default); - } - } +namespace Microsoft.CodeAnalysis.Razor.ProjectSystem.Rules +{ + + + internal partial class RazorGeneral + { + + /// Backing field for deserialized rule.. + private static Microsoft.Build.Framework.XamlTypes.Rule deserializedFallbackRule; + + /// The name of the schema to look for at runtime to fulfill property access. + internal const string SchemaName = "RazorGeneral"; + + /// The ItemType given in the Rule.DataSource property. May not apply to every Property's individual DataSource. + internal const string PrimaryDataSourceItemType = null; + + /// The Label given in the Rule.DataSource property. May not apply to every Property's individual DataSource. + internal const string PrimaryDataSourceLabel = ""; + + /// Razor Language Version (The "RazorLangVersion" property). + internal const string RazorLangVersionProperty = "RazorLangVersion"; + + /// Razor Configuration Name (The "RazorDefaultConfiguration" property). + internal const string RazorDefaultConfigurationProperty = "RazorDefaultConfiguration"; + + /// Backing field for the property. + private Microsoft.VisualStudio.ProjectSystem.Properties.IRule rule; + + /// Backing field for the file name of the rule property. + private string file; + + /// Backing field for the ItemType property. + private string itemType; + + /// Backing field for the ItemName property. + private string itemName; + + /// Configured Project + private Microsoft.VisualStudio.ProjectSystem.ConfiguredProject configuredProject; + + /// The dictionary of named catalogs. + private System.Collections.Immutable.IImmutableDictionary catalogs; + + /// Backing field for the property. + private Microsoft.VisualStudio.ProjectSystem.Properties.IRule fallbackRule; + + /// Thread locking object + private object locker = new object(); + + /// Initializes a new instance of the RazorGeneral class. + internal RazorGeneral(Microsoft.VisualStudio.ProjectSystem.Properties.IRule rule) + { + this.rule = rule; + } + + /// Initializes a new instance of the RazorGeneral class. + internal RazorGeneral(Microsoft.VisualStudio.ProjectSystem.ConfiguredProject configuredProject, System.Collections.Immutable.IImmutableDictionary catalogs, string context, string file, string itemType, string itemName) : + this(GetRule(System.Collections.Immutable.ImmutableDictionary.GetValueOrDefault(catalogs, context), file, itemType, itemName)) + { + if ((configuredProject == null)) + { + throw new System.ArgumentNullException("configuredProject"); + } + this.configuredProject = configuredProject; + this.catalogs = catalogs; + this.file = file; + this.itemType = itemType; + this.itemName = itemName; + } + + /// Initializes a new instance of the RazorGeneral class. + internal RazorGeneral(Microsoft.VisualStudio.ProjectSystem.Properties.IRule rule, Microsoft.VisualStudio.ProjectSystem.ConfiguredProject configuredProject) : + this(rule) + { + if ((rule == null)) + { + throw new System.ArgumentNullException("rule"); + } + if ((configuredProject == null)) + { + throw new System.ArgumentNullException("configuredProject"); + } + this.configuredProject = configuredProject; + this.rule = rule; + this.file = this.rule.File; + this.itemType = this.rule.ItemType; + this.itemName = this.rule.ItemName; + } + + /// Initializes a new instance of the RazorGeneral class. + internal RazorGeneral(Microsoft.VisualStudio.ProjectSystem.ConfiguredProject configuredProject, System.Collections.Immutable.IImmutableDictionary catalogs, string context, Microsoft.VisualStudio.ProjectSystem.Properties.IProjectPropertiesContext propertyContext) : + this(configuredProject, catalogs, context, GetContextFile(propertyContext), propertyContext.ItemType, propertyContext.ItemName) + { + } + + /// Initializes a new instance of the RazorGeneral class that assumes a project context (neither property sheet nor items). + internal RazorGeneral(Microsoft.VisualStudio.ProjectSystem.ConfiguredProject configuredProject, System.Collections.Immutable.IImmutableDictionary catalogs) : + this(configuredProject, catalogs, "Project", null, null, null) + { + } + + /// Gets the IRule used to get and set properties. + public Microsoft.VisualStudio.ProjectSystem.Properties.IRule Rule + { + get + { + return this.rule; + } + } + + /// Razor Language Version + internal Microsoft.VisualStudio.ProjectSystem.Properties.IEvaluatedProperty RazorLangVersion + { + get + { + Microsoft.VisualStudio.ProjectSystem.Properties.IRule localRule = this.rule; + if ((localRule == null)) + { + localRule = this.GeneratedFallbackRule; + } + if ((localRule == null)) + { + return null; + } + Microsoft.VisualStudio.ProjectSystem.Properties.IEvaluatedProperty property = ((Microsoft.VisualStudio.ProjectSystem.Properties.IEvaluatedProperty)(localRule.GetProperty(RazorLangVersionProperty))); + if (((property == null) + && (this.GeneratedFallbackRule != null))) + { + localRule = this.GeneratedFallbackRule; + property = ((Microsoft.VisualStudio.ProjectSystem.Properties.IEvaluatedProperty)(localRule.GetProperty(RazorLangVersionProperty))); + } + return property; + } + } + + /// Razor Configuration Name + internal Microsoft.VisualStudio.ProjectSystem.Properties.IEvaluatedProperty RazorDefaultConfiguration + { + get + { + Microsoft.VisualStudio.ProjectSystem.Properties.IRule localRule = this.rule; + if ((localRule == null)) + { + localRule = this.GeneratedFallbackRule; + } + if ((localRule == null)) + { + return null; + } + Microsoft.VisualStudio.ProjectSystem.Properties.IEvaluatedProperty property = ((Microsoft.VisualStudio.ProjectSystem.Properties.IEvaluatedProperty)(localRule.GetProperty(RazorDefaultConfigurationProperty))); + if (((property == null) + && (this.GeneratedFallbackRule != null))) + { + localRule = this.GeneratedFallbackRule; + property = ((Microsoft.VisualStudio.ProjectSystem.Properties.IEvaluatedProperty)(localRule.GetProperty(RazorDefaultConfigurationProperty))); + } + return property; + } + } + + /// Get the fallback rule if the current rule on disk is missing or a property in the rule on disk is missing + private Microsoft.VisualStudio.ProjectSystem.Properties.IRule GeneratedFallbackRule + { + get + { + if (((this.fallbackRule == null) + && (this.configuredProject != null))) + { + System.Threading.Monitor.Enter(this.locker); + try + { + if ((this.fallbackRule == null)) + { + this.InitializeFallbackRule(); + } + } + finally + { + System.Threading.Monitor.Exit(this.locker); + } + } + return this.fallbackRule; + } + } + + private static Microsoft.VisualStudio.ProjectSystem.Properties.IRule GetRule(Microsoft.VisualStudio.ProjectSystem.Properties.IPropertyPagesCatalog catalog, string file, string itemType, string itemName) + { + if ((catalog == null)) + { + return null; + } + return catalog.BindToContext(SchemaName, file, itemType, itemName); + } + + private static string GetContextFile(Microsoft.VisualStudio.ProjectSystem.Properties.IProjectPropertiesContext propertiesContext) + { + if ((propertiesContext.IsProjectFile == true)) + { + return null; + } + else + { + return propertiesContext.File; + } + } + + private void InitializeFallbackRule() + { + if ((this.configuredProject == null)) + { + return; + } + Microsoft.Build.Framework.XamlTypes.Rule unboundRule = RazorGeneral.deserializedFallbackRule; + if ((unboundRule == null)) + { + System.IO.Stream xamlStream = null; + System.Reflection.Assembly thisAssembly = System.Reflection.Assembly.GetExecutingAssembly(); + try + { + xamlStream = thisAssembly.GetManifestResourceStream("XamlRuleToCode:RazorGeneral.xaml"); + Microsoft.Build.Framework.XamlTypes.IProjectSchemaNode root = ((Microsoft.Build.Framework.XamlTypes.IProjectSchemaNode)(System.Xaml.XamlServices.Load(xamlStream))); + System.Collections.Generic.IEnumerator ruleEnumerator = root.GetSchemaObjects(typeof(Microsoft.Build.Framework.XamlTypes.Rule)).GetEnumerator(); + for ( + ; ((unboundRule == null) + && ruleEnumerator.MoveNext()); + ) + { + Microsoft.Build.Framework.XamlTypes.Rule t = ((Microsoft.Build.Framework.XamlTypes.Rule)(ruleEnumerator.Current)); + if (System.StringComparer.OrdinalIgnoreCase.Equals(t.Name, SchemaName)) + { + unboundRule = t; + unboundRule.Name = "6851f2efc446915a1288ec829aa82f7dc9bcfc6addb65b97866a1bc9e30b3348"; + RazorGeneral.deserializedFallbackRule = unboundRule; + } + } + } + finally + { + if ((xamlStream != null)) + { + ((System.IDisposable)(xamlStream)).Dispose(); + } + } + } + this.configuredProject.Services.AdditionalRuleDefinitions.AddRuleDefinition(unboundRule, "FallbackRuleCodeGenerationContext"); + Microsoft.VisualStudio.ProjectSystem.Properties.IPropertyPagesCatalog catalog = this.configuredProject.Services.PropertyPagesCatalog.GetMemoryOnlyCatalog("FallbackRuleCodeGenerationContext"); + this.fallbackRule = catalog.BindToContext(unboundRule.Name, this.file, this.itemType, this.itemName); + } + } + + internal partial class RazorProjectProperties + { + + private static System.Func>, object, RazorGeneral> CreateRazorGeneralPropertiesDelegate = new System.Func>, object, RazorGeneral>(CreateRazorGeneralProperties); + + private static RazorGeneral CreateRazorGeneralProperties(System.Threading.Tasks.Task> namedCatalogs, object state) + { + RazorProjectProperties that = ((RazorProjectProperties)(state)); + return new RazorGeneral(that.ConfiguredProject, namedCatalogs.Result, "Project", that.File, that.ItemType, that.ItemName); + } + + /// Gets the strongly-typed property accessor used to get and set Razor Properties properties. + internal System.Threading.Tasks.Task GetRazorGeneralPropertiesAsync() + { + System.Threading.Tasks.Task> namedCatalogsTask = this.GetNamedCatalogsAsync(); + return namedCatalogsTask.ContinueWith(CreateRazorGeneralPropertiesDelegate, this, System.Threading.CancellationToken.None, System.Threading.Tasks.TaskContinuationOptions.ExecuteSynchronously, System.Threading.Tasks.TaskScheduler.Default); + } + + /// Gets the strongly-typed property accessor used to get value from the current project snapshot Razor Properties properties. + internal bool TryGetCurrentRazorGeneralPropertiesSnapshot(out RazorGeneral snapshot, [System.Runtime.InteropServices.OptionalAttribute()] [System.Runtime.InteropServices.DefaultParameterValueAttribute(true)] bool requiredToMatchProjectVersion) + { + snapshot = null; + Microsoft.VisualStudio.ProjectSystem.IProjectVersionedValue catalogSnapshot; + if (this.TryGetCurrentCatalogSnapshot(out catalogSnapshot)) + { + if (requiredToMatchProjectVersion) + { + if ((this.ConfiguredProject.ProjectVersion.CompareTo(catalogSnapshot.DataSourceVersions[Microsoft.VisualStudio.ProjectSystem.ProjectDataSources.ConfiguredProjectVersion]) != 0)) + { + return false; + } + } + Microsoft.VisualStudio.ProjectSystem.Properties.IRule rule = this.GetSnapshotRule(catalogSnapshot.Value, "Project", RazorGeneral.SchemaName); + if ((rule != null)) + { + snapshot = new RazorGeneral(rule, this.ConfiguredProject); + return true; + } + } + return false; + } + } } diff --git a/src/Microsoft.VisualStudio.LanguageServices.Razor/ProjectSystem/Rules/RazorGenerateWithTargetPath.cs b/src/Microsoft.VisualStudio.LanguageServices.Razor/ProjectSystem/Rules/RazorGenerateWithTargetPath.cs index 8428e7244f..3b58d8dd23 100644 --- a/src/Microsoft.VisualStudio.LanguageServices.Razor/ProjectSystem/Rules/RazorGenerateWithTargetPath.cs +++ b/src/Microsoft.VisualStudio.LanguageServices.Razor/ProjectSystem/Rules/RazorGenerateWithTargetPath.cs @@ -8,205 +8,268 @@ // //------------------------------------------------------------------------------ -namespace Microsoft.CodeAnalysis.Razor.ProjectSystem.Rules { - - - internal partial class RazorGenerateWithTargetPath { - - /// Backing field for deserialized rule.. - private static Microsoft.Build.Framework.XamlTypes.Rule deserializedFallbackRule; - - /// The name of the schema to look for at runtime to fulfill property access. - internal const string SchemaName = "RazorGenerateWithTargetPath"; - - /// The ItemType given in the Rule.DataSource property. May not apply to every Property's individual DataSource. - internal const string PrimaryDataSourceItemType = "RazorGenerateWithTargetPath"; - - /// The Label given in the Rule.DataSource property. May not apply to every Property's individual DataSource. - internal const string PrimaryDataSourceLabel = ""; - - /// Target Path (The "TargetPath" property). - internal const string TargetPathProperty = "TargetPath"; - - /// Backing field for the property. - private Microsoft.VisualStudio.ProjectSystem.Properties.IRule rule; - - /// Backing field for the file name of the rule property. - private string file; - - /// Backing field for the ItemType property. - private string itemType; - - /// Backing field for the ItemName property. - private string itemName; - - /// Configured Project - private Microsoft.VisualStudio.ProjectSystem.ConfiguredProject configuredProject; - - /// The dictionary of named catalogs. - private System.Collections.Immutable.IImmutableDictionary catalogs; - - /// Backing field for the property. - private Microsoft.VisualStudio.ProjectSystem.Properties.IRule fallbackRule; - - /// Thread locking object - private object locker = new object(); - - /// Initializes a new instance of the RazorGenerateWithTargetPath class. - internal RazorGenerateWithTargetPath(Microsoft.VisualStudio.ProjectSystem.Properties.IRule rule) { - this.rule = rule; - } - - /// Initializes a new instance of the RazorGenerateWithTargetPath class. - internal RazorGenerateWithTargetPath(Microsoft.VisualStudio.ProjectSystem.ConfiguredProject configuredProject, System.Collections.Immutable.IImmutableDictionary catalogs, string context, string file, string itemType, string itemName) : - this(GetRule(System.Collections.Immutable.ImmutableDictionary.GetValueOrDefault(catalogs, context), file, itemType, itemName)) { - if ((configuredProject == null)) { - throw new System.ArgumentNullException("configuredProject"); - } - this.configuredProject = configuredProject; - this.catalogs = catalogs; - this.file = file; - this.itemType = itemType; - this.itemName = itemName; - } - - /// Initializes a new instance of the RazorGenerateWithTargetPath class. - internal RazorGenerateWithTargetPath(Microsoft.VisualStudio.ProjectSystem.Properties.IRule rule, Microsoft.VisualStudio.ProjectSystem.ConfiguredProject configuredProject) : - this(rule) { - if ((rule == null)) { - throw new System.ArgumentNullException("rule"); - } - if ((configuredProject == null)) { - throw new System.ArgumentNullException("configuredProject"); - } - this.configuredProject = configuredProject; - this.rule = rule; - this.file = this.rule.File; - this.itemType = this.rule.ItemType; - this.itemName = this.rule.ItemName; - } - - /// Initializes a new instance of the RazorGenerateWithTargetPath class. - internal RazorGenerateWithTargetPath(Microsoft.VisualStudio.ProjectSystem.ConfiguredProject configuredProject, System.Collections.Immutable.IImmutableDictionary catalogs, string context, Microsoft.VisualStudio.ProjectSystem.Properties.IProjectPropertiesContext propertyContext) : - this(configuredProject, catalogs, context, GetContextFile(propertyContext), propertyContext.ItemType, propertyContext.ItemName) { - } - - /// Initializes a new instance of the RazorGenerateWithTargetPath class that assumes a project context (neither property sheet nor items). - internal RazorGenerateWithTargetPath(Microsoft.VisualStudio.ProjectSystem.ConfiguredProject configuredProject, System.Collections.Immutable.IImmutableDictionary catalogs) : - this(configuredProject, catalogs, "Project", null, null, null) { - } - - /// Gets the IRule used to get and set properties. - public Microsoft.VisualStudio.ProjectSystem.Properties.IRule Rule { - get { - return this.rule; - } - } - - /// Target Path - internal Microsoft.VisualStudio.ProjectSystem.Properties.IEvaluatedProperty TargetPath { - get { - Microsoft.VisualStudio.ProjectSystem.Properties.IRule localRule = this.rule; - if ((localRule == null)) { - localRule = this.GeneratedFallbackRule; - } - if ((localRule == null)) { - return null; - } - Microsoft.VisualStudio.ProjectSystem.Properties.IEvaluatedProperty property = ((Microsoft.VisualStudio.ProjectSystem.Properties.IEvaluatedProperty)(localRule.GetProperty(TargetPathProperty))); - if (((property == null) - && (this.GeneratedFallbackRule != null))) { - localRule = this.GeneratedFallbackRule; - property = ((Microsoft.VisualStudio.ProjectSystem.Properties.IEvaluatedProperty)(localRule.GetProperty(TargetPathProperty))); - } - return property; - } - } - - /// Get the fallback rule if the current rule on disk is missing or a property in the rule on disk is missing - private Microsoft.VisualStudio.ProjectSystem.Properties.IRule GeneratedFallbackRule { - get { - if (((this.fallbackRule == null) - && (this.configuredProject != null))) { - System.Threading.Monitor.Enter(this.locker); - try { - if ((this.fallbackRule == null)) { - this.InitializeFallbackRule(); - } - } - finally { - System.Threading.Monitor.Exit(this.locker); - } - } - return this.fallbackRule; - } - } - - private static Microsoft.VisualStudio.ProjectSystem.Properties.IRule GetRule(Microsoft.VisualStudio.ProjectSystem.Properties.IPropertyPagesCatalog catalog, string file, string itemType, string itemName) { - if ((catalog == null)) { - return null; - } - return catalog.BindToContext(SchemaName, file, itemType, itemName); - } - - private static string GetContextFile(Microsoft.VisualStudio.ProjectSystem.Properties.IProjectPropertiesContext propertiesContext) { - if ((propertiesContext.IsProjectFile == true)) { - return null; - } - else { - return propertiesContext.File; - } - } - - private void InitializeFallbackRule() { - if ((this.configuredProject == null)) { - return; - } - Microsoft.Build.Framework.XamlTypes.Rule unboundRule = RazorGenerateWithTargetPath.deserializedFallbackRule; - if ((unboundRule == null)) { - System.IO.Stream xamlStream = null; - System.Reflection.Assembly thisAssembly = System.Reflection.Assembly.GetExecutingAssembly(); - try { - xamlStream = thisAssembly.GetManifestResourceStream("XamlRuleToCode:RazorGenerateWithTargetPath.xaml"); - Microsoft.Build.Framework.XamlTypes.IProjectSchemaNode root = ((Microsoft.Build.Framework.XamlTypes.IProjectSchemaNode)(System.Xaml.XamlServices.Load(xamlStream))); - System.Collections.Generic.IEnumerator ruleEnumerator = root.GetSchemaObjects(typeof(Microsoft.Build.Framework.XamlTypes.Rule)).GetEnumerator(); - for ( - ; ((unboundRule == null) - && ruleEnumerator.MoveNext()); - ) { - Microsoft.Build.Framework.XamlTypes.Rule t = ((Microsoft.Build.Framework.XamlTypes.Rule)(ruleEnumerator.Current)); - if (System.StringComparer.OrdinalIgnoreCase.Equals(t.Name, SchemaName)) { - unboundRule = t; - unboundRule.Name = "4d01f23e-96db-4c90-9c01-17b7f8b61243"; - RazorGenerateWithTargetPath.deserializedFallbackRule = unboundRule; - } - } - } - finally { - if ((xamlStream != null)) { - ((System.IDisposable)(xamlStream)).Dispose(); - } - } - } - this.configuredProject.Services.AdditionalRuleDefinitions.AddRuleDefinition(unboundRule, "FallbackRuleCodeGenerationContext"); - Microsoft.VisualStudio.ProjectSystem.Properties.IPropertyPagesCatalog catalog = this.configuredProject.Services.PropertyPagesCatalog.GetMemoryOnlyCatalog("FallbackRuleCodeGenerationContext"); - this.fallbackRule = catalog.BindToContext(unboundRule.Name, this.file, this.itemType, this.itemName); - } - } - - internal partial class RazorProjectProperties { - - private static System.Func>, object, RazorGenerateWithTargetPath> CreateRazorGenerateWithTargetPathPropertiesDelegate = new System.Func>, object, RazorGenerateWithTargetPath>(CreateRazorGenerateWithTargetPathProperties); - - private static RazorGenerateWithTargetPath CreateRazorGenerateWithTargetPathProperties(System.Threading.Tasks.Task> namedCatalogs, object state) { - RazorProjectProperties that = ((RazorProjectProperties)(state)); - return new RazorGenerateWithTargetPath(that.ConfiguredProject, namedCatalogs.Result, "Project", that.File, that.ItemType, that.ItemName); - } - - /// Gets the strongly-typed property accessor used to get and set Razor Document Properties properties. - internal System.Threading.Tasks.Task GetRazorGenerateWithTargetPathPropertiesAsync() { - System.Threading.Tasks.Task> namedCatalogsTask = this.GetNamedCatalogsAsync(); - return namedCatalogsTask.ContinueWith(CreateRazorGenerateWithTargetPathPropertiesDelegate, this, System.Threading.CancellationToken.None, System.Threading.Tasks.TaskContinuationOptions.ExecuteSynchronously, System.Threading.Tasks.TaskScheduler.Default); - } - } +namespace Microsoft.CodeAnalysis.Razor.ProjectSystem.Rules +{ + + + internal partial class RazorGenerateWithTargetPath + { + + /// Backing field for deserialized rule.. + private static Microsoft.Build.Framework.XamlTypes.Rule deserializedFallbackRule; + + /// The name of the schema to look for at runtime to fulfill property access. + internal const string SchemaName = "RazorGenerateWithTargetPath"; + + /// The ItemType given in the Rule.DataSource property. May not apply to every Property's individual DataSource. + internal const string PrimaryDataSourceItemType = "RazorGenerateWithTargetPath"; + + /// The Label given in the Rule.DataSource property. May not apply to every Property's individual DataSource. + internal const string PrimaryDataSourceLabel = ""; + + /// (The "TargetPath" property). + internal const string TargetPathProperty = "TargetPath"; + + /// Backing field for the property. + private Microsoft.VisualStudio.ProjectSystem.Properties.IRule rule; + + /// Backing field for the file name of the rule property. + private string file; + + /// Backing field for the ItemType property. + private string itemType; + + /// Backing field for the ItemName property. + private string itemName; + + /// Configured Project + private Microsoft.VisualStudio.ProjectSystem.ConfiguredProject configuredProject; + + /// The dictionary of named catalogs. + private System.Collections.Immutable.IImmutableDictionary catalogs; + + /// Backing field for the property. + private Microsoft.VisualStudio.ProjectSystem.Properties.IRule fallbackRule; + + /// Thread locking object + private object locker = new object(); + + /// Initializes a new instance of the RazorGenerateWithTargetPath class. + internal RazorGenerateWithTargetPath(Microsoft.VisualStudio.ProjectSystem.Properties.IRule rule) + { + this.rule = rule; + } + + /// Initializes a new instance of the RazorGenerateWithTargetPath class. + internal RazorGenerateWithTargetPath(Microsoft.VisualStudio.ProjectSystem.ConfiguredProject configuredProject, System.Collections.Immutable.IImmutableDictionary catalogs, string context, string file, string itemType, string itemName) : + this(GetRule(System.Collections.Immutable.ImmutableDictionary.GetValueOrDefault(catalogs, context), file, itemType, itemName)) + { + if ((configuredProject == null)) + { + throw new System.ArgumentNullException("configuredProject"); + } + this.configuredProject = configuredProject; + this.catalogs = catalogs; + this.file = file; + this.itemType = itemType; + this.itemName = itemName; + } + + /// Initializes a new instance of the RazorGenerateWithTargetPath class. + internal RazorGenerateWithTargetPath(Microsoft.VisualStudio.ProjectSystem.Properties.IRule rule, Microsoft.VisualStudio.ProjectSystem.ConfiguredProject configuredProject) : + this(rule) + { + if ((rule == null)) + { + throw new System.ArgumentNullException("rule"); + } + if ((configuredProject == null)) + { + throw new System.ArgumentNullException("configuredProject"); + } + this.configuredProject = configuredProject; + this.rule = rule; + this.file = this.rule.File; + this.itemType = this.rule.ItemType; + this.itemName = this.rule.ItemName; + } + + /// Initializes a new instance of the RazorGenerateWithTargetPath class. + internal RazorGenerateWithTargetPath(Microsoft.VisualStudio.ProjectSystem.ConfiguredProject configuredProject, System.Collections.Immutable.IImmutableDictionary catalogs, string context, Microsoft.VisualStudio.ProjectSystem.Properties.IProjectPropertiesContext propertyContext) : + this(configuredProject, catalogs, context, GetContextFile(propertyContext), propertyContext.ItemType, propertyContext.ItemName) + { + } + + /// Initializes a new instance of the RazorGenerateWithTargetPath class that assumes a project context (neither property sheet nor items). + internal RazorGenerateWithTargetPath(Microsoft.VisualStudio.ProjectSystem.ConfiguredProject configuredProject, System.Collections.Immutable.IImmutableDictionary catalogs) : + this(configuredProject, catalogs, "Project", null, null, null) + { + } + + /// Gets the IRule used to get and set properties. + public Microsoft.VisualStudio.ProjectSystem.Properties.IRule Rule + { + get + { + return this.rule; + } + } + + /// TargetPath + internal Microsoft.VisualStudio.ProjectSystem.Properties.IEvaluatedProperty TargetPath + { + get + { + Microsoft.VisualStudio.ProjectSystem.Properties.IRule localRule = this.rule; + if ((localRule == null)) + { + localRule = this.GeneratedFallbackRule; + } + if ((localRule == null)) + { + return null; + } + Microsoft.VisualStudio.ProjectSystem.Properties.IEvaluatedProperty property = ((Microsoft.VisualStudio.ProjectSystem.Properties.IEvaluatedProperty)(localRule.GetProperty(TargetPathProperty))); + if (((property == null) + && (this.GeneratedFallbackRule != null))) + { + localRule = this.GeneratedFallbackRule; + property = ((Microsoft.VisualStudio.ProjectSystem.Properties.IEvaluatedProperty)(localRule.GetProperty(TargetPathProperty))); + } + return property; + } + } + + /// Get the fallback rule if the current rule on disk is missing or a property in the rule on disk is missing + private Microsoft.VisualStudio.ProjectSystem.Properties.IRule GeneratedFallbackRule + { + get + { + if (((this.fallbackRule == null) + && (this.configuredProject != null))) + { + System.Threading.Monitor.Enter(this.locker); + try + { + if ((this.fallbackRule == null)) + { + this.InitializeFallbackRule(); + } + } + finally + { + System.Threading.Monitor.Exit(this.locker); + } + } + return this.fallbackRule; + } + } + + private static Microsoft.VisualStudio.ProjectSystem.Properties.IRule GetRule(Microsoft.VisualStudio.ProjectSystem.Properties.IPropertyPagesCatalog catalog, string file, string itemType, string itemName) + { + if ((catalog == null)) + { + return null; + } + return catalog.BindToContext(SchemaName, file, itemType, itemName); + } + + private static string GetContextFile(Microsoft.VisualStudio.ProjectSystem.Properties.IProjectPropertiesContext propertiesContext) + { + if ((propertiesContext.IsProjectFile == true)) + { + return null; + } + else + { + return propertiesContext.File; + } + } + + private void InitializeFallbackRule() + { + if ((this.configuredProject == null)) + { + return; + } + Microsoft.Build.Framework.XamlTypes.Rule unboundRule = RazorGenerateWithTargetPath.deserializedFallbackRule; + if ((unboundRule == null)) + { + System.IO.Stream xamlStream = null; + System.Reflection.Assembly thisAssembly = System.Reflection.Assembly.GetExecutingAssembly(); + try + { + xamlStream = thisAssembly.GetManifestResourceStream("XamlRuleToCode:RazorGenerateWithTargetPath.xaml"); + Microsoft.Build.Framework.XamlTypes.IProjectSchemaNode root = ((Microsoft.Build.Framework.XamlTypes.IProjectSchemaNode)(System.Xaml.XamlServices.Load(xamlStream))); + System.Collections.Generic.IEnumerator ruleEnumerator = root.GetSchemaObjects(typeof(Microsoft.Build.Framework.XamlTypes.Rule)).GetEnumerator(); + for ( + ; ((unboundRule == null) + && ruleEnumerator.MoveNext()); + ) + { + Microsoft.Build.Framework.XamlTypes.Rule t = ((Microsoft.Build.Framework.XamlTypes.Rule)(ruleEnumerator.Current)); + if (System.StringComparer.OrdinalIgnoreCase.Equals(t.Name, SchemaName)) + { + unboundRule = t; + unboundRule.Name = "4325a10cce970a389c33b97140c4307d2e10664e053c75cf9e0e0fd08288774f"; + RazorGenerateWithTargetPath.deserializedFallbackRule = unboundRule; + } + } + } + finally + { + if ((xamlStream != null)) + { + ((System.IDisposable)(xamlStream)).Dispose(); + } + } + } + this.configuredProject.Services.AdditionalRuleDefinitions.AddRuleDefinition(unboundRule, "FallbackRuleCodeGenerationContext"); + Microsoft.VisualStudio.ProjectSystem.Properties.IPropertyPagesCatalog catalog = this.configuredProject.Services.PropertyPagesCatalog.GetMemoryOnlyCatalog("FallbackRuleCodeGenerationContext"); + this.fallbackRule = catalog.BindToContext(unboundRule.Name, this.file, this.itemType, this.itemName); + } + } + + internal partial class RazorProjectProperties + { + + private static System.Func>, object, RazorGenerateWithTargetPath> CreateRazorGenerateWithTargetPathPropertiesDelegate = new System.Func>, object, RazorGenerateWithTargetPath>(CreateRazorGenerateWithTargetPathProperties); + + private static RazorGenerateWithTargetPath CreateRazorGenerateWithTargetPathProperties(System.Threading.Tasks.Task> namedCatalogs, object state) + { + RazorProjectProperties that = ((RazorProjectProperties)(state)); + return new RazorGenerateWithTargetPath(that.ConfiguredProject, namedCatalogs.Result, "Project", that.File, that.ItemType, that.ItemName); + } + + /// Gets the strongly-typed property accessor used to get and set Razor Document Properties properties. + internal System.Threading.Tasks.Task GetRazorGenerateWithTargetPathPropertiesAsync() + { + System.Threading.Tasks.Task> namedCatalogsTask = this.GetNamedCatalogsAsync(); + return namedCatalogsTask.ContinueWith(CreateRazorGenerateWithTargetPathPropertiesDelegate, this, System.Threading.CancellationToken.None, System.Threading.Tasks.TaskContinuationOptions.ExecuteSynchronously, System.Threading.Tasks.TaskScheduler.Default); + } + + /// Gets the strongly-typed property accessor used to get value from the current project snapshot Razor Document Properties properties. + internal bool TryGetCurrentRazorGenerateWithTargetPathPropertiesSnapshot(out RazorGenerateWithTargetPath snapshot, [System.Runtime.InteropServices.OptionalAttribute()] [System.Runtime.InteropServices.DefaultParameterValueAttribute(true)] bool requiredToMatchProjectVersion) + { + snapshot = null; + Microsoft.VisualStudio.ProjectSystem.IProjectVersionedValue catalogSnapshot; + if (this.TryGetCurrentCatalogSnapshot(out catalogSnapshot)) + { + if (requiredToMatchProjectVersion) + { + if ((this.ConfiguredProject.ProjectVersion.CompareTo(catalogSnapshot.DataSourceVersions[Microsoft.VisualStudio.ProjectSystem.ProjectDataSources.ConfiguredProjectVersion]) != 0)) + { + return false; + } + } + Microsoft.VisualStudio.ProjectSystem.Properties.IRule rule = this.GetSnapshotRule(catalogSnapshot.Value, "Project", RazorGenerateWithTargetPath.SchemaName); + if ((rule != null)) + { + snapshot = new RazorGenerateWithTargetPath(rule, this.ConfiguredProject); + return true; + } + } + return false; + } + } } diff --git a/test/Microsoft.VisualStudio.LanguageServices.Razor.Test/ProjectSystem/TestProjectSystemServices.cs b/test/Microsoft.VisualStudio.LanguageServices.Razor.Test/ProjectSystem/TestProjectSystemServices.cs index 78937189f9..42fa7a575f 100644 --- a/test/Microsoft.VisualStudio.LanguageServices.Razor.Test/ProjectSystem/TestProjectSystemServices.cs +++ b/test/Microsoft.VisualStudio.LanguageServices.Razor.Test/ProjectSystem/TestProjectSystemServices.cs @@ -29,7 +29,7 @@ namespace Microsoft.CodeAnalysis.Razor.ProjectSystem public TestProjectSystemServices(string fullPath, params TestPropertyData[] data) { ProjectService = new TestProjectService(); - ThreadingService = ProjectService.Services.ThreadingPolicy; + ThreadingService = ProjectService.Services.TestThreadingPolicy; UnconfiguredProject = new TestUnconfiguredProject(ProjectService, fullPath); ProjectService.LoadedUnconfiguredProjects.Add(UnconfiguredProject); @@ -87,33 +87,33 @@ namespace Microsoft.CodeAnalysis.Razor.ProjectSystem dataSourceVersions: ImmutableDictionary.Empty); } - public class TestProjectServices : IProjectServices + public class TestProjectServices : ProjectServices { public TestProjectServices(TestProjectService projectService) { - ProjectService = projectService; - ThreadingPolicy = new TestThreadingService(); + TestProjectService = projectService; + TestThreadingPolicy = new TestThreadingService(); } - public TestProjectService ProjectService { get; } + public TestProjectService TestProjectService { get; } - public TestThreadingService ThreadingPolicy { get; } + public TestThreadingService TestThreadingPolicy { get; } - IProjectLockService IProjectServices.ProjectLockService => throw new NotImplementedException(); + public override IProjectService ProjectService => TestProjectService; - IProjectThreadingService IProjectServices.ThreadingPolicy => ThreadingPolicy; + public override IProjectThreadingService ThreadingPolicy => TestThreadingPolicy; - IProjectFaultHandlerService IProjectServices.FaultHandler => throw new NotImplementedException(); + public override ExportProvider ExportProvider => throw new NotImplementedException(); - IProjectReloader IProjectServices.ProjectReloader => throw new NotImplementedException(); + public override IProjectDataSourceRegistry DataSourceRegistry => throw new NotImplementedException(); - ExportProvider IProjectCommonServices.ExportProvider => throw new NotImplementedException(); + public override IProjectCapabilitiesScope Capabilities => throw new NotImplementedException(); - IProjectDataSourceRegistry IProjectCommonServices.DataSourceRegistry => throw new NotImplementedException(); + public override IProjectLockService ProjectLockService => throw new NotImplementedException(); - IProjectService IProjectCommonServices.ProjectService => ProjectService; + public override IProjectFaultHandlerService FaultHandler => throw new NotImplementedException(); - IProjectCapabilitiesScope IProjectCommonServices.Capabilities => throw new NotImplementedException(); + public override IProjectReloader ProjectReloader => throw new NotImplementedException(); } public class TestProjectService : IProjectService @@ -130,7 +130,7 @@ namespace Microsoft.CodeAnalysis.Razor.ProjectSystem IEnumerable IProjectService.LoadedUnconfiguredProjects => throw new NotImplementedException(); - IProjectServices IProjectService.Services => Services; + ProjectServices IProjectService.Services => Services; IProjectCapabilitiesScope IProjectService.Capabilities => throw new NotImplementedException(); @@ -171,15 +171,16 @@ namespace Microsoft.CodeAnalysis.Razor.ProjectSystem public List LoadedConfiguredProjects { get; } + public UnconfiguredProjectServices Services => throw new NotImplementedException(); + string UnconfiguredProject.FullPath => FullPath; + bool UnconfiguredProject.RequiresReloadForExternalFileChange => throw new NotImplementedException(); IProjectCapabilitiesScope UnconfiguredProject.Capabilities => throw new NotImplementedException(); IProjectService UnconfiguredProject.ProjectService => ProjectService; - IUnconfiguredProjectServices UnconfiguredProject.Services => throw new NotImplementedException(); - IEnumerable UnconfiguredProject.LoadedConfiguredProjects => LoadedConfiguredProjects; bool UnconfiguredProject.IsLoading => throw new NotImplementedException(); @@ -323,7 +324,7 @@ namespace Microsoft.CodeAnalysis.Razor.ProjectSystem UnconfiguredProject ConfiguredProject.UnconfiguredProject => UnconfiguredProject; - IConfiguredProjectServices ConfiguredProject.Services => Services; + ConfiguredProjectServices ConfiguredProject.Services => Services; event AsyncEventHandler ConfiguredProject.ProjectUnloading { @@ -370,65 +371,81 @@ namespace Microsoft.CodeAnalysis.Razor.ProjectSystem } } - public class TestConfiguredProjectServices : IConfiguredProjectServices + public class TestConfiguredProjectServices : ConfiguredProjectServices { public TestConfiguredProjectServices(TestConfiguredProject configuredProject, TestPropertyData[] data) { ConfiguredProject = configuredProject; - AdditionalRuleDefinitions = new TestAdditionalRuleDefinitionsService(); - PropertyPagesCatalog = new TestPropertyPagesCatalogProvider(new TestPropertyPagesCatalog(data)); + TestAdditionalRuleDefinitions = new TestAdditionalRuleDefinitionsService(); + TestPropertyPagesCatalog = new TestPropertyPagesCatalogProvider(new TestPropertyPagesCatalog(data)); } public TestConfiguredProject ConfiguredProject { get; } - public TestAdditionalRuleDefinitionsService AdditionalRuleDefinitions { get; } + public TestAdditionalRuleDefinitionsService TestAdditionalRuleDefinitions { get; } - public TestPropertyPagesCatalogProvider PropertyPagesCatalog { get; } + public override IAdditionalRuleDefinitionsService AdditionalRuleDefinitions => TestAdditionalRuleDefinitions; - IOutputGroupsService IConfiguredProjectServices.OutputGroups => throw new NotImplementedException(); + public TestPropertyPagesCatalogProvider TestPropertyPagesCatalog { get; } - IBuildProject IConfiguredProjectServices.Build => throw new NotImplementedException(); + public override IPropertyPagesCatalogProvider PropertyPagesCatalog => TestPropertyPagesCatalog; - IBuildSupport IConfiguredProjectServices.BuildSupport => throw new NotImplementedException(); + public override IOutputGroupsService OutputGroups => throw new NotImplementedException(); - IAssemblyReferencesService IConfiguredProjectServices.AssemblyReferences => throw new NotImplementedException(); + public override IBuildProject Build => throw new NotImplementedException(); - IComReferencesService IConfiguredProjectServices.ComReferences => throw new NotImplementedException(); + public override IBuildSupport BuildSupport => throw new NotImplementedException(); - ISdkReferencesService IConfiguredProjectServices.SdkReferences => throw new NotImplementedException(); + public override IAssemblyReferencesService AssemblyReferences => throw new NotImplementedException(); - IPackageReferencesService IConfiguredProjectServices.PackageReferences => throw new NotImplementedException(); + public override IComReferencesService ComReferences => throw new NotImplementedException(); - IWinRTReferencesService IConfiguredProjectServices.WinRTReferences => throw new NotImplementedException(); + public override ISdkReferencesService SdkReferences => throw new NotImplementedException(); - IBuildDependencyProjectReferencesService IConfiguredProjectServices.ProjectReferences => throw new NotImplementedException(); + public override IPackageReferencesService PackageReferences => throw new NotImplementedException(); - IProjectItemProvider IConfiguredProjectServices.SourceItems => throw new NotImplementedException(); + public override IWinRTReferencesService WinRTReferences => throw new NotImplementedException(); - IProjectPropertiesProvider IConfiguredProjectServices.ProjectPropertiesProvider => throw new NotImplementedException(); + public override IBuildDependencyProjectReferencesService ProjectReferences => throw new NotImplementedException(); - IProjectPropertiesProvider IConfiguredProjectServices.UserPropertiesProvider => throw new NotImplementedException(); + public override IProjectItemProvider SourceItems => throw new NotImplementedException(); - IProjectAsynchronousTasksService IConfiguredProjectServices.ProjectAsynchronousTasks => throw new NotImplementedException(); + public override IProjectPropertiesProvider ProjectPropertiesProvider => throw new NotImplementedException(); - IAdditionalRuleDefinitionsService IConfiguredProjectServices.AdditionalRuleDefinitions => AdditionalRuleDefinitions; + public override IProjectPropertiesProvider UserPropertiesProvider => throw new NotImplementedException(); - IPropertyPagesCatalogProvider IConfiguredProjectServices.PropertyPagesCatalog => PropertyPagesCatalog; + public override IProjectSubscriptionService ProjectSubscription => throw new NotImplementedException(); - IProjectSubscriptionService IConfiguredProjectServices.ProjectSubscription => throw new NotImplementedException(); + public override IProjectSnapshotService ProjectSnapshotService => throw new NotImplementedException(); - IProjectSnapshotService IConfiguredProjectServices.ProjectSnapshotService => throw new NotImplementedException(); + public override IActiveConfiguredProjectSubscriptionService ActiveConfiguredProjectSubscription => throw new NotImplementedException(); - object IConfiguredProjectServices.HostObject => throw new NotImplementedException(); + public override IActiveConfiguredProjectProvider ActiveConfiguredProjectProvider => throw new NotImplementedException(); - ExportProvider IProjectCommonServices.ExportProvider => throw new NotImplementedException(); + public override IProjectAsynchronousTasksService ProjectAsynchronousTasks => throw new NotImplementedException(); - IProjectDataSourceRegistry IProjectCommonServices.DataSourceRegistry => throw new NotImplementedException(); + public override IProjectConfigurationsService ProjectConfigurationsService => throw new NotImplementedException(); - IProjectService IProjectCommonServices.ProjectService => ConfiguredProject.UnconfiguredProject.ProjectService; + public override object HostObject => throw new NotImplementedException(); - IProjectCapabilitiesScope IProjectCommonServices.Capabilities => throw new NotImplementedException(); + public override IProjectCapabilitiesRequirementsService ProjectCapabilitiesRequirementsService => throw new NotImplementedException(); + + public override ExportProvider ExportProvider => throw new NotImplementedException(); + + public override IProjectDataSourceRegistry DataSourceRegistry => throw new NotImplementedException(); + + public override IProjectService ProjectService => ConfiguredProject.UnconfiguredProject.ProjectService; + + public override IProjectCapabilitiesScope Capabilities => throw new NotImplementedException(); + + public override IProjectLockService ProjectLockService => throw new NotImplementedException(); + + public override IProjectThreadingService ThreadingPolicy => throw new NotImplementedException(); + + public override IProjectFaultHandlerService FaultHandler => throw new NotImplementedException(); + + public override IProjectReloader ProjectReloader => throw new NotImplementedException(); } public class TestAdditionalRuleDefinitionsService : IAdditionalRuleDefinitionsService