Пример #1
0
        public void TestGetProperty()
        {
            Assert.AreEqual("value1", bag.GetProperty <string>("key1"));
            Assert.IsNull(bag.GetProperty <string>("key2"));

            Assert.AreEqual((int?)1, bag.GetProperty <int?>("key3"));
            Assert.AreEqual((long?)1, bag.GetProperty <long?>("key5"));

            // try not existing
            try
            {
                bag.GetProperty <string>("key4");
                Assert.Fail("Get Property must fail for unexisting property");
            }
            catch (ArgumentException)
            {
            }

            // Try cast
            try
            {
                bag.GetProperty <long?>("key3");
                Assert.Fail("Get Property with incompatible type must fail on InvalidCastException");
            }
            catch (InvalidCastException)
            {
            }
        }
Пример #2
0
        public override void Initialize(AnalysisContext context)
        {
            context.RegisterSyntaxNodeAction(syntaxContext =>
            {
                PropertyBag properties = OptionsHelper.GetProperties(syntaxContext.Options);

                if (!properties.GetProperty(
                        OptionsHelper.BuildDefaultEnabledProperty(ExplicitThisAnalyzer.AnalyzerName)))
                {
                    // Analyzer is entirely disabled
                    return;
                }

                var node = syntaxContext.Node as MemberAccessExpressionSyntax;

                if (node != null)
                {
                    if (node.Expression != null &&
                        node.Expression.Kind() == SyntaxKind.ThisExpression &&
                        IsPrivateField(node, syntaxContext.SemanticModel, syntaxContext.CancellationToken))
                    {
                        syntaxContext.ReportDiagnostic(Diagnostic.Create(s_rule, node.GetLocation(), node.Name));
                    }
                }
            }, SyntaxKind.SimpleMemberAccessExpression);
        }
Пример #3
0
        /// <summary>
        /// Checks all characte properties against the Character template xml
        /// </summary>
        /// <param name="character">The character that will be created.</param>
        /// <param name="msg">anything you want the player to know</param>
        /// <returns></returns>
        private bool ValidateCharacterCreateRequest(ICharacterInfo character, ref string msg)
        {
            // check the properties and stats against the character template. don't allow the client to submit stats or properties that aren't in the template
            Stat[] stats = character.Stats.AllStats;
            for (int i = 0; i < stats.Length; i++)
            {
                if (m_CharacterTemplateStats.GetStat(stats[i].StatID) == null)
                {
                    msg = "Server does not allow characters to be created with Stats of StatID " + stats[i].StatID.ToString();
                    return(false);
                }
            }

            Property[] props = character.Properties.AllProperties;
            for (int i = 0; i < props.Length; i++)
            {
                if (m_CharacterTemplateProperties.GetProperty(props[i].PropertyId) == null)
                {
                    msg = "Server does not allow characters to be created with Properties of PropertyId" + props[i].PropertyId.ToString();
                    return(false);
                }
            }

            if (!CharacterValidateName(character.CharacterName, ref msg))
            {
                // send error if we can't validate the name
                return(false);
            }

            return(true);
        }
        private static bool RuleEnabled(SyntaxNodeAnalysisContext syntaxContext)
        {
            PropertyBag properties = OptionsHelper.GetProperties(syntaxContext.Options);

            return(properties.GetProperty(
                       OptionsHelper.BuildDefaultEnabledProperty(ProvideExplicitVariableTypeAnalyzer.AnalyzerName)));
        }
Пример #5
0
        private static void FillUiWithImportedTest(BindableCollection <ResourcePropertyModel> testProperties4Debug, PropertyBag test)
        {
            if (test == null)
            {
                return;
            }

            var defaultType = string.Empty;

            if (test.HasProperty(Constants.Type))
            {
                defaultType = test.GetProperty <string>(Constants.Type);
                System.Diagnostics.Trace.TraceInformation("----- FillUiWithImportedTest: defaultType = {0}\n", defaultType);
            }


            testProperties4Debug.Clear();
            int i = 1;

            foreach (
                var prop in
                test.GetAllProperties()
                .SelectMany(p => GetResourcePropertyModel(test, p, defaultType))
                .OrderBy(m => m.ResourceType))
            {
                if (prop.Key != Constants.Type)
                {
                    System.Diagnostics.Trace.TraceInformation("----- FillUiWithImportedTest: {0} {1} = {2}", i++, prop.Key, prop.Value);
                    testProperties4Debug.Add(prop);
                }
            }
        }
