예제 #1
0
        public static Entity Rotate(Entity entity, Vector offset, double angleInDegrees)
        {
            var transform = GetRotateMatrix(offset, angleInDegrees);
            var inSitu    = GetRotateMatrix(Vector.Zero, angleInDegrees);

            return(entity.MapEntity <Entity>(
                       aggregate => aggregate.Update(
                           location: transform.Transform(aggregate.Location),
                           children: ReadOnlyList <Entity> .Create(aggregate.Children.Select(c => Rotate(entity, offset, angleInDegrees)))),
                       arc => arc.Update(
                           center: transform.Transform(arc.Center),
                           startAngle: MathHelper.CorrectAngleDegrees(arc.StartAngle + angleInDegrees),
                           endAngle: MathHelper.CorrectAngleDegrees(arc.EndAngle + angleInDegrees)),
                       circle => circle.Update(
                           center: transform.Transform(circle.Center)),
                       ellipse => ellipse.Update(
                           center: transform.Transform(ellipse.Center),
                           majorAxis: inSitu.Transform(ellipse.MajorAxis)),
                       image => image.Update(
                           location: transform.Transform(image.Location),
                           rotation: image.Rotation + angleInDegrees),
                       line => line.Update(
                           p1: transform.Transform(line.P1),
                           p2: transform.Transform(line.P2)),
                       location => location.Update(
                           point: transform.Transform(location.Point)),
                       polyline => polyline.Update(
                           vertices: polyline.Vertices.Select(v => new Vertex(transform.Transform(v.Location), v.IncludedAngle, v.Direction))),
                       spline => spline.Update(
                           controlPoints: spline.ControlPoints.Select(cp => transform.Transform(cp))),
                       text => text.Update(
                           location: transform.Transform(text.Location),
                           rotation: text.Rotation + angleInDegrees)
                       ));
        }
        private ICallSite ResolveCallSite(IMethodSignature methodSig, IModule context, ICodeNode genericContext)
        {
            var returnType = ResolveType(methodSig.ReturnType, context, null);

            if (returnType == null)
            {
                return(null);
            }

            var arguments = new IType[methodSig.GetArgumentCountNoVarArgs()];

            for (int i = 0; i < arguments.Length; i++)
            {
                var argumentType = ResolveType(methodSig.Arguments[i], context, null);
                if (argumentType == null)
                {
                    return(null);
                }

                arguments[i] = argumentType;
            }

            return(MakeCallSite(
                       methodSig.HasThis,
                       methodSig.ExplicitThis,
                       methodSig.VarArgIndex,
                       methodSig.CallConv,
                       returnType,
                       ReadOnlyList <IType> .Create(arguments)));
        }
예제 #3
0
 public CommandServiceDescriptor(string CommandName, string SpecTypeName)
 {
     this.CommandName        = CommandName;
     this.SpecTypeName       = SpecTypeName;
     this.CommandDescription = String.Empty;
     this._Preconditions     = ReadOnlyList.Create <string>();
 }
예제 #4
0
 public static Entity Scale(Entity entity, Point basePoint, double scaleFactor)
 {
     return(entity.MapEntity <Entity>(
                aggregate => aggregate.Update(
                    location: aggregate.Location.ScaleFrom(basePoint, scaleFactor),
                    children: ReadOnlyList <Entity> .Create(aggregate.Children.Select(c => Scale(c, basePoint, scaleFactor)))),
                arc => arc.Update(
                    center: arc.Center.ScaleFrom(basePoint, scaleFactor),
                    radius: arc.Radius * scaleFactor),
                circle => circle.Update(
                    center: circle.Center.ScaleFrom(basePoint, scaleFactor),
                    radius: circle.Radius * scaleFactor),
                ellipse => ellipse.Update(
                    center: ellipse.Center.ScaleFrom(basePoint, scaleFactor),
                    majorAxis: ellipse.MajorAxis * scaleFactor),
                image => image.Update(
                    location: image.Location.ScaleFrom(basePoint, scaleFactor),
                    width: image.Width * scaleFactor,
                    height: image.Height * scaleFactor),
                line => line.Update(
                    p1: line.P1.ScaleFrom(basePoint, scaleFactor),
                    p2: line.P2.ScaleFrom(basePoint, scaleFactor)),
                location => location.Update(
                    point: location.Point.ScaleFrom(basePoint, scaleFactor)),
                polyline => polyline.Update(
                    vertices: polyline.Vertices.Select(v => new Vertex(v.Location.ScaleFrom(basePoint, scaleFactor), v.IncludedAngle, v.Direction))),
                spline => spline.Update(
                    controlPoints: spline.ControlPoints.Select(p => p.ScaleFrom(basePoint, scaleFactor))),
                text => text.Update(
                    location: text.Location.ScaleFrom(basePoint, scaleFactor),
                    height: text.Height * scaleFactor)
                ));
 }
