NStub.CSharp.BuildContext.KeynameFixer.Fix C# (CSharp) Method

Fix() public method

Fixes the specified key.
At this time, simply "get_", "set_", "add_" and "remove_" is removed from the key, to allow build properties for both sides of CLR-Properties and CLR-Events.
public Fix ( string initial ) : string
initial string The initial key value.
return string
        public string Fix(string initial)
        {
            var result = initial;
            if (initial.StartsWith("get_"))
            {
                result = initial.Replace("get_", string.Empty);
            }
            else if (initial.StartsWith("set_"))
            {
                result = initial.Replace("set_", string.Empty);
            }
            else if (initial.StartsWith("add_"))
            {
                result = initial.Replace("add_", string.Empty);
            }
            else if (initial.StartsWith("remove_"))
            {
                result = initial.Replace("remove_", string.Empty);
            }

            return result;
        }

Usage Example

Exemplo n.º 1
0
        /// <summary>
        /// Initializes a new instance of the <see cref="MemberBuildContextBase"/> class.
        /// </summary>
        /// <param name="codeNamespace">The code namespace.</param>
        /// <param name="testClassDeclaration">The test class declaration.( early testObject ).</param>
        /// <param name="typeMember">The current type to create a test method for.</param>
        /// <param name="buildData">The additional build data lookup.</param>
        /// <param name="setUpTearDownContext">Contains data specific to SetUp and TearDown test-methods.</param>
        /// <param name="baseKey">The base string of the <see cref="TestKey"/>. Is amended by the
        /// <paramref name="codeNamespace"/> identifier, normalized and fixed by a <see cref="KeynameFixer"/>.</param>
        protected MemberBuildContextBase(
            CodeNamespace codeNamespace,
            CodeTypeDeclaration testClassDeclaration,
            CodeTypeMember typeMember,
            BuildDataDictionary buildData,
            ISetupAndTearDownContext setUpTearDownContext,
            string baseKey)
        {
            Guard.NotNull(() => codeNamespace, codeNamespace);
            Guard.NotNull(() => testClassDeclaration, testClassDeclaration);
            Guard.NotNull(() => typeMember, typeMember);
            Guard.NotNull(() => buildData, buildData);
            Guard.NotNull(() => setUpTearDownContext, setUpTearDownContext);
            Guard.NotNullOrEmpty(() => baseKey, baseKey);

            this.CodeNamespace        = codeNamespace;
            this.TestClassDeclaration = testClassDeclaration;
            this.TypeMember           = typeMember;
            this.BuildData            = buildData;
            this.SetUpTearDownContext = setUpTearDownContext;

            this.PreBuildResult = new MemberBuildResult();
            this.BuildResult    = new MemberBuildResult();

            //this.TestKey = GetTestKey(codeNamespace, testClassDeclaration, typeMember);
            var fixer     = new KeynameFixer(codeNamespace, testClassDeclaration, typeMember);
            var fixedName = fixer.Fix(typeMember.Name);

            this.TestKey = baseKey + "." + fixedName;
        }