Beispiel #1
0
 public static Attribute ForLowerCaseProperty()
 {
     return(new Attribute
     {
         Type = new Type(NamesService.GetExtensionTypeName("LowerCasePropertyAttribute"))
     });
 }
Beispiel #2
0
 public CollectionExecuteAsyncMethod(OdcmClass odcmClass)
 {
     Name       = "ExecuteAsync";
     Parameters = Parameter.Empty;
     ReturnType = new Type(new Identifier("global::System.Threading.Tasks", "Task"),
                           new Type(NamesService.GetExtensionTypeName("IPagedCollection"),
                                    new Type(NamesService.GetConcreteInterfaceName(odcmClass))));
 }
 public EnsureQueryMethod(OdcmClass odcmClass)
 {
     IsPublic         = false;
     Name             = "EnsureQuery";
     FetchedType      = NamesService.GetPublicTypeName(odcmClass);
     QueryableSetType = new Type(NamesService.GetExtensionTypeName("ReadOnlyQueryableSet"), new Type(NamesService.GetPublicTypeName(odcmClass)));
     ReturnType       = new Type(NamesService.GetExtensionTypeName("IReadOnlyQueryableSet"), new Type(NamesService.GetConcreteInterfaceName(odcmClass)));
 }
Beispiel #4
0
 public static Field ForNavigationConcreteProperty(OdcmProperty property)
 {
     return(new Field
     {
         Name = NamesService.GetConcreteFieldName(property),
         Type = new Type(NamesService.GetExtensionTypeName("EntityCollectionImpl"), new Type(NamesService.GetConcreteTypeName((OdcmClass)property.Type)))
     });
 }
Beispiel #5
0
 private ConcreteNavigationCollectionProperty(OdcmProperty odcmProperty) : base(odcmProperty)
 {
     FieldName  = NamesService.GetConcreteFieldName(odcmProperty);
     OdcmType   = odcmProperty.Type;
     PrivateSet = true;
     Type       = new Type(NamesService.GetExtensionTypeName("IPagedCollection"),
                           new Type(NamesService.GetConcreteInterfaceName(odcmProperty.Type)));
 }
Beispiel #6
0
 public static IEnumerable <Property> ForEntityContainer(OdcmClass odcmContainer)
 {
     return(Properties.ForEntityContainerInterface(odcmContainer)
            .Concat(new Property[]
     {
         new AutoProperty("Context", new Type(NamesService.GetExtensionTypeName("DataServiceContextWrapper")),
                          privateSet: true)
     }));
 }
Beispiel #7
0
 public static Field ForStructuralProperty(OdcmProperty property)
 {
     return(new Field
     {
         Name = NamesService.GetPropertyFieldName(property),
         Type = property.IsCollection
             ? new Type(NamesService.GetExtensionTypeName("NonEntityTypeCollectionImpl"), new Type(NamesService.GetConcreteTypeName(property.Type)))
             : TypeService.GetPropertyType(property)
     });
 }
Beispiel #8
0
 public static Interface ForCollection(OdcmClass odcmClass)
 {
     return(new Interface
     {
         Attributes = new[] { Attribute.ForLowerCaseProperty() },
         Identifier = NamesService.GetCollectionInterfaceName(odcmClass),
         Namespace = odcmClass.Namespace,
         Methods = global::CSharpWriter.Methods.ForCollectionInterface(odcmClass),
         Indexers = IndexerSignature.ForCollectionInterface(odcmClass),
         Interfaces = new[] { new Type(NamesService.GetExtensionTypeName("IReadOnlyQueryableSetBase"), new Type(NamesService.GetConcreteInterfaceName(odcmClass))) }
     });
 }
Beispiel #9
0
        private void Write(CollectionConstructor collectionConstructor)
        {
            _("internal {0}(global::Microsoft.OData.Client.DataServiceQuery inner," +
              "{1} context," +
              "object entity," +
              "string path)" +
              ": base(inner, context, entity as {2}, path)",
              NamesService.GetCollectionTypeName(collectionConstructor.OdcmClass).Name,
              NamesService.GetExtensionTypeName("DataServiceContextWrapper"),
              NamesService.GetExtensionTypeName("EntityBase"));
            _("{");

            _("}");
        }