예제 #5
0
        public CallSite(
            bool hasThis,
            bool explicitThis,
            MethodCallingConvention callConv,
            TypeSignature returnType,
            TypeSignature[] arguments,
            int varArgIndex,
            int genericParameterCount)
        {
            if (returnType == null)
            {
                throw new ArgumentNullException("returnType");
            }

            _hasThis               = hasThis;
            _explicitThis          = hasThis && explicitThis;
            _genericParameterCount = genericParameterCount;
            _callConv              = callConv;
            _returnType            = returnType;
            _arguments             = ReadOnlyList <TypeSignature> .Create(arguments);

            if (callConv == MethodCallingConvention.VarArgs)
            {
                _varArgIndex = varArgIndex;
            }
        }
예제 #6
0
        /// <summary>
        /// Initializes a new instance of <see cref="SnapGrid"/>.
        /// </summary>
        /// <param name="verticalSegments">
        /// A list of vertical line segments the resizing/moving window can snap onto.
        /// </param>
        /// <param name="horizontalSegments">
        /// A list of horizontal line segments the resizing/moving window can snap onto.
        /// </param>
        /// <param name="overlappingRectangles">
        /// A list of overlapping rectangles in z-order. Rectangles with a lower index overlap rectangles with a higher index.
        /// </param>
        /// <param name="cutoff">
        /// The length to cut off both ends of all line segments.
        /// </param>
        /// <exception cref="ArgumentNullException">
        /// <paramref name="verticalSegments"/> and/or <paramref name="horizontalSegments"/> and/or <paramref name="overlappingRectangles"/> is null.
        /// </exception>
        public SnapGrid(
            List <LineSegment> verticalSegments,
            List <LineSegment> horizontalSegments,
            List <Rectangle> overlappingRectangles,
            int cutoff)
        {
            if (verticalSegments == null)
            {
                throw new ArgumentNullException(nameof(verticalSegments));
            }
            if (horizontalSegments == null)
            {
                throw new ArgumentNullException(nameof(horizontalSegments));
            }
            if (overlappingRectangles == null)
            {
                throw new ArgumentNullException(nameof(overlappingRectangles));
            }

            AddVisibleSegments(verticalSegments, overlappingRectangles, true, cutoff);
            AddVisibleSegments(horizontalSegments, overlappingRectangles, false, cutoff);

            VerticalSegments = ReadOnlyList <LineSegment> .Create(verticalSegments);

            HorizontalSegments = ReadOnlyList <LineSegment> .Create(horizontalSegments);
        }
예제 #7
0
        public GenericMethodReference(MethodReference declaringMethod, TypeSignature[] genericArguments)
        {
            if (declaringMethod == null)
            {
                throw new ArgumentNullException("declaringMethod");
            }

            _declaringMethod  = declaringMethod;
            _genericArguments = ReadOnlyList <TypeSignature> .Create(genericArguments);
        }
예제 #8
0
        public ArrayType(TypeSignature elementType, ArrayDimension[] dimensions)
        {
            if (elementType == null)
            {
                throw new ArgumentNullException("elementType");
            }

            _elementType = elementType;
            _dimensions  = ReadOnlyList <ArrayDimension> .Create(dimensions);
        }
