コード例 #1
0
ファイル: SyntaxOperations.cs プロジェクト: apr-xaml/roslyn
        public static Maybe <IReadOnlyList <MethodDeclarationSyntax> > FindMethodsOfClass <TClass>(Expression <Func <TClass, string> > exMethodName, CSharpSyntaxTree syntaxTree) where TClass : class
        {
            var methodName = ValueOf.Property(exMethodName, null);
            var className  = typeof(TClass).Name;

            return(FindMethodsOfClass(syntaxTree, className, methodName));
        }
コード例 #2
0
ファイル: Parser.cs プロジェクト: mpac123/tkom_compiler
        private ValueOf ParseValueOf()
        {
            ExpectTokenType(TokenType.Identifier);
            var result = new ValueOf
            {
                VariableName = _scanner.Token.Value
            };

            _scanner.ReadNextToken();
            if (_scanner.Token.Type == TokenType.SquareBracketOpen)
            {
                _scanner.ReadNextToken();
                ExpectTokenType(TokenType.Number);
                result.Index = Int32.Parse(_scanner.Token.Value);
                _scanner.ReadNextToken();
                ExpectTokenType(TokenType.SquareBracketClose);
                _scanner.ReadNextToken();
            }
            if (_scanner.Token.Type == TokenType.Dot)
            {
                _scanner.ReadNextToken();
                ExpectTokenType(TokenType.Identifier);
                result.NestedValue = ParseValueOf();
            }
            return(result);
        }
コード例 #3
0
        public void NullStringValue()
        {
            ValueOf <String> some = ValueOfFactory.valueOfString(null);

            Assert.IsNotNull(some);
            Assert.IsNull(some.value());
        }
コード例 #4
0
ファイル: ScopeTest.cs プロジェクト: mpac123/tkom_compiler
        public void ScopeWithObjectWithArray_VariableIsCalled_CorrectValueIsReturned()
        {
            // prepare
            var scope_prototype = new ScopePrototype
            {
                Variables = new HashSet <string> {
                    "array"
                },
            };
            var scope = new Scope(scope_prototype)
            {
                VariableValues = new Dictionary <string, AssignedValue> {
                    { "array", new AssignedValue(JToken.Parse("{'object': [1,3,6]}")) }
                }
            };
            var valueOf = new ValueOf
            {
                VariableName = "array",
                NestedValue  = new ValueOf
                {
                    VariableName = "object",
                    Index        = 2
                }
            };

            // act
            var value = scope.FindValueOfValueOf(valueOf);

            // validate
            Assert.Equal("6", value);
        }
コード例 #5
0
ファイル: ScopeTest.cs プロジェクト: mpac123/tkom_compiler
        public void ScopeWithVariable_VariableIsCalled_CorrectValueIsReturned()
        {
            // prepare
            var scope_prototype = new ScopePrototype
            {
                Variables = new HashSet <string> {
                    "arg"
                },
            };
            var scope = new Scope(scope_prototype)
            {
                VariableValues = new Dictionary <string, AssignedValue> {
                    { "arg", new AssignedValue(JToken.Parse("'value'")) }
                }
            };
            var valueOf = new ValueOf
            {
                VariableName = "arg"
            };

            // act
            var value = scope.FindValueOfValueOf(valueOf);

            // validate
            Assert.Equal("value", value);
        }
コード例 #6
0
ファイル: D3.cs プロジェクト: cyecp/Mapgen4Unity
        public static int mean(int[] values, ValueOf valueOf = null)
        {
            int n = values.Length,
                m = n,
                i = -1;
            int value,
                sum = 0;

            if (valueOf == null)
            {
                while (++i < n)
                {
                    value = values[i];
                    sum  += value;
                }
            }
            else
            {
                while (++i < n)
                {
                    value = valueOf(values[i], i, values);
                    sum  += value;
                }
            }
            return(sum / m);
        }
コード例 #7
0
        public void StringValue()
        {
            ValueOf <String> some = ValueOfFactory.valueOfString("value");

            Assert.IsNotNull(some);
            Assert.IsNotNull(some.value());
            Assert.AreEqual("value", some.value());
        }
コード例 #8
0
        public void RawAxisTest()
        {
            ValueSpy <float> spy = new ValueSpy <float>(ValueOf.RawAxis("Horizontal"));

            spy.SimulateInput(i => i.GetAxisRaw("Horizontal").Returns(2.0f));
            spy.AssertWasUpdatedTo(2.0f);

            spy.WaitFrame();
            spy.AssertNothingHappened();
        }
コード例 #9
0
ファイル: UpdateTests.cs プロジェクト: pragmatrix/Facts
        public void testUpdateNestedProperty()
        {
            var inst = new ValueOf { Value = new Value() { ValueField = 10 } };

            var newInst = inst.update(i => i.Value.ValueProperty, v => v + 1);

            Assert.That(newInst, Is.Not.SameAs(inst));
            Assert.That(newInst.Value, Is.Not.SameAs(inst.Value));
            Assert.That(newInst.Value.ValueProperty, Is.EqualTo(inst.Value.ValueProperty + 1));
        }
