public void TestPropertiesWriteAndRead()
        {
            Properties prop = new Properties();

            prop.AddProperty("file", "C:\\Path\\To\\File");
            prop.AddProperty("bool", "true");
            using (MemoryStream stream = new MemoryStream())
            {
                prop.Store(stream);

                Properties readProp = new Properties();
                readProp.Load(stream);
                Assert.IsTrue(readProp.PropertyNames.Contains("file"));
                Assert.IsTrue(readProp.PropertyNames.Contains("bool"));
                Assert.AreEqual("C:\\Path\\To\\File", readProp.GetProperty("file"));
                Assert.AreEqual("true", readProp.GetProperty("bool"));
            }
        }
示例#2
0
    protected virtual void OnEnable()
    {
        Properties.SetObject(serializedObject);

        Properties.AddGroup(0, "Loose Variables");
        Properties.AddProperty("m_IsActive", 0);
        Properties.AddProperty("m_Velocity", 0);
        Properties.AddProperty("m_TotalVelocity", 0);
    }
示例#3
0
        public TextViewMock(ITextBuffer textBuffer, int caretPosition)
        {
            TextBuffer = textBuffer;

            TextDataModel = new TextDataModelMock(TextBuffer);
            TextViewModel = new TextViewModelMock(textBuffer);

            Caret     = new TextCaretMock(this, caretPosition);
            Selection = new TextSelectionMock(this, new TextRange(caretPosition, 0));

            TextViewLines = new TextViewLineCollectionMock(TextBuffer);
            BufferGraph   = new BufferGraphMock(TextBuffer);

            var view = new EditorView(this);

            Properties.AddProperty(typeof(IEditorView), view);
        }
示例#4
0
    protected override void OnEnable()
    {
        base.OnEnable();

        Properties.AddProperty("m_MovementState", 0);
        Properties.AddProperty("m_CanJump", 0);
        Properties.AddProperty("m_JumpTimer", 0);

        Properties.AddGroup(1, "Horizontal Movement", 1);
        Properties.AddProperty("m_Decay", 1);
        Properties.AddProperty("m_Speed", 1);
        Properties.AddProperty("m_MaxSpeed", 1);

        Properties.AddGroup(2, "Vertical Movement", 1);
        Properties.AddProperty("m_IncrementalJumpForce", 2);
        Properties.AddProperty("m_InitialJumpForce", 2);
        Properties.AddProperty("m_MaxJumpTime", 2);

        Properties.AddGroup(3, "Objects", 1);
        Properties.AddProperty("m_Animator", 3);
        Properties.AddProperty("m_Rigidbody", 3);
    }
        public IProperties ConvertProperties(IDictionary <string, object> properties, IObjectType type, HashSet <Updatability> updatabilityFilter)
        {
            // check input
            if (properties == null)
            {
                return(null);
            }

            // get the type
            if (type == null)
            {
                object typeIdObject;
                if (!properties.TryGetValue(PropertyIds.ObjectTypeId, out typeIdObject))
                {
                    throw new ArgumentException("Type or type property must be set!");
                }

                string typeId = typeIdObject as string;
                if (typeId == null)
                {
                    throw new ArgumentException("Type or type property must be set!");
                }

                type = session.GetTypeDefinition(typeId);
            }

            Properties result = new Properties();

            // the big loop
            foreach (KeyValuePair <string, object> property in properties)
            {
                string id    = property.Key;
                object value = property.Value;

                if (value is IProperty)
                {
                    IProperty p = (IProperty)value;
                    if (id != p.Id)
                    {
                        throw new ArgumentException("Property id mismatch: '" + id + "' != '" + p.Id + "'!");
                    }
                    value = (p.PropertyDefinition.Cardinality == Cardinality.Single ? p.FirstValue : p.Values);
                }

                // get the property definition
                IPropertyDefinition definition = type[id];
                if (definition == null)
                {
                    throw new ArgumentException("Property +'" + id + "' is not valid for this type!");
                }

                // check updatability
                if (updatabilityFilter != null)
                {
                    if (!updatabilityFilter.Contains(definition.Updatability))
                    {
                        continue;
                    }
                }

                PropertyData propertyData = new PropertyData(definition.PropertyType);
                propertyData.Id = id;

                // single and multi value check
                if (value == null)
                {
                    propertyData.Values = null;
                }
                else if (value is IList)
                {
                    if (definition.Cardinality != Cardinality.Multi)
                    {
                        throw new ArgumentException("Property '" + id + "' is not a multi value property!");
                    }

                    IList valueList = (IList)value;

                    // check if the list is homogeneous and does not contain null values
                    foreach (object o in valueList)
                    {
                        if (o == null)
                        {
                            throw new ArgumentException("Property '" + id + "' contains null values!");
                        }

                        propertyData.AddValue(o);
                    }
                }
                else
                {
                    if (definition.Cardinality != Cardinality.Single)
                    {
                        throw new ArgumentException("Property '" + id + "' is not a single value property!");
                    }

                    propertyData.AddValue(value);
                }

                result.AddProperty(propertyData);
            }

            return(result);
        }