Beispiel #10
0
 public static Class ForCollection(OdcmClass odcmClass)
 {
     return(new Class
     {
         AccessModifier = "internal ",
         BaseClass = new Type(NamesService.GetExtensionTypeName("QueryableSet"),
                              new Type(NamesService.GetConcreteInterfaceName(odcmClass))),
         Constructors = global::CSharpWriter.Constructors.ForCollection(odcmClass),
         Interfaces = global::CSharpWriter.Interfaces.ForCollection(odcmClass),
         Identifier = NamesService.GetCollectionTypeName(odcmClass),
         Methods = global::CSharpWriter.Methods.ForCollection(odcmClass),
         Indexers = global::CSharpWriter.Indexers.ForCollection(odcmClass)
     });
 }
Beispiel #11
0
        public static IEnumerable <Type> ForConcreteInterface(OdcmClass odcmClass)
        {
            var retVal = new List <Type>();

            var baseClass = odcmClass.Base as OdcmClass;

            var interfaceIdentifier = baseClass == null?
                                      NamesService.GetExtensionTypeName("IEntityBase") :
                                          NamesService.GetConcreteInterfaceName(baseClass);

            retVal.Add(new Type(interfaceIdentifier));

            return(retVal);
        }
Beispiel #12
0
 public static Class ForComplex(OdcmClass odcmClass)
 {
     return(new Class
     {
         AbstractModifier = odcmClass.IsAbstract ? "abstract " : string.Empty,
         AccessModifier = "public ",
         Constructors = global::CSharpWriter.Constructors.ForComplex(odcmClass),
         BaseClass =
             new Type(odcmClass.Base == null
                 ? NamesService.GetExtensionTypeName("ComplexTypeBase")
                 : NamesService.GetPublicTypeName(odcmClass.Base)),
         Fields = global::CSharpWriter.Fields.ForComplex(odcmClass),
         Identifier = NamesService.GetConcreteTypeName(odcmClass),
         Properties = global::CSharpWriter.Properties.ForComplex(odcmClass),
     });
 }
Beispiel #13
0
 public static Class ForFetcher(OdcmClass odcmClass)
 {
     return(new Class
     {
         AccessModifier = "internal ",
         BaseClass =
             new Type(odcmClass.Base == null
                 ? NamesService.GetExtensionTypeName("RestShallowObjectFetcher")
                 : NamesService.GetFetcherTypeName(odcmClass.Base)),
         Constructors = global::CSharpWriter.Constructors.ForFetcher(odcmClass),
         Fields = global::CSharpWriter.Fields.ForFetcher(odcmClass),
         Identifier = NamesService.GetFetcherTypeName(odcmClass),
         Interfaces = global::CSharpWriter.Interfaces.ForFetcher(odcmClass),
         Methods = global::CSharpWriter.Methods.ForFetcher(odcmClass),
         Properties = global::CSharpWriter.Properties.ForFetcher(odcmClass),
     });
 }
Beispiel #14
0
        private void Write(ConcreteNavigationCollectionProperty property)
        {
            WriteDeclaration(property);

            using (_builder.IndentBraced)
            {
                _("get");

                using (_builder.IndentBraced)
                {
                    _("return new {0}<{1}, {2}>(Context, ({3}<{2}>) {4});",
                      NamesService.GetExtensionTypeName("PagedCollection"),
                      NamesService.GetConcreteInterfaceName(property.OdcmType),
                      NamesService.GetConcreteTypeName(property.OdcmType),
                      NamesService.GetExtensionTypeName("EntityCollectionImpl"),
                      property.FieldName);
                }
            }
        }