Пример #6
0
        internal static PropertyBag BuildDefaultPropertyBag()
        {
            PropertyBag allOptions = new PropertyBag();

            // The export command could be updated in the future to accept an arbitrary set
            // of analyzers for which to build an options XML file suitable for configuring them.
            // Currently, we perform discovery against the built-in CodeFormatter rules
            // and analyzers only.
            foreach (IOptionsProvider provider in FormattingEngine.GetOptionsProviders(DefaultCompositionAssemblies))
            {
                foreach (IOption option in provider.GetOptions())
                {
                    allOptions.SetProperty(option, option.DefaultValue);
                }
            }

            // TODO: this needs to be fixed. Instead of maintaining a hard-coded list of analyzers, that needs to
            //       be updated on adding a new check, we need to expose the analyzer name on an appropriate interface.
            //       Retrieving each of these bools populates the property bag with the default value of 'true'
            bool enabled;

            foreach (string analyzerName in AllAnalyzerNames)
            {
                enabled = allOptions.GetProperty(BuildDefaultEnabledProperty(analyzerName));
            }
            return(allOptions);
        }
        public override void Initialize(AnalysisContext context)
        {
            context.RegisterCompilationStartAction(compilationContext =>
            {
                PropertyBag properties = OptionsHelper.GetProperties(compilationContext.Options);

                if (!properties.GetProperty(OptionsHelper.BuildDefaultEnabledProperty(AnalyzerName)))
                {
                    // Analyzer is entirely disabled
                    return;
                }

                if (properties.GetProperty(OptimizeNamespaceImportsOptions.PlaceImportsOutsideNamespaceDeclaration))
                {
                    context.RegisterSyntaxNodeAction(LookForUsingsInsideNamespace, SyntaxKind.NamespaceDeclaration);
                }
            });
        }
Пример #8
0
        public override void Initialize(AnalysisContext context)
        {
            context.RegisterCompilationStartAction(compilationContext =>
            {
                PropertyBag properties = OptionsHelper.GetProperties(compilationContext.Options);

                if (!properties.GetProperty(
                        OptionsHelper.BuildDefaultEnabledProperty(OptimizeNamespaceImportsAnalyzer.AnalyzerName)))
                {
                    // Analyzer is entirely disabled
                    return;
                }

                if (properties.GetProperty(OptimizeNamespaceImportsOptions.RemoveUnnecessaryImports))
                {
                    context.RegisterSemanticModelAction(LookForUnusedImports);
                }
            });
        }
Пример #9
0
        public void PropertyBagRepresentsPropertiesCorrectly()
        {
            var propertyBag = new PropertyBag();

            Assert.False(propertyBag.HasProperty("Test"));
            Assert.Null(propertyBag.GetProperty("Test"));
            Assert.Null(propertyBag.GetProperty <string>("Test"));
            Assert.Equal(default(int), propertyBag.GetProperty <int>("Test"));

            propertyBag.SetProperty("Test", "Test");
            Assert.True(propertyBag.HasProperty("Test"));
            Assert.Equal("Test", propertyBag.GetProperty("Test"));
            Assert.Equal("Test", propertyBag.GetProperty <string>("Test"));

            propertyBag.ClearProperty("Test");
            Assert.False(propertyBag.HasProperty("Test"));
            Assert.Null(propertyBag.GetProperty("Test"));
            Assert.Null(propertyBag.GetProperty <string>("Test"));
            Assert.Equal(default(int), propertyBag.GetProperty <int>("Test"));
        }
