コード例 #1
0
        static string SingleTypeConstraintToString(TypeConstraint singleConstraint)
        {
            switch (singleConstraint)
            {
            case TypeConstraint.Boolean:
                return("Boolean");

            case TypeConstraint.Scalar:
                return("Scalar");

            case TypeConstraint.Vector2:
                return("Vector2");

            case TypeConstraint.Vector3:
                return("Vector3");

            case TypeConstraint.Vector4:
                return("Vector4");

            case TypeConstraint.Matrix3x2:
                return("Matrix3x2");

            case TypeConstraint.Matrix4x4:
                return("Matrix4x4");

            case TypeConstraint.Quaternion:
                return("Quaternion");

            case TypeConstraint.Color:
                return("Color");

            default:
                throw new InvalidOperationException();
            }
        }
コード例 #2
0
 /// <summary> Mark a serializable field as an input port. You can access this through <see cref="GetInputPort(string)"/> </summary>
 /// <param name="backingValue">Should we display the backing value for this port as an editor field? </param>
 /// <param name="connectionType">Should we allow multiple connections? </param>
 /// <param name="typeConstraint">Constrains which input connections can be made to this port </param>
 /// <param name="instancePortList">If true, will display a reorderable list of inputs instead of a single port. Will automatically add and display values for lists and arrays </param>
 public InputAttribute(ShowBackingValue backingValue = ShowBackingValue.Unconnected, ConnectionType connectionType = ConnectionType.Multiple, TypeConstraint typeConstraint = TypeConstraint.None, bool instancePortList = false)
 {
     this.backingValue     = backingValue;
     this.connectionType   = connectionType;
     this.instancePortList = instancePortList;
     this.typeConstraint   = typeConstraint;
 }
コード例 #3
0
 public void EqualsToInt32(Type type, bool expected)
 {
     TypeConstraint
     .EqualsTo(typeof(int))
     .Check(type)
     .Should().Be(expected);
 }
コード例 #4
0
ファイル: Node.cs プロジェクト: a995049470/WarOfCard
 /// <summary> Mark a serializable field as an output port. You can access this through <see cref="GetOutputPort(string)"/> </summary>
 /// <param name="backingValue">Should we display the backing value for this port as an editor field? </param>
 /// <param name="connectionType">Should we allow multiple connections? </param>
 /// <param name="typeConstraint">Constrains which input connections can be made from this port </param>
 /// <param name="dynamicPortList">If true, will display a reorderable list of outputs instead of a single port. Will automatically add and display values for lists and arrays </param>
 public OutputAttribute(ShowBackingValue backingValue = ShowBackingValue.Never, ConnectionType connectionType = ConnectionType.Multiple, TypeConstraint typeConstraint = TypeConstraint.None, bool dynamicPortList = false)
 {
     this.backingValue    = backingValue;
     this.connectionType  = connectionType;
     this.dynamicPortList = dynamicPortList;
     this.typeConstraint  = typeConstraint;
 }
コード例 #5
0
        /// <summary> Add a dynamic, serialized port to this node. </summary>
        /// <seealso cref="AddDynamicInput"/>
        /// <seealso cref="AddDynamicOutput"/>
        private NodePort AddDynamicPort(Type type, NodePort.IO direction,
                                        ConnectionType connectionType = ConnectionType.Multiple,
                                        TypeConstraint typeConstraint = TypeConstraint.None,
                                        string fieldName = null)
        {
            if (fieldName == null)
            {
                fieldName = "dynamicInput_0";
                var i = 0;

                while (this.HasPort(fieldName))
                {
                    fieldName = "dynamicInput_" + (++i);
                }
            }
            else if (this.HasPort(fieldName))
            {
                Debug.LogWarning("Port '" + fieldName + "' already exists in " + this.name, this);
                return(this.ports[fieldName]);
            }

            var port = new NodePort(fieldName, type, direction, connectionType, typeConstraint, this);

            this.ports.Add(fieldName, port);

            return(port);
        }
