public void GetFieldName()
 {
     Assert.AreEqual("_FISH", SchemaDecoratorUtil.GetFieldName("FISH", Enumerable.Empty <string>()));
     Assert.AreEqual("_int", SchemaDecoratorUtil.GetFieldName("int", Enumerable.Empty <string>()));
     Assert.AreEqual(
         "_fishAndChips", SchemaDecoratorUtil.GetFieldName("fish-and-chips", Enumerable.Empty <string>()));
 }
Example #2
0
        internal CodeMemberProperty GenerateProperty(string name,
                                                     JsonSchema propertySchema,
                                                     SchemaImplementationDetails details,
                                                     int index,
                                                     INestedClassProvider internalClassProvider,
                                                     IEnumerable <string> disallowedNames)
        {
            name.ThrowIfNullOrEmpty("name");
            propertySchema.ThrowIfNull("propertySchema");

            var ret = new CodeMemberProperty();

            ret.Name       = SchemaDecoratorUtil.GetPropertyName(name, disallowedNames);
            ret.Type       = SchemaDecoratorUtil.GetCodeType(propertySchema, details, internalClassProvider);
            ret.Attributes = MemberAttributes.Public;

            ret.HasGet = true;
            var fieldReference = new CodeFieldReferenceExpression(
                new CodeThisReferenceExpression(), SchemaDecoratorUtil.GetFieldName(name, disallowedNames));

            ret.GetStatements.Add(new CodeMethodReturnStatement(fieldReference));

            ret.HasSet = true;
            var parameterReference = new CodeVariableReferenceExpression("value");

            ret.SetStatements.Add(new CodeAssignStatement(fieldReference, parameterReference));

            return(ret);
        }
        internal CodeMemberField GenerateField(string name,
                                               JsonSchema propertySchema,
                                               SchemaImplementationDetails details,
                                               int index,
                                               INestedClassProvider internalClassProvider,
                                               IEnumerable <string> otherFieldNames)
        {
            name.ThrowIfNullOrEmpty("name");
            propertySchema.ThrowIfNull("propertySchema");
            internalClassProvider.ThrowIfNull("internalClassProvider");
            details.ThrowIfNull("details");

            var ret = new CodeMemberField(
                SchemaDecoratorUtil.GetCodeType(propertySchema, details, internalClassProvider),
                SchemaDecoratorUtil.GetFieldName(name, otherFieldNames));

            ret.Attributes = MemberAttributes.Private;

            return(ret);
        }