Пример #10
0
        public void PropertyBagRepresentsPropertiesCorrectly()
        {
            var propertyBag = new PropertyBag();

            Assert.False(propertyBag.HasProperty("Test"));
            Assert.Null(propertyBag.GetProperty("Test"));
            Assert.Null(propertyBag.GetProperty<string>("Test"));
            Assert.Equal(default(int), propertyBag.GetProperty<int>("Test"));

            propertyBag.SetProperty("Test", "Test");
            Assert.True(propertyBag.HasProperty("Test"));
            Assert.Equal("Test", propertyBag.GetProperty("Test"));
            Assert.Equal("Test", propertyBag.GetProperty<string>("Test"));

            propertyBag.ClearProperty("Test");
            Assert.False(propertyBag.HasProperty("Test"));
            Assert.Null(propertyBag.GetProperty("Test"));
            Assert.Null(propertyBag.GetProperty<string>("Test"));
            Assert.Equal(default(int), propertyBag.GetProperty<int>("Test"));
        }
Пример #11
0
        private static IEnumerable <ResourcePropertyModel> GetResourcePropertyModel(PropertyBag test, string propertyName,
                                                                                    string defaultType)
        {
            var    value = test.GetProperty(propertyName);
            var    referencePropertyValue = value as IReferenceProperty;
            string type = defaultType;

            if (referencePropertyValue != null)
            {
                type  = referencePropertyValue.Type;
                value = referencePropertyValue.DisplayName;
            }
            else
            {
                var propBagPropertyValue = value as PropertyBag;
                if (propBagPropertyValue != null)
                {
                    if (propBagPropertyValue.HasProperty(Constants.Type))
                    {
                        type = propBagPropertyValue.GetProperty <string>(Constants.Type);
                    }
                    System.Diagnostics.Trace.TraceInformation("----- GetResourcePropertyModel: type={0}\n", type);
                    return
                        (propBagPropertyValue.GetAllProperties()
                         .SelectMany(p => GetResourcePropertyModel(propBagPropertyValue, p, type)));
                }

                var valueProperty = value as ValueProperty;
                if (valueProperty != null)
                {
                    value = valueProperty.Value + " " + valueProperty.Unit;
                }
            }
            System.Diagnostics.Trace.TraceInformation("----- GetResourcePropertyModel: {0} = {1} ({2})", propertyName, value, type);
            return(new[] { new ResourcePropertyModel
                           {
                               Key = propertyName,
                               ResourceType = type,
                               Value = value
                           } });
        }
Пример #12
0
        internal static void FromProject(this CoreGenDescription desc, XilinxProject proj, EPropAssoc assoc)
        {
            PropertyBag pbag = proj.PBag.Copy(assoc);

            if (assoc == EPropAssoc.CoreGenProj)
            {
                string fname = Path.GetFileNameWithoutExtension(desc.Path);
                string wdir  = "./tmp/" + fname + "/";
                pbag.PutProperty(EXilinxProjectProperties.CoreGen_WorkingDirectory, wdir);
            }
            IList <PropDesc> allProps = PropEnum.EnumProps(typeof(EXilinxProjectProperties));

            foreach (PropDesc pd in allProps)
            {
                if (!pd.IDs.ContainsKey(assoc))
                {
                    continue;
                }

                object value = pbag.GetProperty((EXilinxProjectProperties)pd.EnumValue);
                desc.Set(pd.IDs[assoc], PropEnum.ToString(value, assoc), value.GetType());
            }
        }
        private void OnCompilationStart(CompilationStartAnalysisContext context)
        {
            PropertyBag properties = OptionsHelper.GetProperties(context.Options);

            if (!properties.GetProperty(
                    OptionsHelper.BuildDefaultEnabledProperty(UnwrittenWritableFieldAnalyzer.AnalyzerName)))
            {
                return;
            }

            _candidateReadonlyFields = new HashSet <IFieldSymbol>();
            _writtenFields           = new HashSet <IFieldSymbol>();

            _internalsVisibleToAttribute = context.Compilation.GetTypeByMetadataName(
                "System.Runtime.CompilerServices.InternalsVisibleToAttribute");

            context.RegisterSymbolAction(LocateCandidateReadonlyFields, SymbolKind.Field);
            context.RegisterSyntaxNodeAction(CheckForAssignment, s_compoundAssignmentExpressionKinds);
            context.RegisterSyntaxNodeAction(CheckForRefOrOutParameter, SyntaxKind.Argument);
            context.RegisterSyntaxNodeAction(CheckForExternMethodWithRefParameters, SyntaxKind.MethodDeclaration);
            context.RegisterSyntaxNodeAction(CheckForExternIndexer, SyntaxKind.IndexerDeclaration);
            context.RegisterSyntaxNodeAction(CheckForInvocations, SyntaxKind.InvocationExpression);
            context.RegisterCompilationEndAction(ReportUnwrittenFields);
        }