コード例 #6
0
ファイル: Ce.cs プロジェクト: ericlemes/FluentCodeMetrics
        public override Ce FilterBy(TypeConstraint filter)
        {
            Throw.IfArgumentNull(filter, "filter");
            var newSource = source.Select(ceResult => ceResult.FilterBy(filter)).ToList();

            return(new TypeSetCe(newSource));
        }
コード例 #7
0
 public ReferencedTypesTypeSet FilterBy(TypeConstraint filter)
 {
     Throw.IfArgumentNull(filter, "filter");
     return new ReferencedTypesTypeSet(
         sourceField.Where(filter.Check),
         originalField
         );
 }
コード例 #8
0
 public ReferencedTypesTypeSet FilterBy(TypeConstraint filter)
 {
     Throw.IfArgumentNull(filter, "filter");
     return(new ReferencedTypesTypeSet(
                sourceField.Where(filter.Check),
                originalField
                ));
 }
コード例 #9
0
        internal AndTypeConstraint(TypeConstraint left, TypeConstraint right)
        {
            Throw.IfArgumentNull(left, "left");
            Throw.IfArgumentNull(right, "right");

            leftField = left;
            rightField = right;
        }
コード例 #10
0
 /// <summary>
 /// Mark a serializable field as an input port. You can access this through <see cref="GetInputPort(string)"/>
 /// </summary>
 /// <param name="backingValue">
 /// Should we display the backing value for this port as an editor field?
 /// </param>
 /// <param name="connectionType">Should we allow multiple connections?</param>
 /// <param name="typeConstraint">
 /// Constrains which input connections can be made to this port
 /// </param>
 /// <param name="dynamicPortList">
 /// If true, will display a reorderable list of inputs instead of a single port. Will
 /// automatically add and display values for lists and arrays
 /// </param>
 /// <param name="allowedTypes">If set apply to typeConstraint</param>
 public InputAttribute(ShowBackingValue backingValue = ShowBackingValue.Unconnected, ConnectionType connectionType = ConnectionType.Multiple, TypeConstraint typeConstraint = TypeConstraint.None, bool dynamicPortList = false, params Type[] allowedTypes)
 {
     this.backingValue    = backingValue;
     this.connectionType  = connectionType;
     this.dynamicPortList = dynamicPortList;
     this.typeConstraint  = typeConstraint;
     this.allowedTypes    = allowedTypes;
 }
コード例 #11
0
        protected override string InnerTranslate()
        {
            if (TypeConstraint != null && !IsExcludeConstraint)
            {
                return($"{Syntax.Identifier} extends {TypeConstraint.Translate()}");
            }

            return(Syntax.Identifier.ToString());
        }
コード例 #12
0
        private IEnumerable <PropertyInfo> GetProperties(BindingFlags bindingFlags)
        {
            if (bindingFlags == BindingFlags.Default)
            {
                return(TypeConstraint.Properties());
            }

            return(TypeConstraint.Properties(bindingFlags));
        }
コード例 #13
0
        /// <summary>
        /// Get a property by name, or throw exception
        /// </summary>
        /// <exception cref="NoSuchPropertyException"/>
        private PropertyInfo GetProperty(string propertyName)
        {
            var property = TypeConstraint.Property(propertyName);

            if (property == null)
            {
                throw new NoSuchPropertyException(TypeConstraint, propertyName);
            }

            return(property);
        }
コード例 #14
0
        void AssertTypeConstraint(TypeConstraint expected, TypeConstraint actual)
        {
            Assert.AreEqual(expected.Constraint, actual.Constraint);

            if (expected.Constraint == ConstraintType.Type)
            {
                AssertMemberRef(expected.ConstrainedType, actual.ConstrainedType.Type, actual.ConstrainedType.ID);
            }
            else if (expected.Constraint == ConstraintType.TypeParam)
            {
                Assert.AreEqual(expected.ConstrainedTypeParamPosition, actual.ConstrainedTypeParamPosition);
            }
        }
