コード例 #1
0
        public override bool OnBeginRecipe(object currentValue, out object newValue)
        {
            newValue = null;
            if (currentValue == null)
            {
                CodeClass currentDSAClass = ExpressionEvaluationHelper.EvaluateExpression((IDictionaryService)GetService(typeof(IDictionaryService)),
                                                currentDSAClassExpression) as CodeClass;
                string methodName = ExpressionEvaluationHelper.EvaluateExpression((IDictionaryService)GetService(typeof(IDictionaryService)),
                                                methodNameExpression) as string;

                bool built = true;
                object builtValue = ExpressionEvaluationHelper.EvaluateExpression((IDictionaryService)GetService(typeof(IDictionaryService)),
                                                builtExpression);
                if (builtValue != null)
                { built = (bool)builtValue; }

                if (currentDSAClass != null && built)
                {
                    Type dsaType = DteConverter.ToType(currentDSAClass);
                    if (dsaType != null)
                    {
                        MethodInfo method=dsaType.GetMethod(methodName);
                        if (method != null
                            && method.IsStatic
                            && method.GetParameters().Length==0)
                        {
                            newValue = method.Invoke(null, null);
                            newValue = MethodBehaviorHelper.TranslateToOfflineBehavior(newValue);
                        }
                    }
                }

            }
            return currentValue!=newValue;
        }
コード例 #2
0
        public void ShouldTranslateMockOfflineBehavior()
        {
            MockOfflineBehavior mockOffBehavior = new MockOfflineBehavior(DateTime.Now, 123, 456, "XXX");

            Microsoft.Practices.SmartClientFactory.DSACompatibleTypes.OfflineBehavior behavior =
                MethodBehaviorHelper.TranslateToOfflineBehavior(mockOffBehavior);

            Assert.AreEqual(mockOffBehavior.Expiration, behavior.Expiration);
            Assert.AreEqual(mockOffBehavior.MaxRetries, behavior.MaxRetries);
            Assert.AreEqual(mockOffBehavior.Stamps, behavior.Stamps);
            Assert.AreEqual(mockOffBehavior.Tag, behavior.Tag);
        }