예제 #9
0
        public GenericTypeReference(TypeReference declaringType, TypeSignature[] genericArguments)
        {
            if (declaringType == null)
            {
                throw new ArgumentNullException("declaringType");
            }

            _declaringType    = declaringType;
            _genericArguments = ReadOnlyList <TypeSignature> .Create(genericArguments);
        }
예제 #10
0
        public ArrayType(TypeSignature elementType, int rank)
        {
            if (elementType == null)
            {
                throw new ArgumentNullException("elementType");
            }

            _elementType = elementType;
            _dimensions  = ReadOnlyList <ArrayDimension> .Create(new ArrayDimension[rank > 0 ? rank : 0]);
        }
예제 #11
0
        public void IEnumerableCreationTest()
        {
            var array = new[] { 0, 1, 2, 3, 4, 5 };
            var list  = ReadOnlyList <int> .Create(array);

            Assert.Equal(array.Length, list.Count);
            var equal = array.Zip(list, (a, b) => a == b);

            Assert.True(equal.All(x => x));
        }
예제 #12
0
    /// <summary>
    /// Applies a function to an input sequence to yield a transformed output sequence
    /// </summary>
    /// <typeparam name="TSource">The type of input element</typeparam>
    /// <typeparam name="TResult">The type of output element</typeparam>
    /// <param name="src">The source sequence</param>
    /// <param name="mapper">The mapping function</param>
    public static ReadOnlyList <TResult> Mapi <TSource, TResult>(this IEnumerable <TSource> src, Func <int, TSource, TResult> mapper)
    {
        var dstList = MutableList.Create <TResult>();
        var srcList = src.ToList();

        for (int i = 0; i < srcList.Count; i++)
        {
            dstList.Add(mapper(i, srcList[i]));
        }
        return(ReadOnlyList.Create(dstList));
    }
예제 #13
0
    /// <summary>
    /// Applies a function to an input sequence to yield a transformed output sequence
    /// </summary>
    /// <typeparam name="TSource">The type of input element</typeparam>
    /// <typeparam name="TResult">The type of output element</typeparam>
    /// <param name="src">The source sequence</param>
    /// <param name="f">The mapping function</param>
    /// <param name="max">The maximum number of elements from the sequence to map</param>
    internal static ReadOnlyList <TResult> ApplyI <TSource, TResult>(this IEnumerable <TSource> src, int max, Func <int, TSource, TResult> f)
    {
        var dstList = MutableList.Create <TResult>();
        var srcList = src.ToList();

        for (int i = 0; i < max; i++)
        {
            dstList.Add(f(i, srcList[i]));
        }
        return(ReadOnlyList.Create(dstList));
    }
예제 #14
0
        private void LoadMethods()
        {
            var declaringMethods = _declaringType.Methods;
            var methods          = new IMethod[declaringMethods.Count];

            for (int i = 0; i < methods.Length; i++)
            {
                methods[i] = new ReferencedMethod(declaringMethods[i], this, ReadOnlyList <IType> .Empty);
            }

            _methods = ReadOnlyList <IMethod> .Create(methods);
        }
예제 #15
0
        private void LoadFields()
        {
            var declaringFields = _declaringType.Fields;
            var fields          = new IField[declaringFields.Count];

            for (int i = 0; i < fields.Length; i++)
            {
                fields[i] = new ReferencedField(declaringFields[i], this);
            }

            _fields = ReadOnlyList <IField> .Create(fields);
        }
예제 #16
0
        private void LoadProperties()
        {
            var declaringProperties = _declaringType.Properties;
            var properties          = new IProperty[declaringProperties.Count];

            for (int i = 0; i < properties.Length; i++)
            {
                properties[i] = new ReferencedProperty(declaringProperties[i], this);
            }

            _properties = ReadOnlyList <IProperty> .Create(properties);
        }