コード例 #15
0
        internal static ExpressionType ConstrainToTypes(TypeConstraint allowedTypes, ExpressionType constrainerA, ExpressionType constrainerB)
        {
            if (constrainerA.Constraints == TypeConstraint.NoType)
            {
                return(ConstrainToType(allowedTypes, constrainerB));
            }

            if (constrainerB.Constraints == TypeConstraint.NoType)
            {
                return(ConstrainToType(allowedTypes, constrainerA));
            }

            // Both constrainers have types. Constrain to the intersection of their constraints.
            return(new ExpressionType(IntersectConstraints(allowedTypes, IntersectConstraints(constrainerA.Constraints, constrainerB.Constraints))));
        }
コード例 #16
0
        private IEnumerable <PropertyInfo> GetProperties(Type propertyType, BindingFlags bindingFlags)
        {
            IEnumerable <PropertyInfo> properties;

            if (bindingFlags == BindingFlags.Default)
            {
                properties = TypeConstraint.Properties().Where(x => x.PropertyType == propertyType);
            }
            else
            {
                properties = TypeConstraint.Properties(bindingFlags).Where(x => x.PropertyType == propertyType);
            }

            return(properties);
        }
コード例 #17
0
        public static TreeNodeViewModel BuildSelectorTree(TypeConstraint constraints)
        {
            TreeNodeViewModel tree = new TreeNodeViewModel();

            BuildConstantSelectorTree(tree, constraints.DotNetTypes);
            BuildEnumerationsSelectorTree(tree, constraints.Enumerations);
            BuildConceptSelectorTree(tree, constraints.DataTypes, typeof(DataType));
            BuildConceptSelectorTree(tree, constraints.Concepts, typeof(SyntaxNode));

            // expand only top level nodes
            foreach (TreeNodeViewModel treeNode in tree.TreeNodes)
            {
                treeNode.IsExpanded = true;
            }

            return(tree);
        }
コード例 #18
0
        public void TestGetTypeParamConstraints()
        {
            Type gcClass = typeof(GenericConstrainedClass <, , ,>);

            Type[] typeparams = gcClass.GetGenericArguments();

            Type tParam = typeparams[0];
            Type uParam = typeparams[1];
            Type vParam = typeparams[2];
            Type wParam = typeparams[3];

            var tExpected = new TypeConstraint[] { TypeConstraint.Struct };
            var uExpected = new TypeConstraint[] { TypeConstraint.Class, TypeConstraint.Ctor };
            var vExpected = new TypeConstraint[] { TypeConstraint.TypeParam(3) };
            var wExpected = new TypeConstraint[] { TypeConstraint.Type(new MemberRef("", MemberRefType.Class, typeof(TestClass).MetadataToken)) };

            AssertTypeConstraints(tExpected, utility.GetTypeParamConstraints(tParam));
            AssertTypeConstraints(uExpected, utility.GetTypeParamConstraints(uParam));
            AssertTypeConstraints(vExpected, utility.GetTypeParamConstraints(vParam));
            AssertTypeConstraints(wExpected, utility.GetTypeParamConstraints(wParam));
        }
コード例 #19
0
        public IReadOnlyList <TypeConstraint> GetTypeParamConstraints(Type typeParam)
        {
            Check.Ref(typeParam);
            Check.Cond(typeParam.IsGenericParameter, "typeParam must be a generic parameter type");

            List <TypeConstraint> constraints = new List <TypeConstraint>();
            var attr = typeParam.GenericParameterAttributes;

            if (attr.HasFlag(GenericParameterAttributes.NotNullableValueTypeConstraint))
            {
                constraints.Add(TypeConstraint.Struct);
            }
            else
            {
                if (attr.HasFlag(GenericParameterAttributes.ReferenceTypeConstraint))
                {
                    constraints.Add(TypeConstraint.Class);
                }
                if (attr.HasFlag(GenericParameterAttributes.DefaultConstructorConstraint))
                {
                    constraints.Add(TypeConstraint.Ctor);
                }

                foreach (var constraint in typeParam.GetGenericParameterConstraints())
                {
                    if (constraint.IsGenericParameter)
                    {
                        int pos = constraint.GenericParameterPosition;
                        constraints.Add(TypeConstraint.TypeParam(pos));
                    }
                    else
                    {
                        MemberRef mRef = new MemberRef(constraint.Name, GetMemberRefType(constraint), constraint.MetadataToken);
                        constraints.Add(TypeConstraint.Type(mRef));
                    }
                }
            }

            return(constraints.ToArray());
        }