Пример #14
0
        /// <summary>
        /// Method for convenient testing of local connectors.
        /// </summary>
        public APIConfiguration CreateTestConfiguration(SafeType <Connector> connectorClass, PropertyBag configData, string prefix)
        {
            Debug.Assert(null != connectorClass);
            Type rawConnectorClass = connectorClass.RawType;

            Object[] attributes = connectorClass.RawType.GetCustomAttributes(
                typeof(ConnectorClassAttribute),
                false);
            if (attributes.Length > 0)
            {
                ConnectorClassAttribute attribute =
                    (ConnectorClassAttribute)attributes[0];

                Assembly assembly = IOUtil.GetAssemblyContainingType(rawConnectorClass.FullName);

                String fileName = assembly.Location;
                SafeType <Configuration> connectorConfigurationClass = attribute.ConnectorConfigurationType;
                if (connectorConfigurationClass == null)
                {
                    String MSG = ("File " + fileName +
                                  " contains a ConnectorInfo attribute " +
                                  "with no connector configuration class.");
                    throw new ConfigurationException(MSG);
                }
                String connectorDisplayNameKey =
                    attribute.ConnectorDisplayNameKey;
                if (connectorDisplayNameKey == null)
                {
                    String MSG = ("File " + fileName +
                                  " contains a ConnectorInfo attribute " +
                                  "with no connector display name.");
                    throw new ConfigurationException(MSG);
                }
                LocalConnectorInfoImpl rv = new LocalConnectorInfoImpl();
                rv.ConnectorClass = connectorClass;
                rv.ConnectorConfigurationClass = connectorConfigurationClass;
                rv.ConnectorDisplayNameKey     = connectorDisplayNameKey;
                rv.ConnectorCategoryKey        = attribute.ConnectorCategoryKey;
                rv.ConnectorKey = (
                    new ConnectorKey(rawConnectorClass.Name + ".bundle",
                                     "1.0",
                                     rawConnectorClass.Name));;
                APIConfigurationImpl impl = LocalConnectorInfoManagerImpl.CreateDefaultAPIConfiguration(rv);
                rv.DefaultAPIConfiguration = impl;
//                if (false)
//                {
//                    rv.Messages = CreateDummyMessages();
//                }
//                else
                {
                    rv.Messages = LocalConnectorInfoManagerImpl.LoadMessages(assembly, rv, attribute.MessageCatalogPaths);
                }
                ConfigurationPropertiesImpl configProps = (ConfigurationPropertiesImpl)impl.ConfigurationProperties;

                string fullPrefix = StringUtil.IsBlank(prefix) ? null : prefix + ".";

                foreach (ConfigurationPropertyImpl property in configProps.Properties)
                {
                    object value = configData.GetProperty(null != fullPrefix ? fullPrefix + property.Name : property.Name, property.ValueType, property.Value);
                    if (value != null)
                    {
                        property.Value = value;
                    }
                }
                return(impl);
            }
            throw new ArgumentException("ConnectorClass does not define ConnectorClassAttribute");
        }