예제 #17
0
        private void LoadEvents()
        {
            var declaringEvents = _declaringType.Events;
            var events          = new IEvent[declaringEvents.Count];

            for (int i = 0; i < events.Length; i++)
            {
                events[i] = new ReferencedEvent(declaringEvents[i], this);
            }

            _events = ReadOnlyList <IEvent> .Create(events);
        }
예제 #18
0
    Option <ReadOnlyList <CommandSubmission <TSpec> > > ICommandSubmitter.Submit <TSpec>(IEnumerable <TSpec> commands, SystemNode target, CorrelationToken?ct)
    {
        var submissions = MutableList.Create <CommandSubmission <TSpec> >();

        foreach (var command in commands)
        {
            var submission = CommandSubmission.Create(command, NextSubmissionId(), C.Service <IJsonSerializer>().ObjectToJson(command), ct, now());
            SubmissionQueue.Enqueue(submission);
            submissions.Add(submission);
        }
        return(ReadOnlyList.Create(submissions));
    }
예제 #19
0
    Option <ReadOnlyList <CommandSubmission> > ICommandSubmitter.Submit(IEnumerable <ICommandSpec> commands, SystemNode target, CorrelationToken?ct)
    {
        var submissions = MutableList.Create <CommandSubmission>();

        foreach (var command in commands)
        {
            var submission = Submit(command, ct);
            SubmissionQueue.Enqueue(submission);
            submissions.Add(submission);
        }
        return(ReadOnlyList.Create(submissions));
    }
예제 #20
0
        private void LoadGenericParameters()
        {
            var declaringGenericParameters = _declaringType.GenericParameters;
            var genericParameters          = new IGenericParameter[declaringGenericParameters.Count];

            for (int i = 0; i < genericParameters.Length; i++)
            {
                genericParameters[i] = new ReferencedGenericParameter(declaringGenericParameters[i], this);
            }

            _genericParameters = ReadOnlyList <IGenericParameter> .Create(genericParameters);
        }
예제 #21
0
    /// <summary>
    /// Gets the members of a type that can contain/represent data (properties and fields)
    /// </summary>
    /// <param name="ValueObjectType"></param>
    /// <returns></returns>
    public static ReadOnlyList <ValueMember> GetValueMembers(this Type ValueObjectType)
    => ValueMemberCache.GetOrAdd(ValueObjectType, t =>
    {
        var members     = MutableList.Create <ValueMember>();
        var autoMembers = GetAutoProps(ValueObjectType);
        members.AddRange(autoMembers);
        var fieldMembers = t.GetPublicImmutableFields(MemberInstanceType.Instance).Select(x => new ValueMember(x));
        members.AddRange(fieldMembers);
        var propMembers = t.GetPublicProperties(false, true).Where(x => x.CanRead && x.CanWrite).Select(x => new ValueMember(x));
        members.AddRange(propMembers);

        return(ReadOnlyList.Create(members));
    });
예제 #22
0
    ReadOnlyList <ICommandDispatch> Dispatch(int MaxCount)
    {
        var dispatched = MutableList.Create <ICommandDispatch>();

        while (dispatched.Count < MaxCount)
        {
            if (!Dispatch().OnSome(d => dispatched.Add(d)))
            {
                break;
            }
        }
        return(ReadOnlyList.Create(dispatched));
    }