コード例 #20
0
 internal static ExpressionType ConstrainToType(TypeConstraint allowedTypes, ExpressionType constrainer)
 {
     return(new ExpressionType(IntersectConstraints(constrainer.Constraints, allowedTypes)));
 }
コード例 #21
0
 internal static TypeConstraint IntersectConstraints(TypeConstraint a, TypeConstraint b)
 {
     return(a & b);
 }
コード例 #22
0
 private void Setup([CanBeNull] Type setValue, [NotNull] Type[] setBaseTypeConstraints, TypeConstraint setTypeCategoryConstraint, LinkedMemberInfo setMemberInfo, IParentDrawer setParent, GUIContent setLabel, bool setReadOnly)
 {
     baseTypeConstraints    = setBaseTypeConstraints;
     typeCategoryConstraint = setTypeCategoryConstraint;
     base.Setup(setValue, typeof(Type), setMemberInfo, setParent, setLabel, setReadOnly);
 }
コード例 #23
0
        /// <summary> Creates a new instance of the drawer or returns a reusable instance from the pool. </summary>
        /// <param name="value"> The initial cached value of the drawer. </param>
        /// <param name="memberInfo"> LinkedMemberInfo for the class member that the created drawer represents. Can be null. </param>
        /// <param name="parent"> The parent drawer of the created drawer. Can be null. </param>
        /// <param name="label"> The prefix label. </param>
        /// <param name="readOnly"> True if drawer should be read only. </param>
        /// <returns> The drawer instance, ready to be used. </returns>
        public static ConstraintedTypeDrawer Create([CanBeNull] Type value, [NotNull] Type[] baseTypeConstraints, TypeConstraint typeCategoryConstraint, LinkedMemberInfo memberInfo, IParentDrawer parent, GUIContent label, bool readOnly)
        {
            ConstraintedTypeDrawer result;

            if (!DrawerPool.TryGet(out result))
            {
                result = new ConstraintedTypeDrawer();
            }
            result.Setup(value, baseTypeConstraints, typeCategoryConstraint, memberInfo, parent, label, readOnly);
            result.LateSetup();
            return(result);
        }
コード例 #24
0
 public static int ComputeCe(this Type that, TypeConstraint filter = null)
 {
     return(Ce
            .For(that)
            .FilterBy(filter));
 }