コード例 #10
0
ファイル: Parser.cs プロジェクト: mpac123/tkom_compiler
        private ICondition ParseConditionWithAnyValue(ValueOf lhs, ConditionType conditionType)
        {
            var result = new ConditionWithValue
            {
                LeftHandSideVariable  = lhs,
                ConditionType         = conditionType,
                RightHandSideVariable = ParseValue()
            };

            return(result);
        }
コード例 #11
0
ファイル: Parser.cs プロジェクト: mpac123/tkom_compiler
        private ConditionWithValue ParseConditionWithVariableOrNumericValue(ValueOf lhs, ConditionType conditionType)
        {
            var result = new ConditionWithValue
            {
                LeftHandSideVariable = lhs,
                ConditionType        = conditionType,
            };

            result.RightHandSideVariable = ParseVariableOrNumericValue();
            return(result);
        }
コード例 #12
0
        private StringComponentInstruction PopulateValueOf(ScopePrototype scope, ValueOf valueOf)
        {
            // check if value has been declared in the scope
            if (!scope.Variables.Contains(valueOf.VariableName))
            {
                throw new SemanticsException($"Variable {valueOf.VariableName} has not been declared in the scope of function {scope.FunctionName}.");
            }

            var valueOfInstruction = new StringComponentInstruction(scope, valueOf);

            return(valueOfInstruction);
        }
コード例 #13
0
ファイル: ScopeTest.cs プロジェクト: mpac123/tkom_compiler
        public void ScopeWithoutVariable_VariableIsCalled_RuntimeExceptionIsThrown()
        {
            // prepare
            var outer_scope_prototype = new ScopePrototype
            {
                Variables = new HashSet <string> {
                    "arg"
                },
            };
            var scope_prototype = new ScopePrototype
            {
                Variables = new HashSet <string> {
                    "arg2"
                },
                UpperScopePrototype = outer_scope_prototype
            };
            var scope = new Scope(scope_prototype)
            {
                UpperScope = new Scope(outer_scope_prototype)
                {
                    VariableValues = new Dictionary <string, AssignedValue> {
                        { "arg", new AssignedValue(JToken.Parse("'value'")) }
                    }
                },
                VariableValues = new Dictionary <string, AssignedValue> {
                    { "arg2", new AssignedValue(JToken.Parse("'value2'")) }
                }
            };
            var valueOf = new ValueOf
            {
                VariableName = "arg3"
            };

            // act
            var exceptionWasThrown = false;

            try
            {
                scope.FindValueOfValueOf(valueOf);
            }
            catch (RuntimeException)
            {
                exceptionWasThrown = true;
            }

            // validate
            Assert.True(exceptionWasThrown);
        }
コード例 #14
0
        public JToken FindValueOfValueOf(ValueOf valueOf)
        {
            var rootValue = FindValueOfVariable(valueOf.VariableName);
            var rootName  = valueOf.VariableName;

            if (rootValue.IsNumericValue)
            {
                if (valueOf.Index != null || valueOf.NestedValue != null)
                {
                    throw new RuntimeException("Tried to access members of a numeric value.");
                }
                return(rootValue.NumericValue.ToString());
            }
            var    currentValueOf       = valueOf;
            var    alreadyParsedBuilder = new StringBuilder(rootName);
            JToken jToken = rootValue.StringValue;

            do
            {
                if (currentValueOf.Index != null)
                {
                    var list = jToken.ToList();
                    if (list.Count() <= currentValueOf.Index)
                    {
                        throw new RuntimeException($"The object {alreadyParsedBuilder.ToString()} does not have a member of index {currentValueOf.Index}.");
                    }
                    jToken = list[currentValueOf.Index.Value];
                    alreadyParsedBuilder.Append($"[{currentValueOf.Index}]");
                }
                currentValueOf = currentValueOf.NestedValue;
                if (currentValueOf != null)
                {
                    try
                    {
                        jToken = jToken[currentValueOf.VariableName];
                    }
                    catch (InvalidOperationException)
                    {
                        throw new RuntimeException($"The object {alreadyParsedBuilder.ToString()} does not have a member called {currentValueOf.VariableName}.");
                    }
                    alreadyParsedBuilder.Append($".{currentValueOf.VariableName}");
                }
            }while (currentValueOf != null);
            return(jToken);
        }
コード例 #15
0
ファイル: Equals.cs プロジェクト: mcintyre321/ValueOf
 protected override bool Equals(ValueOf <string, CaseInsensitiveClientRef> other)
 {
     return(EqualityComparer <string> .Default.Equals(Value.ToLower(), other.Value.ToLower()));
 }