예제 #1
0
파일: EdgeAnalyzer.cs 프로젝트: sys27/Edge
        private void CheckValue(Type expected, PropertyNode property)
        {
            if (property.Value is NumberNode)
            {
                if (!expected.IsAssignableFrom(typeof(double)))
                    // todo: error message
                    throw new EdgeAnalyzerException();
            }
            else if (property.Value is StringNode)
            {
                if (!expected.IsAssignableFrom(typeof(string)))
                    // todo: error message
                    throw new EdgeAnalyzerException();
            }
            else if (property.Value is ReferenceNode)
            {
                if (!expected.IsAssignableFrom(CheckType(((ReferenceNode)property.Value).Type)))
                    // todo: error message
                    throw new EdgeAnalyzerException();
            }
            else if (property.Value is EnumNode)
            {
                var e = (EnumNode)property.Value;
                Type eType;

                if (e.Type != null)
                {
                    eType = CheckType(e.Type);

                    if (expected != eType)
                        // todo: error message
                        throw new EdgeAnalyzerException();
                }
                else
                {
                    eType = expected;
                }

                if (!Enum.IsDefined(eType, e.Value))
                    // todo: error message
                    throw new EdgeAnalyzerException();

                e.Type = eType.Name;
            }
            else if (property.Value is ArrayNode)
            {
                var arr = (ArrayNode)property.Value;

                var interfaceType = expected.GetInterface("IDictionary`2");
                if (interfaceType != null)
                {
                    property.Value = new CollectionNode(expected.Name, interfaceType.GetGenericArguments()[1].Name, arr.Array);
                }
                else if ((interfaceType = expected.GetInterface("ICollection`1")) != null)
                {
                    property.Value = new CollectionNode(expected.Name, interfaceType.GetGenericArguments()[0].Name, arr.Array);
                }
                else if (typeof(ICollection).IsAssignableFrom(expected))
                {
                    property.Value = new CollectionNode(expected.Name, "Object", arr.Array);
                }
                else if (!expected.IsAssignableFrom(CheckType(arr.ElementType)))
                {
                    // todo: error message
                    throw new EdgeAnalyzerException();
                }
            }
            else if (property.Value is BindingNode)
            {
            }
        }
예제 #2
0
파일: EdgeAnalyzer.cs 프로젝트: sys27/Edge
        private void CheckProperty(Type objType, PropertyNode property)
        {
            var prop = objType.GetProperty(property.Property);

            if (prop == null)
                // todo: error message
                throw new EdgeAnalyzerException();

            CheckValue(prop.PropertyType, property);
        }