Beispiel #15
0
 public static Class ForConcrete(OdcmClass odcmClass)
 {
     return(new Class
     {
         AbstractModifier = odcmClass.IsAbstract ? "abstract " : string.Empty,
         AccessModifier = "public ",
         Attributes = global::CSharpWriter.Attributes.ForConcrete(odcmClass),
         BaseClass =
             new Type(odcmClass.Base == null
                 ? NamesService.GetExtensionTypeName("EntityBase")
                 : NamesService.GetConcreteTypeName(odcmClass.Base)),
         Constructors = global::CSharpWriter.Constructors.ForConcrete(odcmClass),
         Fields = global::CSharpWriter.Fields.ForConcrete(odcmClass),
         Identifier = NamesService.GetConcreteTypeName(odcmClass),
         Interfaces = global::CSharpWriter.Interfaces.ForConcrete(odcmClass),
         Methods = global::CSharpWriter.Methods.ForConcrete(odcmClass),
         Properties = global::CSharpWriter.Properties.ForConcrete(odcmClass)
     });
 }
Beispiel #16
0
        private void Write(StructuralCollectionProperty property)
        {
            WriteDeclaration(property);

            using (_builder.IndentBraced)
            {
                _("get");

                using (_builder.IndentBraced)
                {
                    _("if (this.{0} == default({1}))", property.FieldName, property.Type);

                    using (_builder.IndentBraced)
                    {
                        _("this.{0} = new {1}<{2}>();", property.FieldName,
                          NamesService.GetExtensionTypeName("NonEntityTypeCollectionImpl"), property.InstanceType);
                        _("this.{0}.SetContainer(() => GetContainingEntity(\"{1}\"));", property.FieldName, property.ModelName);
                    }

                    _("return this.{0};", property.FieldName);
                }
                _("set");
                using (_builder.IndentBraced)
                {
                    _("{0}.Clear();", property.FieldName);
                    _("if (value != null)");

                    using (_builder.IndentBraced)
                    {
                        _("foreach (var i in value)");

                        using (_builder.IndentBraced)
                        {
                            _("{0}.Add(i);", property.FieldName);
                        }
                    }
                }
            }
        }
Beispiel #17
0
        private void Write(ConcreteNavigationCollectionAccessorProperty property)
        {
            WriteDeclaration(property);

            using (_builder.IndentBraced)
            {
                _("get");

                using (_builder.IndentBraced)
                {
                    _("if (this.{0} == null)", property.FieldName);
                    using (_builder.IndentBraced)
                    {
                        _("this.{0} = new {1}<{2}>();", property.FieldName, NamesService.GetExtensionTypeName("EntityCollectionImpl"), property.InstanceType);
                        _("this.{0}.SetContainer(() => GetContainingEntity(\"{1}\"));", property.FieldName, property.ModelName);
                    }
                    _("");
                    _("return ({0})this.{1};", property.Type, property.FieldName);
                }

                _("set");

                using (_builder.IndentBraced)
                {
                    _("{0}.Clear();", property.FieldName);
                    _("if (value != null)");
                    using (_builder.IndentBraced)
                    {
                        _("foreach (var i in value)");
                        using (_builder.IndentBraced)
                        {
                            _("{0}.Add(i);", property.FieldName);
                        }
                    }
                }
            }
        }
Beispiel #18
0
 private void Write(EntityContainerConstructor entityContainerConstructor)
 {
     _("public {0}(global::System.Uri serviceRoot, global::System.Func<global::System.Threading.Tasks.Task<string>> accessTokenGetter)",
       entityContainerConstructor.Name);
     using (_builder.IndentBraced)
     {
         _("Context = new {0}(serviceRoot, global::Microsoft.OData.Client.ODataProtocolVersion.V4, accessTokenGetter);", NamesService.GetExtensionTypeName("DataServiceContextWrapper"));
         _("Context.MergeOption = global::Microsoft.OData.Client.MergeOption.OverwriteChanges;");
         _("Context.ResolveName = new global::System.Func<global::System.Type, string>(this.ResolveNameFromType);");
         _("Context.ResolveType = new global::System.Func<string, global::System.Type>(this.ResolveTypeFromName);");
         _("this.OnContextCreated();");
         _("Context.Format.LoadServiceModel = GeneratedEdmModel.GetInstance;");
         _("Context.Format.UseJson();");
     }
     _("partial void OnContextCreated();");
 }