예제 #23
0
 public static Entity Quantize(Entity entity, QuantizeSettings settings)
 {
     return(entity.MapEntity <Entity>(
                aggregate => aggregate.Update(
                    location: settings.Quantize(aggregate.Location),
                    children: ReadOnlyList <Entity> .Create(aggregate.Children.Select(c => Quantize(c, settings)))),
                arc => arc.Update(
                    center: settings.Quantize(arc.Center),
                    radius: settings.QuantizeDistance(arc.Radius),
                    startAngle: settings.QuantizeAngle(arc.StartAngle),
                    endAngle: settings.QuantizeAngle(arc.EndAngle),
                    normal: settings.Quantize(arc.Normal),
                    thickness: settings.QuantizeDistance(arc.Thickness)),
                circle => circle.Update(
                    center: settings.Quantize(circle.Center),
                    radius: settings.QuantizeDistance(circle.Radius),
                    normal: settings.Quantize(circle.Normal),
                    thickness: settings.QuantizeDistance(circle.Thickness)),
                ellipse => ellipse.Update(
                    center: settings.Quantize(ellipse.Center),
                    majorAxis: settings.Quantize(ellipse.MajorAxis),
                    minorAxisRatio: settings.QuantizeDistance(ellipse.MinorAxisRatio),
                    startAngle: settings.QuantizeAngle(ellipse.StartAngle),
                    endAngle: settings.QuantizeAngle(ellipse.EndAngle),
                    normal: settings.Quantize(ellipse.Normal),
                    thickness: settings.QuantizeDistance(ellipse.Thickness)),
                image => image.Update(
                    location: settings.Quantize(image.Location),
                    width: settings.QuantizeDistance(image.Width),
                    height: settings.QuantizeDistance(image.Height),
                    rotation: settings.QuantizeAngle(image.Rotation)),
                line => line.Update(
                    p1: settings.Quantize(line.P1),
                    p2: settings.Quantize(line.P2),
                    thickness: settings.QuantizeDistance(line.Thickness)),
                location => location.Update(
                    point: settings.Quantize(location.Point)),
                polyline => polyline.Update(
                    vertices: polyline.Vertices.Select(
                        v => new Vertex(settings.Quantize(v.Location), settings.QuantizeAngle(v.IncludedAngle), v.Direction))),
                spline => spline.Update(
                    controlPoints: spline.ControlPoints.Select(cp => settings.Quantize(cp))),
                text => text.Update(
                    location: settings.Quantize(text.Location),
                    normal: settings.Quantize(text.Normal),
                    height: settings.QuantizeDistance(text.Height),
                    rotation: settings.QuantizeAngle(text.Rotation))
                ));
 }
        public override void Build(CustomAttribute customAttribute)
        {
            var arguments = new List <TypeSignature>(2);

            // Ctor arguments
            var ctorArguments = customAttribute.CtorArguments;

            ctorArguments.Clear();

            // Bindable
            arguments.Add(TypeReference.GetPrimitiveType(PrimitiveTypeCode.Boolean, customAttribute.Assembly));

            ctorArguments.Add(
                new CustomAttributeTypedArgument(
                    _bindable,
                    TypeReference.GetPrimitiveType(PrimitiveTypeCode.Boolean, customAttribute.Assembly)));

            // Direction
            if (_direction.HasValue)
            {
                arguments.Add(new TypeReference("BindingDirection", "System.ComponentModel", AssemblyReference.GetSystem(customAttribute.Assembly), true));

                ctorArguments.Add(
                    new CustomAttributeTypedArgument(
                        (int)_direction,
                        TypeReference.GetPrimitiveType(PrimitiveTypeCode.Int32, customAttribute.Assembly)));
            }

            // Named arguments
            customAttribute.NamedArguments.Clear();

            // Constructor
            customAttribute.Constructor =
                new MethodReference(
                    ".ctor",
                    new TypeReference(
                        "BindableAttribute",
                        "System.ComponentModel",
                        AssemblyReference.GetMscorlib(customAttribute.Assembly)),
                    new CallSite(
                        true,
                        false,
                        MethodCallingConvention.Default,
                        TypeReference.GetPrimitiveType(PrimitiveTypeCode.Void, customAttribute.Assembly),
                        ReadOnlyList <TypeSignature> .Create(arguments),
                        0,
                        0));
        }
예제 #25
0
 public static ReadOnlyList <P> Items <P>(this Option <ReadOnlyList <P> > x, Action <IAppMessage> error)
 {
     if (x.IsSome())
     {
         return(x.Items());
     }
     else
     {
         var message
             = x.Message.IsEmpty
             ? AppMessage.Error("Required option has no value")
             : x.Message;
         error(message);
         return(ReadOnlyList.Create(new P[] { }));
     }
 }