示例#6
0
 public InMemoryStubProjectScope(IIdeScope ideScope)
 {
     IdeScope = ideScope;
     Properties.AddProperty(typeof(IDeveroomConfigurationProvider), new StubDeveroomConfigurationProvider(DeveroomConfiguration));
     ((StubIdeScope)ideScope).ProjectScopes.Add(this);
 }
        /// <inheritdoc/>
        public virtual IProperties ConvertProperties(IDictionary <string, object> properties, IObjectType type, ICollection <ISecondaryType> secondaryTypes, ISet <Updatability> updatabilityFilter)
        {
            // check input
            if (properties == null)
            {
                return(null);
            }

            // get the type
            if (type == null)
            {
                object typeIdObject;
                if (!properties.TryGetValue(PropertyIds.ObjectTypeId, out typeIdObject))
                {
                    throw new ArgumentException("Type or type property must be set!");
                }

                string typeId = typeIdObject as string;
                if (typeId == null)
                {
                    throw new ArgumentException("Type or type property must be set!");
                }

                type = session.GetTypeDefinition(typeId);
            }

            // get secondary types
            ICollection <ISecondaryType> allSecondaryTypes = null;
            object secondaryTypeIds;

            properties.TryGetValue(PropertyIds.SecondaryObjectTypeIds, out secondaryTypeIds);
            if (secondaryTypeIds is IList <string> )
            {
                allSecondaryTypes = new List <ISecondaryType>();

                foreach (string secondaryTypeId in (secondaryTypeIds as IList <string>))
                {
                    if (!(secondaryTypeId is string))
                    {
                        throw new ArgumentException("Secondary types property contains an invalid entry: "
                                                    + secondaryTypeId);
                    }

                    IObjectType secondaryType = session.GetTypeDefinition(secondaryTypeId.ToString());
                    if (!(secondaryType is ISecondaryType))
                    {
                        throw new ArgumentException(
                                  "Secondary types property contains a type that is not a secondary type: " + secondaryTypeId);
                    }

                    allSecondaryTypes.Add((ISecondaryType)secondaryType);
                }
            }

            if (secondaryTypes != null && allSecondaryTypes == null)
            {
                allSecondaryTypes = secondaryTypes;
            }

            Properties result = new Properties();

            // the big loop
            foreach (KeyValuePair <string, object> property in properties)
            {
                string id    = property.Key;
                object value = property.Value;

                if (value is IProperty)
                {
                    IProperty p = (IProperty)value;
                    if (id != p.Id)
                    {
                        throw new ArgumentException("Property id mismatch: '" + id + "' != '" + p.Id + "'!");
                    }
                    value = (p.PropertyDefinition.Cardinality == Cardinality.Single ? p.FirstValue : p.Values);
                }

                // get the property definition
                IPropertyDefinition definition = type[id];
                if (definition == null && allSecondaryTypes != null)
                {
                    foreach (ISecondaryType secondaryType in allSecondaryTypes)
                    {
                        if (secondaryType.PropertyDefinitions != null)
                        {
                            foreach (IPropertyDefinition propertyDefinition in secondaryType.PropertyDefinitions)
                            {
                                if (propertyDefinition.Id == id)
                                {
                                    definition = propertyDefinition;
                                    break;
                                }
                            }
                            if (definition != null)
                            {
                                break;
                            }
                        }
                    }
                    if (definition == null)
                    {
                        throw new ArgumentException("Property +'" + id + "' is not valid for this type!");
                    }
                }

                // check updatability
                if (updatabilityFilter != null)
                {
                    if (definition.Updatability.HasValue && !updatabilityFilter.Contains(definition.Updatability.Value))
                    {
                        continue;
                    }
                }

                PropertyData propertyData = new PropertyData(definition.PropertyType);
                propertyData.Id = id;

                // single and multi value check
                if (value == null)
                {
                    propertyData.Values = null;
                }
                else if (value is IList)
                {
                    if (definition.Cardinality != Cardinality.Multi)
                    {
                        throw new ArgumentException("Property '" + id + "' is not a multi value property!");
                    }

                    IList valueList = (IList)value;

                    // check if the list is homogeneous and does not contain null values
                    foreach (object o in valueList)
                    {
                        if (o == null)
                        {
                            throw new ArgumentException("Property '" + id + "' contains null values!");
                        }

                        propertyData.AddValue(o);
                    }
                }
                else
                {
                    if (definition.Cardinality != Cardinality.Single)
                    {
                        throw new ArgumentException("Property '" + id + "' is not a single value property!");
                    }

                    propertyData.AddValue(value);
                }

                result.AddProperty(propertyData);
            }

            return(result);
        }
示例#8
0
 /// <summary>
 /// Adds a property key/value pair to the target context.
 /// </summary>
 /// <param name="key">The property key.</param>
 /// <param name="value">The property value.</param>
 public void AddProperty(string key, string value)
 {
     Properties.AddProperty(key, value);
 }
    protected override void OnEnable()
    {
        base.OnEnable();

        Properties.AddProperty("m_HitPoints", 0);
    }