Exemplo n.º 1
0
        private static void HandlePublicSetter(bool isMake, bool hasEvents, PropertyInfo baseProperty, List <string> propertyImplementations)
        {
            var setMethod     = baseProperty.SetMethod;
            var setVisibility = setMethod.IsPublic ? string.Empty : CodeTemplates.GetVisibility(setMethod.IsFamily, setMethod.IsFamilyOrAssembly);

            if (isMake)
            {
                propertyImplementations.Add(PropertyTemplates.GetPropertySetForMake(setVisibility));
            }
            else if (setMethod.GetParameters()[0].ParameterType.IsSpanLike())
            {
                propertyImplementations.Add(PropertyTemplates.GetPropertySetForSpanLike(setVisibility));
            }
            else
            {
                var setArgumentNameList = setMethod.GetArgumentNameList();
                var setDelegateCast     = setMethod.GetDelegateCast();

                if (setMethod.GetParameters().Length > 0)
                {
                    var setExpectationChecks           = setMethod.GetExpectationChecks();
                    var setExpectationExceptionMessage = setMethod.GetExpectationExceptionMessage();
                    propertyImplementations.Add(PropertyTemplates.GetPropertySet(
                                                    setMethod.MetadataToken, setArgumentNameList, setExpectationChecks, setDelegateCast,
                                                    setExpectationExceptionMessage, setVisibility, hasEvents));
                }
                else
                {
                    propertyImplementations.Add(PropertyTemplates.GetPropertySetAndNoIndexers(
                                                    setMethod.MetadataToken, setArgumentNameList, setDelegateCast, setVisibility, hasEvents));
                }
            }
        }
Exemplo n.º 2
0
        public static void GetPropertySetAndHasEventsIsFalse() =>
        Assert.That(PropertyTemplates.GetPropertySet(1, "b", "c", "d", "e", "f", false), Is.EqualTo(
                        @"f set
{
	if (this.handlers.TryGetValue(1, out var methodHandlers))
	{
		var foundMatch = false;

		foreach(var methodHandler in methodHandlers)
		{
			if(c)
			{
				foundMatch = true;

				if(methodHandler.Method != null)
				{
					((d)methodHandler.Method)(b);
				}
	
				
				methodHandler.IncrementCallCount();
				break;
			}
		}

		if(!foundMatch)
		{
			throw new RE.ExpectationException($""No handlers were found for e"");
		}
	}
	else
	{
		throw new RE.ExpectationException($""No handlers were found for e"");
	}
}"));