예제 #26
0
        protected internal override void InternMembers(Module module)
        {
            module.AddSignature(ref _returnType);

            int count = _arguments.Count;

            if (count > 0)
            {
                var arguments = new TypeSignature[count];
                for (int i = 0; i < count; i++)
                {
                    var argument = _arguments[i];
                    module.AddSignature(ref argument);
                    arguments[i] = argument;
                }

                _arguments = ReadOnlyList <TypeSignature> .Create(arguments);
            }
        }
예제 #27
0
        protected internal override void InternMembers(Module module)
        {
            module.AddSignature(ref _declaringMethod);

            int count = _genericArguments.Count;

            if (count > 0)
            {
                var genericArguments = new TypeSignature[count];
                for (int i = 0; i < count; i++)
                {
                    var argument = _genericArguments[i];
                    module.AddSignature(ref argument);
                    genericArguments[i] = argument;
                }

                _genericArguments = ReadOnlyList <TypeSignature> .Create(genericArguments);
            }
        }
예제 #28
0
    public Option <ReadOnlyList <ICommandCompletion> > Complete(IEnumerable <ICommandResult> results)
    {
        var completions = MutableList.Create <ICommandCompletion>();

        foreach (var result in results)
        {
            if (Dispatches.TryGetValue(result.SubmissionId, out ICommandDispatch dispatched))
            {
                var completion = new CommandCompletion(dispatched, result, now());
                if (!Completions.TryAdd(result.SubmissionId, completion))
                {
                    throw new Exception("Can't add task to the memory completion index");
                }
                completions.Add(completion);
            }
        }

        return(ReadOnlyList.Create(completions));
    }
예제 #29
0
        /// <summary>
        /// Initializes a new instance of <see cref="JsonErrorInfo"/>.
        /// </summary>
        /// <param name="errorCode">
        /// The error code.
        /// </param>
        /// <param name="errorLevel">
        /// The severity level of the error.
        /// </param>
        /// <param name="start">
        /// The start position of the text span where the error occurred.
        /// </param>
        /// <param name="length">
        /// The length of the text span where the error occurred.
        /// </param>
        /// <param name="parameters">
        /// Parameters of the error.
        /// </param>
        /// <exception cref="ArgumentOutOfRangeException">
        /// Either <paramref name="start"/> or <paramref name="length"/>, or both are negative.
        /// </exception>
        public JsonErrorInfo(JsonErrorCode errorCode, JsonErrorLevel errorLevel, int start, int length, params JsonErrorInfoParameter[] parameters)
        {
            if (start < 0)
            {
                throw new ArgumentOutOfRangeException(nameof(start));
            }
            if (length < 0)
            {
                throw new ArgumentOutOfRangeException(nameof(length));
            }

            ErrorCode  = errorCode;
            ErrorLevel = errorLevel;
            Start      = start;
            Length     = length;
            Parameters = parameters != null
                ? ReadOnlyList <JsonErrorInfoParameter> .Create(parameters)
                : ReadOnlyList <JsonErrorInfoParameter> .Empty;
        }
예제 #30
0
        public void DeleteSpecificIndexTest()
        {
            var array = new[] { 0, 1, 2, 3, 4, 5 };
            var list  = ReadOnlyList <int> .Create(array);

            // remove first index
            list = list.Remove(0);
            Assert.Equal(5, list.Count);
            AssertArrayEqual(new[] { 1, 2, 3, 4, 5 }, list.ToArray());

            // remove last index
            list = list.Remove(4);
            Assert.Equal(4, list.Count);
            AssertArrayEqual(new[] { 1, 2, 3, 4 }, list.ToArray());

            // remove middle index
            list = list.Remove(1);
            Assert.Equal(3, list.Count);
            AssertArrayEqual(new[] { 1, 3, 4 }, list.ToArray());
        }