コード例 #25
0
        protected override void OnMouseDown(object parameter)
        {
            if (!(parameter is MouseButtonEventArgs args))
            {
                return;
            }
            if (args.ChangedButton == MouseButton.Right)
            {
                return;
            }
            args.Handled = true;

            Visual control = args.Source as Visual;

            if (IsTemporallyVisible)
            {
                base.OnMouseDown(parameter);
                return;
            }

            // get parent concept node
            var ancestor = this.Ancestor <ConceptNodeViewModel>();

            if (ancestor == null)
            {
                return;
            }

            // check if property is referencing assembly - special case !
            if (ancestor.SyntaxNode.IsAssemblyReference(PropertyBinding))
            {
                IAssemblyConcept assemblyConcept = SelectAssemblyReference(ancestor.SyntaxNode, PropertyBinding, control);
                if (assemblyConcept == null)
                {
                    return;
                }
                SyntaxTreeManager.SetConceptProperty(ancestor.SyntaxNode, PropertyBinding, assemblyConcept.Assembly);
                SyntaxNode = ancestor.SyntaxNode;
                OnPropertyChanged(nameof(Presentation));
                return;
            }

            // get hosting script concept
            ScriptConcept script;

            if (ancestor.SyntaxNode is ScriptConcept)
            {
                script = (ScriptConcept)ancestor.SyntaxNode;
            }
            else
            {
                script = ancestor.SyntaxNode.Ancestor <ScriptConcept>() as ScriptConcept;
            }

            // get type constraints of the property
            TypeConstraint constraints = SyntaxTreeManager.GetTypeConstraints(script?.Languages, ancestor.SyntaxNode, PropertyBinding);

            // build tree view
            TreeNodeViewModel viewModel = SyntaxNodeSelector.BuildSelectorTree(constraints);

            // open dialog window
            PopupWindow dialog = new PopupWindow(control, viewModel);

            _ = dialog.ShowDialog();
            if (dialog.Result == null)
            {
                return;
            }

            Type selectedType = dialog.Result.NodePayload as Type;

            if (selectedType == null)
            {
                return;
            }

            // set binded property of the model by selected reference
            PropertyInfo property = ancestor.SyntaxNode.GetPropertyInfo(PropertyBinding);

            if (SyntaxTreeManager.GetPropertyType(property) == typeof(Type))
            {
                selectedType = SelectTypeReference(ancestor.SyntaxNode, selectedType, control);
                SyntaxTreeManager.SetConceptProperty(ancestor.SyntaxNode, PropertyBinding, selectedType);
                SyntaxNodeType = selectedType;
            }
            else if (selectedType.IsEnum)
            {
                object enumValue = SelectEnumerationValue(selectedType, control);
                if (enumValue == null)
                {
                    return;
                }
                SyntaxTreeManager.SetConceptProperty(ancestor.SyntaxNode, PropertyBinding, enumValue);
            }
            else
            {
                ISyntaxNode reference;
                if (selectedType.IsSubclassOf(typeof(DataType)))
                {
                    reference = (ISyntaxNode)Activator.CreateInstance(selectedType);
                }
                else
                {
                    // use dialog and scope provider to find reference to the node in the syntax tree
                    reference = SelectSyntaxNodeReference(selectedType, ancestor.SyntaxNode, PropertyBinding, control);
                    if (reference == null)
                    {
                        return;
                    }
                }
                SyntaxTreeManager.SetConceptProperty(ancestor.SyntaxNode, PropertyBinding, reference);
                SyntaxNode = reference;
            }

            // reset view model's state
            OnPropertyChanged(nameof(Presentation));
        }
コード例 #26
0
 static TypeAssert Name(string name, TypeConstraint typeConstraint) => new TypeAssert(new Name(name), typeConstraint);
コード例 #27
0
 public TypeAssert(Expression child, TypeConstraint constraints)
 {
     _child       = child;
     _constraints = constraints;
 }
コード例 #28
0
        internal static ExpressionType AssertMatchingTypes(TypeConstraint allowedTypes, ExpressionType constrainerA, ExpressionType constrainerB, TypeConstraint resultType)
        {
            var doTypesMatch = IntersectConstraints(allowedTypes, IntersectConstraints(constrainerA.Constraints, constrainerB.Constraints)) != TypeConstraint.NoType;

            return(new ExpressionType(doTypesMatch ? resultType : TypeConstraint.NoType));
        }
コード例 #29
0
 public ExpressionType(TypeConstraint constraints)
 {
     Constraints = constraints;
 }
コード例 #30
0
ファイル: Ce.cs プロジェクト: ericlemes/FluentCodeMetrics
 public abstract Ce FilterBy(TypeConstraint filter);
コード例 #31
0
            return !filterField.Check(type);
        }
    }
}
コード例 #32
0
ファイル: Ce.cs プロジェクト: ericlemes/FluentCodeMetrics
 public Ce Ignoring(TypeConstraint toIgnore)
 {
     Throw.IfArgumentNull(toIgnore, "toIgnore");
     return(FilterBy(toIgnore.Not()));
 }
コード例 #33
0
 public static TypeConstraint Or(this Type left, TypeConstraint right)
 {
     return TypeConstraint.EqualsTo(left)
         .Or(right);
 }
コード例 #34
0
ファイル: Ce.cs プロジェクト: ericlemes/FluentCodeMetrics
 public override Ce FilterBy(TypeConstraint filter)
 {
     return(filter == null ?
            this :
            new TypeCe(references.FilterBy(filter), Type));
 }
コード例 #35
0
 public static int ComputeCe(this Type that, TypeConstraint filter = null)
 {
     return Ce
         .For(that)
         .FilterBy(filter);
 }
コード例 #36
0
 internal OrTypeConstraint(TypeConstraint left, TypeConstraint right)
 {
     leftField = left;
     rightField = right;
 }