示例#1
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);
        }
 public void GetPropertyName()
 {
     Assert.AreEqual("Fish", SchemaDecoratorUtil.GetPropertyName("fish", Enumerable.Empty <string>()));
     Assert.AreEqual("Int", SchemaDecoratorUtil.GetPropertyName("int", Enumerable.Empty <string>()));
     Assert.AreEqual(
         "FishAndChips", SchemaDecoratorUtil.GetPropertyName("fish-and-chips", Enumerable.Empty <string>()));
 }